From f5a613bdceac2900ef98a49a696e585053f2ac0d Mon Sep 17 00:00:00 2001 From: Daniel Fowler Date: Tue, 4 Aug 2020 17:19:04 +0700 Subject: [PATCH 1/3] Add update method for Account --- omise/__init__.py | 8 +++++ omise/test/test_account.py | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/omise/__init__.py b/omise/__init__.py index 203ff26..b82ca05 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -252,6 +252,14 @@ def reload(self): """ return self._reload_data(self._request('get', self._instance_path())) + def update(self, **kwargs): + changed = copy.deepcopy(self.changes) + changed.update(kwargs) + return self._reload_data( + self._request('patch', + self._attributes['location'], + changed)) + class Balance(_MainResource, Base): """API class representing balance details. diff --git a/omise/test/test_account.py b/omise/test/test_account.py index 33da0d1..197c352 100644 --- a/omise/test/test_account.py +++ b/omise/test/test_account.py @@ -10,6 +10,16 @@ def _getTargetClass(self): from .. import Account return Account + def _makeOne(self): + return self._getTargetClass().from_data({ + "object": "account", + "location": "/account", + "id": "acct_test", + "email": None, + "created": "2014-10-20T08:21:42Z", + "chain_enabled": False + }) + @mock.patch('requests.get') def test_retrieve(self, api_call): class_ = self._getTargetClass() @@ -36,3 +46,57 @@ def test_retrieve(self, api_call): account.reload() self.assertEqual(account.id, 'acct_foo') self.assertRequest(api_call, 'https://api.omise.co/account') + + + @mock.patch('requests.patch') + def test_update(self, api_call): + account = self._makeOne() + class_ = self._getTargetClass() + self.mockResponse(api_call, """{ + "object": "account", + "id": "account_test_no1t4tnemucod0e51mo", + "team": "acct_no1t4tnemucod0e51mo", + "livemode": false, + "location": "/account", + "country": "TH", + "currency": "THB", + "email": "somchai.prasert@example.com", + "created_at": "2019-12-31T12:59:59Z", + "supported_currencies": [ + "THB", + "JPY", + "USD", + "EUR", + "GBP", + "SGD", + "AUD", + "CHF", + "CNY", + "DKK", + "HKD" + ], + "api_version": "2019-05-29", + "auto_activate_recipients": true, + "chain_enabled": true, + "zero_interest_installments": true, + "chain_return_uri": "https://dashboard.omise.co/test/settings", + "webhook_uri": "https://omise-flask-example.herokuapp.com/webhook", + "metadata_export_keys": { + "charge": [ + "color", + "order_id" + ] + } + }""") + + self.assertTrue(isinstance(account, class_)) + account.chain_enabled = True + account.update() + self.assertEqual(account.chain_enabled, True) + self.assertRequest( + api_call, + 'https://api.omise.co/account', + { + 'chain_enabled': True, + } + ) From fa8a06f9a8e7820841fcb2feeb9b18d972cf6150 Mon Sep 17 00:00:00 2001 From: Daniel Fowler Date: Wed, 5 Aug 2020 08:43:30 +0700 Subject: [PATCH 2/3] Add docstring --- omise/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/omise/__init__.py b/omise/__init__.py index b82ca05..6d36f49 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -253,6 +253,26 @@ def reload(self): return self._reload_data(self._request('get', self._instance_path())) def update(self, **kwargs): + """Update account settings with the given arguments. + + See the `update an account`_ section in the API documentation for list + of available arguments. + + Basic usage:: + + >>> import omise + >>> omise.api_secret = 'skey_test_4xs8breq3htbkj03d2x' + >>> account = omise.Account.retrieve() + >>> account.update(webhook_uri='https://omise-flask-example.herokuapp.com/webhook') + + + :param \*\*kwargs: arguments to update an account. + :rtype: Account + + .. _update an account: + .. https://www.omise.co/account-api#update + """ + changed = copy.deepcopy(self.changes) changed.update(kwargs) return self._reload_data( From 8992381832f445d3f75b37fd03dd57dbdc55315e Mon Sep 17 00:00:00 2001 From: Daniel Fowler Date: Wed, 5 Aug 2020 16:26:19 +0700 Subject: [PATCH 3/3] Make test clearer --- omise/test/test_account.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/omise/test/test_account.py b/omise/test/test_account.py index 197c352..da83b73 100644 --- a/omise/test/test_account.py +++ b/omise/test/test_account.py @@ -79,7 +79,7 @@ def test_update(self, api_call): "auto_activate_recipients": true, "chain_enabled": true, "zero_interest_installments": true, - "chain_return_uri": "https://dashboard.omise.co/test/settings", + "chain_return_uri": "https://omise-flask-example.herokuapp.com", "webhook_uri": "https://omise-flask-example.herokuapp.com/webhook", "metadata_export_keys": { "charge": [ @@ -90,9 +90,9 @@ def test_update(self, api_call): }""") self.assertTrue(isinstance(account, class_)) - account.chain_enabled = True - account.update() - self.assertEqual(account.chain_enabled, True) + self.assertFalse(account.chain_enabled) + account.update(chain_enabled=True) + self.assertTrue(account.chain_enabled) self.assertRequest( api_call, 'https://api.omise.co/account',