From 3062dad7fe221984d704e94ac5731c3ba7229a59 Mon Sep 17 00:00:00 2001 From: som-m Date: Tue, 26 Jan 2021 10:50:18 +0700 Subject: [PATCH] add link destroy --- .gitignore | 1 + omise/__init__.py | 27 +++++++++++++++++++++++ omise/test/test_link.py | 48 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/.gitignore b/.gitignore index 3df86c1..dcad735 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .eggs/ .vagrant/ dist/ +.DS_Store # Tests .coverage diff --git a/omise/__init__.py b/omise/__init__.py index 0e0274a..c318116 100644 --- a/omise/__init__.py +++ b/omise/__init__.py @@ -1244,6 +1244,33 @@ def reload(self): self._request('get', self._instance_path(self._attributes['id']))) + def destroy(self): + """Delete the link from the server. + + Basic usage:: + + >>> import omise + >>> omise.api_secret = 'skey_test_4xsjvwfnvb2g0l81sjz' + >>> link = omise.Link.retrieve('link_test_5dsoxxan7gxrqihu8rs') + >>> link.destroy() + + >>> link.destroyed + True + + :rtype: Link + """ + return self._reload_data( + self._request('delete', + self._instance_path(self.id))) + + @property + def destroyed(self): + """Returns ``True`` if the link has been deleted. + + :rtype: bool + """ + return self._attributes.get('deleted', False) + class Occurrence(_MainResource, Base): """API class representing occurrence information. diff --git a/omise/test/test_link.py b/omise/test/test_link.py index d0b1922..fa95141 100644 --- a/omise/test/test_link.py +++ b/omise/test/test_link.py @@ -14,6 +14,33 @@ def _getCollectionClass(self): from .. import Collection return Collection + def _makeOne(self): + return self._getTargetClass().from_data({ + 'object': 'link', + 'id': 'link_test', + 'livemode': False, + 'location': '/links/link_test', + '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': None, + 'location': '/links/link_test/charges', + 'data': [] + }, + 'payment_uri': 'http://link.example.com/0BB268C6', + 'created': '2017-03-03T12:16:48Z' + }) + @mock.patch('requests.post') def test_create(self, api_call): class_ = self._getTargetClass() @@ -178,3 +205,24 @@ def test_retrieve_no_args(self, api_call): self.assertTrue(links[1].id, 'link_test_2') self.assertTrue(links[1].amount, 20000) self.assertRequest(api_call, 'https://api.omise.co/links') + + @mock.patch('requests.delete') + def test_destroy(self, api_call): + link = self._makeOne() + class_ = self._getTargetClass() + self.mockResponse(api_call, """{ + "object": "link", + "id": "link_test", + "livemode": false, + "deleted": true + }""") + + self.assertTrue(isinstance(link, class_)) + self.assertEqual(link.id, 'link_test') + + link.destroy() + self.assertTrue(link.destroyed) + self.assertRequest( + api_call, + 'https://api.omise.co/links/link_test' + ) \ No newline at end of file