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

detach method for detaching sources from customers #349

Merged
merged 1 commit into from
Oct 11, 2017
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
14 changes: 10 additions & 4 deletions stripe/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ def class_url(cls):


class Source(CreateableAPIResource, UpdateableAPIResource, VerifyMixin):
def delete(self, **params):
def detach(self, **params):
if hasattr(self, 'customer') and self.customer:
extn = urllib.quote_plus(util.utf8(self.id))
customer = util.utf8(self.customer)
Expand All @@ -1197,6 +1197,12 @@ def delete(self, **params):

else:
raise NotImplementedError(
'Source objects cannot be deleted, they can only be detached '
'from customer objects. This source object does not appear to '
'be currently attached to a customer object.')
"This source object does not appear to be currently attached "
"to a customer object.")

def delete(self, **params):
warnings.warn("The `Source.delete` method is deprecated and will "
"be removed in future versions. Please use the "
"`Source.detach` method instead",
DeprecationWarning)
self.detach(**params)
23 changes: 19 additions & 4 deletions stripe/test/resources/test_sources.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import warnings

import stripe
from stripe.test.helper import StripeResourceTest

Expand Down Expand Up @@ -46,18 +48,18 @@ def test_update_source(self):
None
)

def test_delete_source_unattached(self):
def test_detach_source_unattached(self):
source = stripe.Source.construct_from({
'id': 'src_foo',
}, 'api_key')
self.assertRaises(NotImplementedError, source.delete)
self.assertRaises(NotImplementedError, source.detach)

def test_delete_source_attached(self):
def test_detach_source_attached(self):
source = stripe.Source.construct_from({
'id': 'src_foo',
'customer': 'cus_bar',
}, 'api_key')
source.delete()
source.detach()

self.requestor_mock.request.assert_called_with(
'delete',
Expand All @@ -66,6 +68,19 @@ def test_delete_source_attached(self):
None
)

def test_delete_source(self):
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')

source = stripe.Source.construct_from({
'id': 'src_foo',
'customer': 'cus_bar',
}, 'api_key')
source.delete()

self.assertEqual(1, len(w))
self.assertEqual(w[0].category, DeprecationWarning)

def test_verify_source(self):
source = stripe.Source.construct_from({
'id': 'src_foo',
Expand Down