diff --git a/chartmogul/__init__.py b/chartmogul/__init__.py index d341172..f245fbe 100644 --- a/chartmogul/__init__.py +++ b/chartmogul/__init__.py @@ -30,7 +30,7 @@ """ __title__ = 'chartmogul' -__version__ = '1.4.0' +__version__ = '1.4.1' __build__ = 0x000000 __author__ = 'ChartMogul Ltd' __license__ = 'MIT' diff --git a/chartmogul/api/invoice.py b/chartmogul/api/invoice.py index fce6ab7..be613ab 100644 --- a/chartmogul/api/invoice.py +++ b/chartmogul/api/invoice.py @@ -72,4 +72,5 @@ def all(cls, config, **kwargs): Invoice.all_any = Invoice._method('all', 'get', '/invoices') Invoice.destroy = Invoice._method('destroy', 'delete', '/invoices{/uuid}') +Invoice.destroy_all = Invoice._method('destroy_all', 'delete', '/data_sources{/data_source_uuid}/customers{/customer_uuid}/invoices') Invoice.retrieve = Invoice._method('retrieve', 'get', '/invoices{/uuid}') diff --git a/chartmogul/resource.py b/chartmogul/resource.py index f745a30..6373289 100644 --- a/chartmogul/resource.py +++ b/chartmogul/resource.py @@ -152,6 +152,8 @@ def fc(cls, config, **kwargs): raise ArgumentMissingError("Please pass 'uuid' parameter") if method in ['create', 'modify'] and 'data' not in kwargs: raise ArgumentMissingError("Please pass 'data' parameter") + if method in ['destroy_all'] and 'data_source_uuid' not in kwargs and 'customer_uuid' not in kwargs: + raise ArgumentMissingError("Please pass 'data_source_uuid' and 'customer_uuid' parameters") pathTemp = Resource._expandPath(pathTemp, kwargs) # UUID is always path parameter only. diff --git a/test/api/test_invoice.py b/test/api/test_invoice.py index 23a9cca..01bf54c 100644 --- a/test/api/test_invoice.py +++ b/test/api/test_invoice.py @@ -376,6 +376,27 @@ def test_delete_not_found(self, mock_requests): self.assertEqual(mock_requests.call_count, 1, "expected call") + @requests_mock.mock() + def test_delete_all(self, mock_requests): + mock_requests.register_uri( + 'DELETE', + ("https://api.chartmogul.com/v1/data_sources" + "/ds_f466e33d-ff2b-4a11-8f85-417eb02157a7/customers" + "/cus_f466e33d-ff2b-4a11-8f85-417eb02157a7/invoices"), + request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'}, + headers={'Content-Type': 'application/json'}, + status_code=204 + ) + + config = Config("token", "secret") # is actually checked in mock + result = Invoice.destroy_all(config, + data_source_uuid='ds_f466e33d-ff2b-4a11-8f85-417eb02157a7', + customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7').get() + + self.assertEqual(mock_requests.call_count, 1, "expected call") + self.assertEqual(mock_requests.last_request.qs, {}) + self.assertTrue(result is None) + @requests_mock.mock() def test_retrieve_invoice(self, mock_requests):