From c71d1643f53ef640486a48ba292b1a9f790a69de Mon Sep 17 00:00:00 2001 From: crosalot Date: Wed, 14 Feb 2018 14:42:35 +0700 Subject: [PATCH 1/2] add Card.retrieve(customer_id, card_id) with rquest from api --- omise/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/omise/__init__.py b/omise/__init__.py index 241b816..3f0d5d7 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -413,6 +413,22 @@ class Card(_MainResource, Base): '4242' """ + @classmethod + def _instance_path(cls, customer_id, card_id): + return ('customers', customer_id, 'cards', card_id) + + @classmethod + def retrieve(cls, customer_id, card_id): + """Retrieve the card details for the given :param:`card_id`. + + :param customer_id: a customer id of card id. + :type customer_id: str + :param card_id: a card id to retrieve. + :type card_id: str + :rtype: Card + """ + return _as_object(cls._request('get', cls._instance_path(customer_id, card_id))) + def reload(self): """Reload the card details. From ce23ff600c5864d2cff55c4f2c0dc5aa5dc73028 Mon Sep 17 00:00:00 2001 From: Daniel Fowler Date: Thu, 6 Aug 2020 14:57:39 +0700 Subject: [PATCH 2/2] Add test for one-line card retrieval --- omise/test/test_card.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/omise/test/test_card.py b/omise/test/test_card.py index 33c36d1..2ea2d88 100644 --- a/omise/test/test_card.py +++ b/omise/test/test_card.py @@ -64,6 +64,34 @@ def test_reload(self, api_call): 'https://api.omise.co/customers/cust_test/cards/card_test' ) + @mock.patch('requests.get') + def test_retrieve(self, api_call): + class_ = self._getTargetClass() + + self.mockResponse(api_call, """{ + "object": "card", + "id": "card_test", + "livemode": false, + "location": "/customers/cust_test/cards/card_test", + "country": "", + "city": "Bangkok", + "postal_code": "10310", + "financing": "", + "last_digits": "4242", + "brand": "Visa", + "expiration_month": 12, + "expiration_year": 2018, + "fingerprint": "098f6bcd4621d373cade4e832627b4f6", + "name": "Somchai Prasert", + "created": "2014-10-21T04:04:12Z" + }""") + + card = class_.retrieve('cust_test', 'card_test') + self.assertTrue(isinstance(card, class_)) + self.assertEqual(card.id, 'card_test') + self.assertEqual(card.name, 'Somchai Prasert') + self.assertRequest(api_call, 'https://api.omise.co/customers/cust_test/cards/card_test') + @mock.patch('requests.patch') def test_update(self, api_call): card = self._makeOne()