Example #1
0
class TestProducts(SprintlyTestCase):
    def setUp(self):
        self._products = Products('products', 'api')

    def test_add_product_raises_when_no_paying_account(self):
        return_value = MockSprintlyResponse(
                status_code=403,
                reason='FORBIDDEN',
                json={'code': 403, 'message': 'You do not own an account.'})

        self._mock_session_for(self._products, 'post', return_value)

        with self.assertRaises(SprintlyUnauthorizedError) as cm:
            self._products.add_product('new-sprintly-product')
        self.assertEqual('403 - FORBIDDEN', cm.exception.message)

    def test_add_product_ok(self):
        product_name = 'shinny-new-product'
        return_value = MockSprintlyResponse(
                status_code=200,
                reason='OK',
                json={
                    'admin': True,
                    'archived': False,
                    'id': 3,
                    'name': product_name
                    }
                )
        self._mock_session_for(self._products, 'post', return_value)
        self.assertDictEqual(return_value.json,
                self._products.add_product(product_name))

    def test_add_products_makes_list_unique(self):
        add = mock.Mock()
        self._products.add_product = add
        self._products.add_products(['one', 'one'])
        add.assert_called_once_with('one')

    def test_get_product(self):
        product = self._build_fake_product(222, 'whales!')
        return_value = MockSprintlyResponse(
                status_code=200,
                reason='OK',
                json=product)
        self._mock_session_for(self._products, 'get', return_value)
        self.assertDictEqual(product, self._products.get_product(222))

    def test_list_products(self):
        products = [self._build_fake_product(111256, 'dolphines!')]
        return_value = MockSprintlyResponse(
                status_code=200,
                reason='OK',
                json=products)
        self._mock_session_for(self._products, 'get', return_value)
        self.assertEqual(products, self._products.list_products())

    def test_delete_product_no_paying_account(self):
        return_value = MockSprintlyResponse(
                status_code=403,
                reason='FORBIDDEN',
                json={'code': 403, 'message': 'You do not own an account.'})
        self._mock_session_for(self._products, 'delete', return_value)

        with self.assertRaises(SprintlyUnauthorizedError) as cm:
            self._products.delete_product(333)
        self.assertEqual('403 - FORBIDDEN', cm.exception.message)

    def test_delete_product_ok(self):
        product_name = 'drop-this'
        return_value = MockSprintlyResponse(
                status_code=200,
                reason='OK',
                json={
                    'admin': True,
                    'archived': False,
                    'id': 3,
                    'name': product_name
                    }
                )
        self._mock_session_for(self._products, 'delete', return_value)
        self.assertDictEqual(return_value.json,
                self._products.delete_product(product_name))
Example #2
0
class TestProducts(SprintlyTestCase):
    def setUp(self):
        self._products = Products('products', 'api')

    def test_add_product_raises_when_no_paying_account(self):
        return_value = MockSprintlyResponse(status_code=403,
                                            reason='FORBIDDEN',
                                            json={
                                                'code':
                                                403,
                                                'message':
                                                'You do not own an account.'
                                            })

        self._mock_session_for(self._products, 'post', return_value)

        with self.assertRaises(SprintlyUnauthorizedError) as cm:
            self._products.add_product('new-sprintly-product')
        self.assertEqual('403 - FORBIDDEN', cm.exception.message)

    def test_add_product_ok(self):
        product_name = 'shinny-new-product'
        return_value = MockSprintlyResponse(status_code=200,
                                            reason='OK',
                                            json={
                                                'admin': True,
                                                'archived': False,
                                                'id': 3,
                                                'name': product_name
                                            })
        self._mock_session_for(self._products, 'post', return_value)
        self.assertDictEqual(return_value.json,
                             self._products.add_product(product_name))

    def test_add_products_makes_list_unique(self):
        add = mock.Mock()
        self._products.add_product = add
        self._products.add_products(['one', 'one'])
        add.assert_called_once_with('one')

    def test_get_product(self):
        product = self._build_fake_product(222, 'whales!')
        return_value = MockSprintlyResponse(status_code=200,
                                            reason='OK',
                                            json=product)
        self._mock_session_for(self._products, 'get', return_value)
        self.assertDictEqual(product, self._products.get_product(222))

    def test_list_products(self):
        products = [self._build_fake_product(111256, 'dolphines!')]
        return_value = MockSprintlyResponse(status_code=200,
                                            reason='OK',
                                            json=products)
        self._mock_session_for(self._products, 'get', return_value)
        self.assertEqual(products, self._products.list_products())

    def test_delete_product_no_paying_account(self):
        return_value = MockSprintlyResponse(status_code=403,
                                            reason='FORBIDDEN',
                                            json={
                                                'code':
                                                403,
                                                'message':
                                                'You do not own an account.'
                                            })
        self._mock_session_for(self._products, 'delete', return_value)

        with self.assertRaises(SprintlyUnauthorizedError) as cm:
            self._products.delete_product(333)
        self.assertEqual('403 - FORBIDDEN', cm.exception.message)

    def test_delete_product_ok(self):
        product_name = 'drop-this'
        return_value = MockSprintlyResponse(status_code=200,
                                            reason='OK',
                                            json={
                                                'admin': True,
                                                'archived': False,
                                                'id': 3,
                                                'name': product_name
                                            })
        self._mock_session_for(self._products, 'delete', return_value)
        self.assertDictEqual(return_value.json,
                             self._products.delete_product(product_name))
Example #3
0
 def setUp(self):
     self._products = Products('products', 'api')
Example #4
0
 def setUp(self):
     self._products = Products('products', 'api')