Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions omise/test/test_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down
123 changes: 123 additions & 0 deletions omise/test/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down Expand Up @@ -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()
Expand Down
66 changes: 66 additions & 0 deletions omise/test/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down
39 changes: 39 additions & 0 deletions omise/test/test_dispute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions omise/test/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Loading