Skip to content

Commit

Permalink
Add a method to delete all customer's invoices (ch23545) (#37)
Browse files Browse the repository at this point in the history
* Add delete all invoices method

* Bump version
  • Loading branch information
swember authored Aug 17, 2020
1 parent 7bf1079 commit cde9524
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"""

__title__ = 'chartmogul'
__version__ = '1.4.0'
__version__ = '1.4.1'
__build__ = 0x000000
__author__ = 'ChartMogul Ltd'
__license__ = 'MIT'
Expand Down
1 change: 1 addition & 0 deletions chartmogul/api/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
2 changes: 2 additions & 0 deletions chartmogul/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions test/api/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit cde9524

Please sign in to comment.