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

Fixed error when getting instance_url from resources without id #10

Merged
merged 3 commits into from
Mar 2, 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
4 changes: 0 additions & 4 deletions payjp/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ def __init__(self, message, param, code, http_body=None,
self.code = code


class InvalidRequestError(PayjpException):
pass


class AuthenticationError(PayjpException):
pass

Expand Down
3 changes: 2 additions & 1 deletion payjp/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def class_url(cls):
def instance_url(self):
id = self.get('id')
if not id:
raise error.InvalidRequestError
raise error.InvalidRequestError("Could not create instance url without it's id",
None)

base = self.class_url()
ext = quote_plus(id)
Expand Down
6 changes: 6 additions & 0 deletions payjp/test/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ def test_retrieve(self):

class APIResourceTests(PayjpApiTestCase):

def test_instance_url_without_id(self):
from payjp.error import InvalidRequestError
resource = MyResource.construct_from({'id': None}, 'mykey')
with self.assertRaises(InvalidRequestError):
resource.instance_url()

def test_retrieve_and_refresh(self):
self.mock_response({
'id': 'foo2',
Expand Down