1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import pytest
import stripe
TEST_RESOURCE_ID = "ba_123"
class TestBankAccountTest(object):
def construct_resource(self, **params):
bank_dict = {
"id": TEST_RESOURCE_ID,
"object": "bank_account",
"metadata": {},
}
bank_dict.update(params)
return stripe.BankAccount.construct_from(bank_dict, stripe.api_key)
def test_has_account_instance_url(self):
resource = self.construct_resource(account="acct_123")
assert (
resource.instance_url()
== "/v1/accounts/acct_123/external_accounts/%s" % TEST_RESOURCE_ID
)
def test_has_customer_instance_url(self):
resource = self.construct_resource(customer="cus_123")
assert (
resource.instance_url()
== "/v1/customers/cus_123/sources/%s" % TEST_RESOURCE_ID
)
# The previous tests already ensure that the request will be routed to the
# correct URL, so we only test the API operations once.
def test_is_not_retrievable(self):
with pytest.raises(NotImplementedError):
stripe.BankAccount.retrieve(TEST_RESOURCE_ID)
def test_is_saveable(self, http_client_mock):
resource = self.construct_resource(customer="cus_123")
resource.metadata["key"] = "value"
resource.save()
http_client_mock.assert_requested(
"post",
path="/v1/customers/cus_123/sources/%s" % TEST_RESOURCE_ID,
post_data="metadata[key]=value",
)
def test_is_not_modifiable(self):
with pytest.raises(NotImplementedError):
stripe.BankAccount.modify(
TEST_RESOURCE_ID, metadata={"key": "value"}
)
def test_is_deletable(self, http_client_mock):
resource = self.construct_resource(customer="cus_123")
resource.delete()
http_client_mock.assert_requested(
"delete",
path="/v1/customers/cus_123/sources/%s" % TEST_RESOURCE_ID,
)
def test_is_verifiable(self, http_client_mock):
resource = self.construct_resource(customer="cus_123")
resource.verify()
http_client_mock.assert_requested(
"post",
path="/v1/customers/cus_123/sources/%s/verify" % TEST_RESOURCE_ID,
post_data="",
)
|