def test_suspend_product(self): client = inventory_client.InventoryClient() client.suspend_product('1') inventory_client.requests.patch.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product/1', json={'status': 'Suspended'}) inventory_client.requests.patch( ).raise_for_status.assert_called_once_with()
def test_get_product(self): client = inventory_client.InventoryClient() client.get_product('1') inventory_client.requests.get.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product/1' ) inventory_client.requests.get( ).raise_for_status.assert_called_once_with()
def test_get_products(self, name, query, qs): client = inventory_client.InventoryClient() products = client.get_products(query=query) inventory_client.requests.get.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product' + qs) inventory_client.requests.get( ).raise_for_status.assert_called_once_with() self.assertEquals(inventory_client.requests.get().json(), products)
def test_activate_product(self): client = inventory_client.InventoryClient() client.activate_product('1') inventory_client.requests.patch.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product/1', json={ 'status': 'Active', 'startDate': '2016-01-22T04:10:25.176751Z' }) inventory_client.requests.patch( ).raise_for_status.assert_called_once_with()
def test_create_subscription_error(self): self.response.json.return_value = [] self.response.status_code = 404 error = None try: client = inventory_client.InventoryClient() client.create_inventory_subscription() except ImproperlyConfigured as e: error = e self.assertTrue(isinstance(error, ImproperlyConfigured)) msg = "It hasn't been possible to create inventory subscription, " msg += 'please check that the inventory API is correctly configured ' msg += 'and that the inventory API is up and running' self.assertEquals(msg, unicode(error))
def test_create_subscription(self, name, callbacks, created=True): self.response.json.return_value = callbacks client = inventory_client.InventoryClient() client.create_inventory_subscription() inventory_client.requests.get.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/hub' ) if created: inventory_client.requests.post.assert_called_once_with( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/hub', json={ 'callback': 'http://localhost:8004/charging/api/orderManagement/products' }) else: self.assertEquals(0, inventory_client.requests.post.call_count)
def test_terminate_product(self): client = inventory_client.InventoryClient() client.terminate_product('1') self.assertEquals([ call( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product/1', json={ 'status': 'Active', 'startDate': '2016-01-22T04:10:25.176751Z' }), call( 'http://localhost:8080/DSProductInventory/api/productInventory/v2/product/1', json={ 'status': 'Terminated', 'terminationDate': '2016-01-22T04:10:25.176751Z' }) ], inventory_client.requests.patch.call_args_list) self.assertEquals( [call(), call()], inventory_client.requests.patch().raise_for_status.call_args_list)