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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
import stripe
TEST_RESOURCE_ID = "cus_123"
TEST_SUB_ID = "sub_123"
TEST_SOURCE_ID = "ba_123"
TEST_TAX_ID_ID = "txi_123"
TEST_TRANSACTION_ID = "cbtxn_123"
class TestCustomer(object):
def test_is_listable(self, http_client_mock):
resources = stripe.Customer.list()
http_client_mock.assert_requested("get", path="/v1/customers")
assert isinstance(resources.data, list)
assert isinstance(resources.data[0], stripe.Customer)
def test_is_retrievable(self, http_client_mock):
resource = stripe.Customer.retrieve(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"get", path="/v1/customers/%s" % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.Customer)
def test_is_creatable(self, http_client_mock):
resource = stripe.Customer.create()
http_client_mock.assert_requested("post", path="/v1/customers")
assert isinstance(resource, stripe.Customer)
def test_is_saveable(self, http_client_mock):
resource = stripe.Customer.retrieve(TEST_RESOURCE_ID)
resource.metadata["key"] = "value"
resource.save()
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s" % TEST_RESOURCE_ID,
post_data="metadata[key]=value",
)
def test_is_modifiable(self, http_client_mock):
resource = stripe.Customer.modify(
TEST_RESOURCE_ID, metadata={"key": "value"}
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s" % TEST_RESOURCE_ID,
post_data="metadata[key]=value",
)
assert isinstance(resource, stripe.Customer)
def test_is_deletable(self, http_client_mock):
resource = stripe.Customer.retrieve(TEST_RESOURCE_ID)
resource.delete()
http_client_mock.assert_requested(
"delete", path="/v1/customers/%s" % TEST_RESOURCE_ID
)
assert resource.deleted is True
def test_can_delete(self, http_client_mock):
resource = stripe.Customer.delete(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"delete", path="/v1/customers/%s" % TEST_RESOURCE_ID
)
assert resource.deleted is True
def test_can_delete_discount(self, http_client_mock):
resource = stripe.Customer.retrieve(TEST_RESOURCE_ID)
resource.delete_discount()
http_client_mock.assert_requested(
"delete", path="/v1/customers/%s/discount" % TEST_RESOURCE_ID
)
def test_can_delete_discount_class_method(self, http_client_mock):
stripe.Customer.delete_discount(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"delete", path="/v1/customers/%s/discount" % TEST_RESOURCE_ID
)
class TestCustomerSources(object):
def test_is_creatable(self, http_client_mock):
stripe.Customer.create_source(TEST_RESOURCE_ID, source="btok_123")
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s/sources" % TEST_RESOURCE_ID,
post_data="source=btok_123",
)
def test_is_retrievable(self, http_client_mock):
stripe.Customer.retrieve_source(TEST_RESOURCE_ID, TEST_SOURCE_ID)
http_client_mock.assert_requested(
"get",
path="/v1/customers/%s/sources/%s"
% (TEST_RESOURCE_ID, TEST_SOURCE_ID),
)
def test_is_modifiable(self, http_client_mock):
stripe.Customer.modify_source(
TEST_RESOURCE_ID, TEST_SOURCE_ID, metadata={"foo": "bar"}
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s/sources/%s"
% (TEST_RESOURCE_ID, TEST_SOURCE_ID),
post_data="metadata[foo]=bar",
)
def test_is_deletable(self, http_client_mock):
stripe.Customer.delete_source(TEST_RESOURCE_ID, TEST_SOURCE_ID)
http_client_mock.assert_requested(
"delete",
path="/v1/customers/%s/sources/%s"
% (TEST_RESOURCE_ID, TEST_SOURCE_ID),
)
def test_is_listable(self, http_client_mock):
resources = stripe.Customer.list_sources(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"get", path="/v1/customers/%s/sources" % TEST_RESOURCE_ID
)
assert isinstance(resources.data, list)
class TestCustomerTaxIds(object):
def test_is_creatable(self, http_client_mock):
resource = stripe.Customer.create_tax_id(
TEST_RESOURCE_ID, type="eu_vat", value="11111"
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s/tax_ids" % TEST_RESOURCE_ID,
post_data="type=eu_vat&value=11111",
)
assert isinstance(resource, stripe.TaxId)
def test_is_retrievable(self, http_client_mock):
stripe.Customer.retrieve_tax_id(TEST_RESOURCE_ID, TEST_TAX_ID_ID)
http_client_mock.assert_requested(
"get",
path="/v1/customers/%s/tax_ids/%s"
% (TEST_RESOURCE_ID, TEST_TAX_ID_ID),
)
def test_is_deletable(self, http_client_mock):
stripe.Customer.delete_tax_id(TEST_RESOURCE_ID, TEST_TAX_ID_ID)
http_client_mock.assert_requested(
"delete",
path="/v1/customers/%s/tax_ids/%s"
% (TEST_RESOURCE_ID, TEST_TAX_ID_ID),
)
def test_is_listable(self, http_client_mock):
resources = stripe.Customer.list_tax_ids(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"get", path="/v1/customers/%s/tax_ids" % TEST_RESOURCE_ID
)
assert isinstance(resources.data, list)
class TestCustomerTransactions(object):
def test_is_creatable(self, http_client_mock):
resource = stripe.Customer.create_balance_transaction(
TEST_RESOURCE_ID, amount=1234, currency="usd"
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/%s/balance_transactions" % TEST_RESOURCE_ID,
)
assert isinstance(resource, stripe.CustomerBalanceTransaction)
def test_is_retrievable(self, http_client_mock):
stripe.Customer.retrieve_balance_transaction(
TEST_RESOURCE_ID, TEST_TRANSACTION_ID
)
http_client_mock.assert_requested(
"get",
path="/v1/customers/%s/balance_transactions/%s"
% (TEST_RESOURCE_ID, TEST_TRANSACTION_ID),
)
def test_is_listable(self, http_client_mock):
resources = stripe.Customer.list_balance_transactions(TEST_RESOURCE_ID)
http_client_mock.assert_requested(
"get",
path="/v1/customers/%s/balance_transactions" % TEST_RESOURCE_ID,
)
assert isinstance(resources.data, list)
class TestCustomerPaymentMethods(object):
def test_is_listable(self, http_client_mock):
stripe.Customer.list_payment_methods(TEST_RESOURCE_ID, type="card")
http_client_mock.assert_requested(
"get", path="/v1/customers/%s/payment_methods" % TEST_RESOURCE_ID
)
def test_is_listable_on_object(self, http_client_mock):
resource = stripe.Customer.retrieve(
TEST_RESOURCE_ID
).list_payment_methods(type="card")
http_client_mock.assert_requested(
"get", path="/v1/customers/%s/payment_methods" % TEST_RESOURCE_ID
)
assert isinstance(resource, stripe.ListObject)
class TestCustomerCashBalanceMethods(object):
# These tests are present for compatibility purposes. Previously the cash
# balance methods required None as a second nested_id parameter. The method
# has been patched to no longer require this, but we want to preserve
# compatibility for existing users.
def test_customer_cashbalance_retrieve_legacy_call_pattern(
self, http_client_mock
):
stripe.Customer.retrieve_cash_balance("cus_123")
http_client_mock.assert_requested(
"get", path="/v1/customers/cus_123/cash_balance"
)
def test_customer_cashbalance_modify_legacy_call_pattern(
self, http_client_mock
):
stripe.Customer.modify_cash_balance(
"cus_123",
settings={"reconciliation_mode": "manual"},
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/cus_123/cash_balance",
post_data="settings[reconciliation_mode]=manual",
)
def test_customer_cashbalance_modify_fixed_pattern(self, http_client_mock):
stripe.Customer.modify_cash_balance(
"cus_123",
settings={"reconciliation_mode": "manual"},
)
http_client_mock.assert_requested(
"post",
path="/v1/customers/cus_123/cash_balance",
post_data="settings[reconciliation_mode]=manual",
)
|