Skip to content

Commit

Permalink
Change exception type when detaching unattached sources to InvalidReq…
Browse files Browse the repository at this point in the history
…uestError
  • Loading branch information
ob-stripe committed Jun 19, 2018
1 parent b11775c commit f5f46c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions stripe/api_resources/source.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import, division, print_function

from stripe import util
from stripe import error, util
from stripe.api_resources import Customer
from stripe.api_resources.abstract import CreateableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
Expand All @@ -12,8 +12,10 @@ class Source(CreateableAPIResource, UpdateableAPIResource, VerifyMixin):
OBJECT_NAME = 'source'

def detach(self, idempotency_key=None, **params):
token = util.utf8(self.id)

if hasattr(self, 'customer') and self.customer:
extn = quote_plus(util.utf8(self.id))
extn = quote_plus(token)
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = quote_plus(customer)
Expand All @@ -24,9 +26,9 @@ def detach(self, idempotency_key=None, **params):
return self

else:
raise NotImplementedError(
"This source object does not appear to be currently attached "
"to a customer object.")
raise error.InvalidRequestError(
"Source %s does not appear to be currently attached "
"to a customer object." % token, 'id')

def source_transactions(self, **params):
return self.request(
Expand Down
2 changes: 1 addition & 1 deletion tests/api_resources/test_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_is_detachable_when_attached(self, request_mock):

def test_is_not_detachable_when_unattached(self):
resource = stripe.Source.retrieve(TEST_RESOURCE_ID)
with pytest.raises(NotImplementedError):
with pytest.raises(stripe.error.InvalidRequestError):
resource.detach()

def test_is_verifiable(self, request_mock):
Expand Down

0 comments on commit f5f46c0

Please sign in to comment.