Skip to content

Commit

Permalink
[DP-468] Retrieve Invoice endpoint (#11)
Browse files Browse the repository at this point in the history
* [DP-468] Retrieve Invoice endpoint

* Real UUID

* Actually readme update

* OK, added a commit hook
  • Loading branch information
pkopac authored May 30, 2017
1 parent ce8a6ec commit 7404b2e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ import chartmogul
chartmogul.Invoice.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
chartmogul.Invoice.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', page=2, per_page=10)
chartmogul.Invoice.all(config, customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7', external_id='INV0001')
chartmogul.Invoice.retrieve(config, uuid='inv_22910fc6-c931-48e7-ac12-90d2cb5f0059')
```

#### [Transactions](https://dev.chartmogul.com/docs/transactions)
Expand Down
2 changes: 1 addition & 1 deletion chartmogul/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"""

__title__ = 'chartmogul'
__version__ = '1.1.3'
__version__ = '1.1.4'
__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 @@ -66,3 +66,4 @@ def all(cls, config, **kwargs):

Invoice.all_any = Invoice._method('all', 'get', '/invoices')
Invoice.destroy = Invoice._method('destroy', 'delete', '/invoices{/uuid}')
Invoice.retrieve = Invoice._method('retrieve', 'get', '/invoices{/uuid}')
71 changes: 71 additions & 0 deletions test/api/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,55 @@
}
"""

retrieveInvoiceExample = """
{
"uuid": "inv_22910fc6-c931-48e7-ac12-90d2cb5f0059",
"external_id": "INV0001",
"date": "2015-11-01T00:00:00.000Z",
"due_date": "2015-11-15T00:00:00.000Z",
"currency": "USD",
"line_items": [
{
"uuid": "li_d72e6843-5793-41d0-bfdf-0269514c9c56",
"external_id": null,
"type": "subscription",
"subscription_uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035",
"plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206",
"prorated": false,
"service_period_start": "2015-11-01T00:00:00.000Z",
"service_period_end": "2015-12-01T00:00:00.000Z",
"amount_in_cents": 5000,
"quantity": 1,
"discount_code": "PSO86",
"discount_amount_in_cents": 1000,
"tax_amount_in_cents": 900,
"account_code": null
},
{
"uuid": "li_0cc8c112-beac-416d-af11-f35744ca4e83",
"external_id": null,
"type": "one_time",
"description": "Setup Fees",
"amount_in_cents": 2500,
"quantity": 1,
"discount_code": "PSO86",
"discount_amount_in_cents": 500,
"tax_amount_in_cents": 450,
"account_code": null
}
],
"transactions": [
{
"uuid": "tr_879d560a-1bec-41bb-986e-665e38a2f7bc",
"external_id": null,
"type": "payment",
"date": "2015-11-05T00:14:23.000Z",
"result": "successful"
}
]
}
"""

class InvoiceTestCase(unittest.TestCase):
"""
Tests most important Import API part and its nested schemas.
Expand Down Expand Up @@ -323,3 +372,25 @@ def test_delete_not_found(self, mock_requests):
result = Invoice.destroy(config, uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()

self.assertEqual(mock_requests.call_count, 1, "expected call")

@requests_mock.mock()
def test_retrieve_invoice(self, mock_requests):

mock_requests.register_uri(
'GET',
("https://api.chartmogul.com/v1/invoices/inv_22910fc6-c931-48e7-ac12-90d2cb5f0059"),
request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
headers={'Content-Type': 'application/json'},
status_code=200,
text=retrieveInvoiceExample
)

config = Config("token", "secret") # is actually checked in mock
result = Invoice.retrieve(config, uuid='inv_22910fc6-c931-48e7-ac12-90d2cb5f0059').get()

self.assertEqual(mock_requests.call_count, 1, "expected call")

# Struct too complex to do 1:1 comparison
self.assertTrue(isinstance(result, Invoice))

self.assertEqual(result.uuid, 'inv_22910fc6-c931-48e7-ac12-90d2cb5f0059')

0 comments on commit 7404b2e

Please sign in to comment.