From 5d7c9681f962242ddfb24113aadd5fdcfe31b348 Mon Sep 17 00:00:00 2001 From: som-m Date: Wed, 10 Feb 2021 09:07:56 +0700 Subject: [PATCH] Add tests for list method --- omise/test/test_chain.py | 51 ++++++++++++++ omise/test/test_charge.py | 123 +++++++++++++++++++++++++++++++++ omise/test/test_customer.py | 66 ++++++++++++++++++ omise/test/test_dispute.py | 39 +++++++++++ omise/test/test_event.py | 35 ++++++++++ omise/test/test_link.py | 79 +++++++++++++++++++++ omise/test/test_receipt.py | 60 ++++++++++++++++ omise/test/test_recipient.py | 49 +++++++++++++ omise/test/test_refund.py | 51 ++++++++++++++ omise/test/test_schedule.py | 81 ++++++++++++++++++++++ omise/test/test_transaction.py | 48 +++++++++++++ omise/test/test_transfer.py | 41 +++++++++++ 12 files changed, 723 insertions(+) diff --git a/omise/test/test_chain.py b/omise/test/test_chain.py index e7d4e74..c178d78 100644 --- a/omise/test/test_chain.py +++ b/omise/test/test_chain.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'chain', @@ -94,6 +98,53 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(chains[1].email, 'john.doe@example.com') self.assertRequest(api_call, 'https://api.omise.co/chains') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "data": [ + { + "object": "chain", + "id": "acch_test_1", + "livemode": false, + "location": "/chains/acch_test_1", + "revoked": true, + "email": "jenny.doe@example.com", + "key": "", + "created_at": "2020-09-22T06:08:38Z" + }, + { + "object": "chain", + "id": "acch_test_2", + "livemode": false, + "location": "/chains/acch_test_2", + "revoked": false, + "email": "john.doe@example.com", + "key": "ckey_test", + "created_at": "2021-02-02T03:12:43Z" + } + ], + "limit": 20, + "offset": 0, + "total": 2, + "location": null, + "order": "chronological", + "from": "1970-01-01T00:00:00Z", + "to": "2021-02-02T03:16:57Z" + }""") + + chains = class_.list() + self.assertTrue(isinstance(chains, lazy_collection_class_)) + + chains = list(chains) + self.assertTrue(isinstance(chains[0], class_)) + self.assertTrue(chains[0].id, 'acch_test_1') + self.assertTrue(chains[0].email, 'jenny.doe@example.com') + self.assertTrue(chains[1].id, 'acch_test_2') + self.assertTrue(chains[1].email, 'john.doe@example.com') + @mock.patch('requests.get') def test_reload(self, api_call): chain = self._makeOne() diff --git a/omise/test/test_charge.py b/omise/test/test_charge.py index 31f3758..c06a167 100644 --- a/omise/test/test_charge.py +++ b/omise/test/test_charge.py @@ -22,6 +22,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'card': { @@ -485,6 +489,125 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(charges[1].amount, 100000) self.assertRequest(api_call, 'https://api.omise.co/charges') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-11-20T14:17:24+07:00", + "offset": 0, + "limit": 20, + "total": 2, + "data": [ + { + "object": "charge", + "id": "chrg_test_1", + "livemode": false, + "location": "/charges/chrg_test_1", + "amount": 200000, + "currency": "thb", + "description": "on Johns mastercard", + "capture": true, + "authorized": false, + "captured": false, + "transaction": null, + "failure_code": null, + "failure_message": null, + "refunded": 0, + "refunds": { + "object": "list", + "from": "1970-01-01T00:00:00+00:00", + "to": "2015-01-26T16:20:43+00:00", + "offset": 0, + "limit": 20, + "total": 0, + "data": [], + "location": "/charges/chrg_test_1/refunds" + }, + "card": { + "object": "card", + "id": "card_test_1", + "livemode": false, + "location": "/customers/cust_test/cards/card_test_1", + "country": "us", + "city": null, + "postal_code": null, + "financing": "debit", + "last_digits": "4242", + "brand": "Visa", + "expiration_month": 10, + "expiration_year": 2018, + "fingerprint": null, + "name": "john_mastercard", + "security_code_check": false, + "created": "2014-11-20T01:30:37Z" + }, + "customer": "cust_test", + "ip": "133.71.33.7", + "created": "2014-11-20T01:32:07Z" + }, + { + "object": "charge", + "id": "chrg_test_2", + "livemode": false, + "location": "/charges/chrg_test_2", + "amount": 100000, + "currency": "thb", + "description": "on Johns personal visa", + "capture": true, + "authorized": false, + "captured": false, + "transaction": null, + "failure_code": null, + "failure_message": null, + "refunded": 0, + "refunds": { + "object": "list", + "from": "1970-01-01T00:00:00+00:00", + "to": "2015-01-26T16:20:43+00:00", + "offset": 0, + "limit": 20, + "total": 0, + "data": [], + "location": "/charges/chrg_test_2/refunds" + }, + "card": { + "object": "card", + "id": "card_test_2", + "livemode": false, + "location": "/customers/cust_test/cards/card_test_2", + "country": "us", + "city": "Dunkerque", + "postal_code": "59140", + "financing": "debit", + "last_digits": "4242", + "brand": "Visa", + "expiration_month": 10, + "expiration_year": 2015, + "fingerprint": null, + "name": "john_personal_visa", + "security_code_check": false, + "created": "2014-11-20T01:30:27Z" + }, + "customer": "cust_test", + "ip": "133.71.33.7", + "created": "2014-11-20T01:32:07Z" + } + ] + }""") + + charges = class_.list() + self.assertTrue(isinstance(charges, lazy_collection_class_)) + + charges = list(charges) + self.assertTrue(isinstance(charges[0], class_)) + self.assertTrue(charges[0].id, 'chrg_test_1') + self.assertTrue(charges[0].amount, 200000) + self.assertTrue(charges[1].id, 'chrg_test_2') + self.assertTrue(charges[1].amount, 100000) + @mock.patch('requests.patch') def test_update(self, api_call): charge = self._makeOne() diff --git a/omise/test/test_customer.py b/omise/test/test_customer.py index d9a41dc..ef66a51 100644 --- a/omise/test/test_customer.py +++ b/omise/test/test_customer.py @@ -18,6 +18,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'customer', @@ -284,6 +288,68 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(customers[0].email, 'john.smith@example.com') self.assertRequest(api_call, 'https://api.omise.co/customers') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-10-27T11:36:24+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "data": [ + { + "object": "customer", + "id": "cust_test", + "livemode": false, + "location": "/customers/cust_test", + "default_card": "card_test", + "email": "john.smith@example.com", + "description": "John Doe (id: 30)", + "created": "2014-10-24T08:26:46Z", + "cards": { + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-10-24T15:32:31+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "order": null, + "data": [ + { + "object": "card", + "id": "card_test", + "livemode": false, + "location": "/customers/cust_test/cards/card_test", + "country": "", + "city": null, + "postal_code": null, + "financing": "", + "last_digits": "4242", + "brand": "Visa", + "expiration_month": 9, + "expiration_year": 2017, + "fingerprint": "098f6bcd4621d373cade4e832627b4f6", + "name": "Test card", + "created": "2014-10-24T08:26:07Z" + } + ], + "location": "/customers/cust_test/cards" + } + } + ] + }""") + + customers = class_.list() + self.assertTrue(isinstance(customers, lazy_collection_class_)) + + customers = list(customers) + self.assertTrue(isinstance(customers[0], class_)) + self.assertTrue(customers[0].id, 'cust_test') + self.assertTrue(customers[0].email, 'john.smith@example.com') + @mock.patch('requests.patch') def test_update(self, api_call): customer = self._makeOne() diff --git a/omise/test/test_dispute.py b/omise/test/test_dispute.py index 3d79e01..c0dff87 100644 --- a/omise/test/test_dispute.py +++ b/omise/test/test_dispute.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'dispute', @@ -141,6 +145,41 @@ def test_retrieve_kwargs(self, api_call): self.assertTrue(disputes[0].status, 'closed') self.assertRequest(api_call, 'https://api.omise.co/disputes/closed') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2015-03-23T05:24:39+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "data": [ + { + "object": "dispute", + "id": "dspt_test", + "livemode": false, + "location": "/disputes/dspt_test", + "amount": 100000, + "currency": "thb", + "status": "pending", + "message": "Foobar Baz", + "charge": "chrg_test", + "created": "2015-03-23T05:24:39Z" + } + ] + }""") + + disputes = class_.list() + self.assertTrue(isinstance(disputes, lazy_collection_class_)) + + disputes = list(disputes) + self.assertTrue(isinstance(disputes[0], class_)) + self.assertTrue(disputes[0].id, 'dspt_test') + self.assertTrue(disputes[0].amount, 100000) + @mock.patch('requests.patch') def test_update(self, api_call): dispute = self._makeOne() diff --git a/omise/test/test_event.py b/omise/test/test_event.py index 4fb66d5..f2734db 100644 --- a/omise/test/test_event.py +++ b/omise/test/test_event.py @@ -13,6 +13,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _getChargeClass(self): from .. import Charge return Charge @@ -138,3 +142,34 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(events[0].id, 'evnt_test') self.assertTrue(events[0].key, 'charge.create') self.assertRequest(api_call, 'https://api.omise.co/events') + + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2015-06-02T05:41:53+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "data": [ + { + "object": "event", + "id": "evnt_test", + "livemode": false, + "location": "/events/evnt_test", + "key": "charge.create", + "created": "2015-06-02T05:41:53Z" + } + ] + }""") + + events = class_.list() + self.assertTrue(isinstance(events, lazy_collection_class_)) + + events = list(events) + self.assertTrue(isinstance(events[0], class_)) + self.assertTrue(events[0].id, 'evnt_test') + self.assertTrue(events[0].key, 'charge.create') diff --git a/omise/test/test_link.py b/omise/test/test_link.py index fa95141..b953efb 100644 --- a/omise/test/test_link.py +++ b/omise/test/test_link.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'link', @@ -206,6 +210,81 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(links[1].amount, 20000) self.assertRequest(api_call, 'https://api.omise.co/links') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-11-20T14:17:24+07:00", + "offset": 0, + "limit": 20, + "total": 2, + "data": [ + { + "object": "link", + "id": "link_test_1", + "livemode": false, + "location": "/links/link_test_1", + "amount": 10000, + "currency": "thb", + "used": false, + "multiple": false, + "description": "Description of order-384", + "title": "Order-384", + "charges": { + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2017-03-03T19:22:33+07:00", + "offset": 0, + "limit": 20, + "total": 0, + "order": null, + "location": "/links/link_test_1/charges", + "data": [] + }, + "payment_uri": "http://link.example.com/0BB268C6", + "created": "2017-03-03T12:16:48Z" + }, + { + "object": "link", + "id": "link_test_2", + "livemode": false, + "location": "/links/link_test_2", + "amount": 20000, + "currency": "thb", + "used": false, + "multiple": false, + "description": "Description of order-385", + "title": "Order-385", + "charges": { + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2017-03-03T19:22:33+07:00", + "offset": 0, + "limit": 20, + "total": 0, + "order": null, + "location": "/links/link_test_2/charges", + "data": [] + }, + "payment_uri": "http://link.example.com/0BB268C6", + "created": "2017-03-03T12:16:48Z" + } + ] + }""") + + links = class_.list() + self.assertTrue(isinstance(links, lazy_collection_class_)) + + links = list(links) + self.assertTrue(isinstance(links[0], class_)) + self.assertTrue(links[0].id, 'link_test_1') + self.assertTrue(links[0].amount, 10000) + self.assertTrue(links[1].id, 'link_test_2') + self.assertTrue(links[1].amount, 20000) + @mock.patch('requests.delete') def test_destroy(self, api_call): link = self._makeOne() diff --git a/omise/test/test_receipt.py b/omise/test/test_receipt.py index 465d781..3e626c0 100644 --- a/omise/test/test_receipt.py +++ b/omise/test/test_receipt.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'receipt', @@ -141,3 +145,59 @@ def test_retrieve_no_args(self, api_call): api_call, 'https://api.omise.co/receipts' ) + + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T00:00:00Z", + "to": "2017-10-11T23:59:59Z", + "offset": 0, + "limit": 20, + "total": 1, + "order": "chronological", + "location": "/receipts", + "data": [ + { + "object": "receipt", + "id": "rcpt_test", + "number": "OMTH201710110001", + "location": "/receipts/rcpt_test", + "date": "2017-10-11T16:59:59Z", + "customer_name": "John Doe", + "customer_address": "Crystal Design Center (CDC)", + "customer_tax_id": "Tax ID 1234", + "customer_email": "john@omise.co", + "customer_statement_name": "John", + "company_name": "Omise Company Limited", + "company_address": "Crystal Design Center (CDC)", + "company_tax_id": "0000000000000", + "charge_fee": 1315, + "voided_fee": 0, + "transfer_fee": 0, + "subtotal": 1315, + "vat": 92, + "wht": 0, + "total": 1407, + "credit_note": false, + "currency": "thb" + } + ] + }""") + + receipts = class_.list() + self.assertTrue(isinstance(receipts, lazy_collection_class_)) + + receipts = list(receipts) + self.assertTrue(isinstance(receipts[0], class_)) + self.assertEqual(receipts[0].id, 'rcpt_test') + self.assertEqual(receipts[0].number, 'OMTH201710110001') + self.assertEqual(receipts[0].company_tax_id, '0000000000000') + self.assertEqual(receipts[0].charge_fee, 1315) + self.assertEqual(receipts[0].voided_fee, 0) + self.assertEqual(receipts[0].transfer_fee, 0) + self.assertEqual(receipts[0].subtotal, 1315) + self.assertEqual(receipts[0].total, 1407) + self.assertEqual(receipts[0].currency, 'thb') \ No newline at end of file diff --git a/omise/test/test_recipient.py b/omise/test/test_recipient.py index 0f5fc78..0ad97b2 100644 --- a/omise/test/test_recipient.py +++ b/omise/test/test_recipient.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _getBankAccountClass(self): from .. import BankAccount return BankAccount @@ -225,6 +229,51 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(recipients[0].name, 'Foobar Baz') self.assertRequest(api_call, 'https://api.omise.co/recipients') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2015-06-02T05:41:53+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "data": [ + { + "object": "recipient", + "id": "recp_test", + "livemode": false, + "location": "/recipients/recp_test", + "verified": false, + "active": false, + "name": "Foobar Baz", + "email": "secondary@recipient.co", + "description": "Secondary recipient", + "type": "individual", + "tax_id": "1234567890", + "bank_account": { + "object": "bank_account", + "brand": "test", + "last_digits": "2345", + "name": "James Smith", + "created": "2015-06-02T05:41:53Z" + }, + "failure_code": null, + "created": "2015-06-02T05:41:53Z" + } + ] + }""") + + recipients = class_.list() + self.assertTrue(isinstance(recipients, lazy_collection_class_)) + + recipients = list(recipients) + self.assertTrue(isinstance(recipients[0], class_)) + self.assertTrue(recipients[0].id, 'recp_test') + self.assertTrue(recipients[0].name, 'Foobar Baz') + @mock.patch('requests.patch') def test_update(self, api_call): recipient = self._makeOne() diff --git a/omise/test/test_refund.py b/omise/test/test_refund.py index fe1e44f..cda93a4 100644 --- a/omise/test/test_refund.py +++ b/omise/test/test_refund.py @@ -10,6 +10,10 @@ def _getTargetClass(self): from .. import Refund return Refund + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'refund', @@ -22,6 +26,53 @@ def _makeOne(self): 'created': '2015-01-26T15:06:16Z' }) + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2015-11-20T14:17:24+07:00", + "offset": 0, + "limit": 20, + "total": 2, + "data": [ + { + "object": "refund", + "id": "rfnd_test_1", + "livemode": false, + "location": "/charges/chrg_test/refunds/rfnd_test_1", + "amount": 10000, + "currency": "thb", + "charge": "chrg_test", + "transaction": null, + "created": "2015-01-26T15:06:16Z" + }, + { + "object": "refund", + "id": "rfnd_test_2", + "livemode": false, + "location": "/charges/chrg_test/refunds/rfnd_test_2", + "amount": 20000, + "currency": "thb", + "charge": "chrg_test", + "transaction": null, + "created": "2015-01-27T12:16:48Z" + } + ] + }""") + + refunds = class_.list() + self.assertTrue(isinstance(refunds, lazy_collection_class_)) + + refunds = list(refunds) + self.assertTrue(isinstance(refunds[0], class_)) + self.assertTrue(refunds[0].id, 'rfnd_test_1') + self.assertTrue(refunds[0].amount, 10000) + self.assertTrue(refunds[1].id, 'rfnd_test_2') + self.assertTrue(refunds[1].amount, 20000) + @mock.patch('requests.get') def test_reload(self, api_call): refund = self._makeOne() diff --git a/omise/test/test_schedule.py b/omise/test/test_schedule.py index 50dfc7e..b8398c2 100644 --- a/omise/test/test_schedule.py +++ b/omise/test/test_schedule.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ "object": "schedule", @@ -283,6 +287,83 @@ def test_retrieve_no_args(self, api_call): self.assertEqual(schedules[0].end_date, '2018-05-01') self.assertRequest(api_call, 'https://api.omise.co/schedules') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2017-06-02T12:34:43+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "order": "chronological", + "location": "/schedules", + "data": [ + { + "object": "schedule", + "id": "schd_test", + "livemode": false, + "location": "/schedules/schd_test", + "status": "active", + "deleted": false, + "every": 1, + "period": "month", + "on": { + "weekday_of_month": "2nd_monday" + }, + "in_words": "Every 1 month(s) on the 2nd Monday", + "start_date": "2017-06-02", + "end_date": "2018-05-01", + "charge": { + "amount": 100000, + "currency": "thb", + "description": "Membership fee", + "customer": "cust_test_58655j2ez4elik6t2xc", + "card": null + }, + "occurrences": { + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2017-06-02T19:14:21+07:00", + "offset": 0, + "limit": 20, + "total": 0, + "order": null, + "location": "/schedules/schd_test/occurrences", + "data": [] + }, + "next_occurrence_dates": [ + "2017-06-12", + "2017-07-10", + "2017-08-14", + "2017-09-11", + "2017-10-09", + "2017-11-13", + "2017-12-11", + "2018-01-08", + "2018-02-12", + "2018-03-12", + "2018-04-09" + ], + "created": "2017-06-02T12:14:21Z" + } + ] + }""") + + schedules = class_.list() + self.assertTrue(isinstance(schedules, lazy_collection_class_)) + + schedules = list(schedules) + self.assertTrue(isinstance(schedules[0], class_)) + self.assertTrue(schedules[0].id, 'schd_test') + self.assertEqual(schedules[0].every, 1) + self.assertEqual(schedules[0].period, 'month') + self.assertEqual(schedules[0].status, 'active') + self.assertEqual(schedules[0].start_date, '2017-06-02') + self.assertEqual(schedules[0].end_date, '2018-05-01') + @mock.patch('requests.get') def test_reload(self, api_call): schedule = self._makeOne() diff --git a/omise/test/test_transaction.py b/omise/test/test_transaction.py index 0022e5f..226f3ea 100644 --- a/omise/test/test_transaction.py +++ b/omise/test/test_transaction.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + @mock.patch('requests.get') def test_retrieve(self, api_call): class_ = self._getTargetClass() @@ -100,3 +104,47 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(transactions[1].type, 'debit') self.assertTrue(transactions[1].amount, 100025) self.assertRequest(api_call, 'https://api.omise.co/transactions') + + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-10-27T14:55:29+07:00", + "offset": 0, + "limit": 20, + "total": 2, + "data": [ + { + "object": "transaction", + "id": "trxn_test_1", + "type": "credit", + "amount": 9635024, + "currency": "thb", + "created": "2014-10-27T06:58:56Z" + }, + { + "object": "transaction", + "id": "trxn_test_2", + "type": "debit", + "amount": 100025, + "currency": "thb", + "created": "2014-10-27T07:02:54Z" + } + ] + }""") + + transactions = class_.list() + self.assertTrue(isinstance(transactions, lazy_collection_class_)) + + transactions = list(transactions) + self.assertTrue(isinstance(transactions[0], class_)) + self.assertTrue(transactions[0].id, 'trxn_test_1') + self.assertTrue(transactions[0].type, 'credit') + self.assertTrue(transactions[0].amount, 9635024) + self.assertTrue(isinstance(transactions[1], class_)) + self.assertTrue(transactions[1].id, 'trxn_test_2') + self.assertTrue(transactions[1].type, 'debit') + self.assertTrue(transactions[1].amount, 100025) \ No newline at end of file diff --git a/omise/test/test_transfer.py b/omise/test/test_transfer.py index 606df53..75fd328 100644 --- a/omise/test/test_transfer.py +++ b/omise/test/test_transfer.py @@ -14,6 +14,10 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _getLazyCollectionClass(self): + from .. import LazyCollection + return LazyCollection + def _makeOne(self): return self._getTargetClass().from_data({ 'object': 'transfer', @@ -142,6 +146,43 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(transfers[0].amount, 96350) self.assertRequest(api_call, 'https://api.omise.co/transfers') + @mock.patch('requests.get') + def test_list(self, api_call): + class_ = self._getTargetClass() + lazy_collection_class_ = self._getLazyCollectionClass() + self.mockResponse(api_call, """{ + "object": "list", + "from": "1970-01-01T07:00:00+07:00", + "to": "2014-10-27T11:36:24+07:00", + "offset": 0, + "limit": 20, + "total": 1, + "data": [ + { + "object": "transfer", + "id": "trsf_test", + "livemode": false, + "location": "/transfers/trsf_test", + "sent": false, + "paid": false, + "amount": 96350, + "currency": "thb", + "failure_code": null, + "failure_message": null, + "transaction": null, + "created": "2014-11-18T11:31:26Z" + } + ] + }""") + + transfers = class_.list() + self.assertTrue(isinstance(transfers, lazy_collection_class_)) + + transfers = list(transfers) + self.assertTrue(isinstance(transfers[0], class_)) + self.assertTrue(transfers[0].id, 'trsf_test') + self.assertTrue(transfers[0].amount, 96350) + @mock.patch('requests.patch') def test_update(self, api_call): transfer = self._makeOne()