|
145 | 145 | ]
|
146 | 146 | }
|
147 | 147 |
|
| 148 | +newInvoiceListExample = """ |
| 149 | +{ |
| 150 | + "invoices": [ |
| 151 | + { |
| 152 | + "uuid": "inv_565c73b2-85b9-49c9-a25e-2b7df6a677c9", |
| 153 | + "customer_uuid": "cus_f466e33d-ff2b-4a11-8f85-417eb02157a7", |
| 154 | + "external_id": "INV0001", |
| 155 | + "date": "2015-11-01T00:00:00.000Z", |
| 156 | + "due_date": "2015-11-15T00:00:00.000Z", |
| 157 | + "currency": "USD", |
| 158 | + "line_items": [ |
| 159 | + { |
| 160 | + "uuid": "li_d72e6843-5793-41d0-bfdf-0269514c9c56", |
| 161 | + "external_id": null, |
| 162 | + "type": "subscription", |
| 163 | + "subscription_uuid": "sub_e6bc5407-e258-4de0-bb43-61faaf062035", |
| 164 | + "plan_uuid": "pl_eed05d54-75b4-431b-adb2-eb6b9e543206", |
| 165 | + "prorated": false, |
| 166 | + "service_period_start": "2015-11-01T00:00:00.000Z", |
| 167 | + "service_period_end": "2015-12-01T00:00:00.000Z", |
| 168 | + "amount_in_cents": 5000, |
| 169 | + "quantity": 1, |
| 170 | + "discount_code": "PSO86", |
| 171 | + "discount_amount_in_cents": 1000, |
| 172 | + "tax_amount_in_cents": 900, |
| 173 | + "account_code": null |
| 174 | + }, |
| 175 | + { |
| 176 | + "uuid": "li_0cc8c112-beac-416d-af11-f35744ca4e83", |
| 177 | + "external_id": null, |
| 178 | + "type": "one_time", |
| 179 | + "description": "Setup Fees", |
| 180 | + "amount_in_cents": 2500, |
| 181 | + "quantity": 1, |
| 182 | + "discount_code": "PSO86", |
| 183 | + "discount_amount_in_cents": 500, |
| 184 | + "tax_amount_in_cents": 450, |
| 185 | + "account_code": null |
| 186 | + } |
| 187 | + ], |
| 188 | + "transactions": [ |
| 189 | + { |
| 190 | + "uuid": "tr_879d560a-1bec-41bb-986e-665e38a2f7bc", |
| 191 | + "external_id": null, |
| 192 | + "type": "payment", |
| 193 | + "date": "2015-11-05T00:14:23.000Z", |
| 194 | + "result": "successful" |
| 195 | + } |
| 196 | + ] |
| 197 | + } |
| 198 | + ], |
| 199 | + "current_page": 1, |
| 200 | + "total_pages": 1 |
| 201 | +} |
| 202 | +""" |
148 | 203 |
|
149 | 204 | class InvoiceTestCase(unittest.TestCase):
|
150 | 205 | """
|
@@ -192,4 +247,38 @@ def test_list_has_customer_uuid(self, mock_requests):
|
192 | 247 | # Struct too complex to do 1:1 comparison
|
193 | 248 | self.assertTrue(isinstance(result, Invoice._many))
|
194 | 249 | self.assertEqual(len(result.invoices), 1)
|
| 250 | + self.assertTrue(isinstance(result.invoices[0], Invoice)) |
| 251 | + self.assertEqual(result.invoices[0].uuid, "inv_565c73b2-85b9-49c9-a25e-2b7df6a677c9") |
195 | 252 | self.assertEqual(result.customer_uuid, 'UUID')
|
| 253 | + |
| 254 | + @requests_mock.mock() |
| 255 | + def test_new_list(self, mock_requests): |
| 256 | + |
| 257 | + mock_requests.register_uri( |
| 258 | + 'GET', |
| 259 | + ("https://api.chartmogul.com/v1/invoices" |
| 260 | + "?external_id=INV0001&customer_uuid=cus_f466e33d-ff2b-4a11-8f85-417eb02157a7"), |
| 261 | + request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'}, |
| 262 | + headers={'Content-Type': 'application/json'}, |
| 263 | + status_code=200, |
| 264 | + text=newInvoiceListExample |
| 265 | + ) |
| 266 | + |
| 267 | + config = Config("token", "secret") # is actually checked in mock |
| 268 | + result = Invoice.all(config, |
| 269 | + customer_uuid='cus_f466e33d-ff2b-4a11-8f85-417eb02157a7', |
| 270 | + external_id='INV0001').get() |
| 271 | + |
| 272 | + self.assertEqual(mock_requests.call_count, 1, "expected call") |
| 273 | + cu = [] |
| 274 | + cu.append('cus_f466e33d-ff2b-4a11-8f85-417eb02157a7') |
| 275 | + ei = [] |
| 276 | + ei.append('inv0001') |
| 277 | + self.assertEqual(mock_requests.last_request.qs, {'customer_uuid': cu,'external_id': ei}) |
| 278 | + # Struct too complex to do 1:1 comparison |
| 279 | + self.assertTrue(isinstance(result, Invoice._many)) |
| 280 | + self.assertEqual(len(result.invoices), 1) |
| 281 | + |
| 282 | + self.assertEqual(result.invoices[0].customer_uuid, 'cus_f466e33d-ff2b-4a11-8f85-417eb02157a7') |
| 283 | + self.assertEqual(result.current_page, 1) |
| 284 | + self.assertEqual(result.total_pages, 1) |
0 commit comments