Skip to content

Commit ce8a6ec

Browse files
authored
[DP-309] support for Delete Invoice (#10)
1 parent 016a902 commit ce8a6ec

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

chartmogul/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"""
3030

3131
__title__ = 'chartmogul'
32-
__version__ = '1.1.2'
32+
__version__ = '1.1.3'
3333
__build__ = 0x000000
3434
__author__ = 'ChartMogul Ltd'
3535
__license__ = 'MIT'

chartmogul/api/invoice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ def all(cls, config, **kwargs):
6565
return cls.all_any(config, **kwargs)
6666

6767
Invoice.all_any = Invoice._method('all', 'get', '/invoices')
68+
Invoice.destroy = Invoice._method('destroy', 'delete', '/invoices{/uuid}')

test/api/test_invoice.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import requests_mock
66

7+
from requests.exceptions import HTTPError
8+
79
from chartmogul import Config
10+
from chartmogul import APIError
811
from chartmogul import Invoice
912

1013

@@ -282,3 +285,41 @@ def test_new_list(self, mock_requests):
282285
self.assertEqual(result.invoices[0].customer_uuid, 'cus_f466e33d-ff2b-4a11-8f85-417eb02157a7')
283286
self.assertEqual(result.current_page, 1)
284287
self.assertEqual(result.total_pages, 1)
288+
289+
@requests_mock.mock()
290+
def test_delete(self, mock_requests):
291+
292+
mock_requests.register_uri(
293+
'DELETE',
294+
("https://api.chartmogul.com/v1/invoices"
295+
"/inv_f466e33d-ff2b-4a11-8f85-417eb02157a7"),
296+
request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
297+
status_code=204
298+
)
299+
300+
config = Config("token", "secret") # is actually checked in mock
301+
result = Invoice.destroy(config,
302+
uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()
303+
304+
self.assertEqual(mock_requests.call_count, 1, "expected call")
305+
self.assertEqual(mock_requests.last_request.qs, {})
306+
self.assertTrue(result is None)
307+
308+
@requests_mock.mock()
309+
def test_delete_not_found(self, mock_requests):
310+
311+
mock_requests.register_uri(
312+
'DELETE',
313+
("https://api.chartmogul.com/v1/invoices"
314+
"/inv_f466e33d-ff2b-4a11-8f85-417eb02157a7"),
315+
request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
316+
headers={'Content-Type': 'application/json'},
317+
status_code=404,
318+
json={'error': 'Invoice not found'}
319+
)
320+
321+
config = Config("token", "secret") # is actually checked in mock
322+
with self.assertRaises(APIError) as context:
323+
result = Invoice.destroy(config, uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()
324+
325+
self.assertEqual(mock_requests.call_count, 1, "expected call")

0 commit comments

Comments
 (0)