-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the Capability resource and APIs (#566)
- Loading branch information
1 parent
25b21ce
commit a1df6d1
Showing
9 changed files
with
127 additions
and
5 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
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,32 @@ | ||
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 Capability(UpdateableAPIResource): | ||
OBJECT_NAME = "capability" | ||
|
||
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/capabilities/%s" % (base, acct_extn, extn) | ||
|
||
@classmethod | ||
def modify(cls, sid, **params): | ||
raise NotImplementedError( | ||
"Can't update a capability without an account ID. Update a capability using " | ||
"account.modify_capability('acct_123', 'acap_123', params)" | ||
) | ||
|
||
@classmethod | ||
def retrieve(cls, id, api_key=None, **params): | ||
raise NotImplementedError( | ||
"Can't retrieve a capability without an account ID. Retrieve a capability using " | ||
"account.retrieve_capability('acct_123', 'acap_123')" | ||
) |
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 = "acap_123" | ||
|
||
|
||
class TestCapability(object): | ||
def construct_resource(self): | ||
capability_dict = { | ||
"id": TEST_RESOURCE_ID, | ||
"object": "capability", | ||
"account": "acct_123", | ||
} | ||
return stripe.Capability.construct_from( | ||
capability_dict, stripe.api_key | ||
) | ||
|
||
def test_has_instance_url(self, request_mock): | ||
resource = self.construct_resource() | ||
assert ( | ||
resource.instance_url() | ||
== "/v1/accounts/acct_123/capabilities/%s" % TEST_RESOURCE_ID | ||
) | ||
|
||
def test_is_not_modifiable(self, request_mock): | ||
with pytest.raises(NotImplementedError): | ||
stripe.Capability.modify(TEST_RESOURCE_ID, requested=True) | ||
|
||
def test_is_not_retrievable(self, request_mock): | ||
with pytest.raises(NotImplementedError): | ||
stripe.Capability.retrieve(TEST_RESOURCE_ID) | ||
|
||
def test_is_saveable(self, request_mock): | ||
resource = self.construct_resource() | ||
resource.requested = True | ||
resource.save() | ||
request_mock.assert_requested( | ||
"post", "/v1/accounts/acct_123/capabilities/%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