-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9a8d75
commit 3b3104b
Showing
8 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
from stripe import util | ||
from stripe.api_resources.account import Account | ||
from stripe.api_resources.abstract import UpdateableAPIResource | ||
from stripe.six.moves.urllib.parse import quote_plus | ||
|
||
|
||
class Person(UpdateableAPIResource): | ||
OBJECT_NAME = 'person' | ||
|
||
def instance_url(self): | ||
token = util.utf8(self.id) | ||
account = util.utf8(self.account) | ||
base = Account.class_url() | ||
acct_extn = quote_plus(account) | ||
extn = quote_plus(token) | ||
return "%s/%s/persons/%s" % (base, acct_extn, extn) | ||
|
||
@classmethod | ||
def modify(cls, sid, **params): | ||
raise NotImplementedError( | ||
"Can't modify a person without an account" | ||
"ID. Call save on account.persons.retrieve('person_id')") | ||
|
||
@classmethod | ||
def retrieve(cls, id, api_key=None, **params): | ||
raise NotImplementedError( | ||
"Can't retrieve a person without an account" | ||
"ID. Use account.persons.retrieve('person_id')") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from __future__ import absolute_import, division, print_function | ||
|
||
import pytest | ||
|
||
import stripe | ||
|
||
|
||
TEST_RESOURCE_ID = 'trr_123' | ||
|
||
|
||
class TestPerson(object): | ||
def construct_resource(self): | ||
person_dict = { | ||
'id': TEST_RESOURCE_ID, | ||
'object': 'person', | ||
'account': 'acct_123' | ||
} | ||
return stripe.Person.construct_from(person_dict, stripe.api_key) | ||
|
||
def test_has_instance_url(self, request_mock): | ||
resource = self.construct_resource() | ||
assert resource.instance_url() == \ | ||
'/v1/accounts/acct_123/persons/%s' % TEST_RESOURCE_ID | ||
|
||
def test_is_not_modifiable(self, request_mock): | ||
with pytest.raises(NotImplementedError): | ||
stripe.Person.modify( | ||
TEST_RESOURCE_ID, | ||
first_name='John' | ||
) | ||
|
||
def test_is_not_retrievable(self, request_mock): | ||
with pytest.raises(NotImplementedError): | ||
stripe.Person.retrieve(TEST_RESOURCE_ID) | ||
|
||
def test_is_saveable(self, request_mock): | ||
resource = self.construct_resource() | ||
resource.first_name = 'John' | ||
resource.save() | ||
request_mock.assert_requested( | ||
'post', | ||
'/v1/accounts/acct_123/persons/%s' % TEST_RESOURCE_ID | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters