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

Change exception type when detaching unattached sources to InvalidRequestError #415

Merged
merged 1 commit into from
Mar 15, 2018
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
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