Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add destroy method for Link #39

Merged
merged 1 commit into from
Jan 26, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
.eggs/
.vagrant/
dist/
.DS_Store

# Tests
.coverage
Expand Down
27 changes: 27 additions & 0 deletions omise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 id='link_test_5dsoxxan7gxrqihu8rs' at 0x7fcc349bdd90>
>>> 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.
Expand Down
48 changes: 48 additions & 0 deletions omise/test/test_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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'
)