|
4 | 4 |
|
5 | 5 | import requests_mock
|
6 | 6 |
|
| 7 | +from requests.exceptions import HTTPError |
| 8 | + |
7 | 9 | from chartmogul import Config
|
| 10 | +from chartmogul import APIError |
8 | 11 | from chartmogul import Invoice
|
9 | 12 |
|
10 | 13 |
|
@@ -282,3 +285,41 @@ def test_new_list(self, mock_requests):
|
282 | 285 | self.assertEqual(result.invoices[0].customer_uuid, 'cus_f466e33d-ff2b-4a11-8f85-417eb02157a7')
|
283 | 286 | self.assertEqual(result.current_page, 1)
|
284 | 287 | 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