File: test_account.py

package info (click to toggle)
python-stripe 12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,864 kB
  • sloc: python: 157,573; makefile: 13; sh: 9
file content (286 lines) | stat: -rw-r--r-- 10,648 bytes parent folder | download
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import stripe
import json


TEST_RESOURCE_ID = "acct_123"
TEST_CAPABILITY_ID = "acap_123"
TEST_EXTERNALACCOUNT_ID = "ba_123"
TEST_PERSON_ID = "person_123"


class TestAccount(object):
    def test_is_listable(self, http_client_mock):
        resources = stripe.Account.list()
        http_client_mock.assert_requested("get", path="/v1/accounts")
        assert isinstance(resources.data, list)
        assert isinstance(resources.data[0], stripe.Account)

    def test_is_retrievable(self, http_client_mock):
        resource = stripe.Account.retrieve(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "get", path="/v1/accounts/%s" % TEST_RESOURCE_ID
        )
        assert isinstance(resource, stripe.Account)

    def test_is_creatable(self, http_client_mock):
        resource = stripe.Account.create(country="US", type="custom")
        http_client_mock.assert_requested("post", path="/v1/accounts")
        assert isinstance(resource, stripe.Account)

    def test_is_saveable(self, http_client_mock):
        account = stripe.Account.retrieve(TEST_RESOURCE_ID)
        account.metadata["key"] = "value"
        resource = account.save()
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s" % TEST_RESOURCE_ID,
            post_data="metadata[key]=value",
        )
        assert isinstance(resource, stripe.Account)
        assert resource is account

    def test_is_saveable_with_individual(self, http_client_mock):
        individual = stripe.Person.construct_from(
            {"id": "person_123", "object": "person", "first_name": "Jenny"},
            stripe.api_key,
        )
        account = stripe.Account.construct_from(
            {"id": "acct_123", "object": "account", "individual": individual},
            stripe.api_key,
        )

        account.individual.first_name = "Jane"

        http_client_mock.stub_request(
            "post",
            path="/v1/accounts/%s" % TEST_RESOURCE_ID,
            rbody=json.dumps(account.to_dict_recursive()),
        )
        resource = account.save()
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s" % TEST_RESOURCE_ID,
            post_data="individual[first_name]=Jane",
        )
        assert isinstance(resource, stripe.Account)
        assert resource is account

    def test_is_modifiable(self, http_client_mock):
        resource = stripe.Account.modify(
            TEST_RESOURCE_ID, metadata={"key": "value"}
        )
        http_client_mock.assert_requested(
            "post", path="/v1/accounts/%s" % TEST_RESOURCE_ID
        )
        assert isinstance(resource, stripe.Account)

    def test_is_deletable(self, http_client_mock):
        resource = stripe.Account.retrieve(TEST_RESOURCE_ID)
        resource.delete()
        http_client_mock.assert_requested(
            "delete", path="/v1/accounts/%s" % TEST_RESOURCE_ID
        )
        assert resource.deleted is True

    def test_can_delete(self, http_client_mock):
        resource = stripe.Account.delete(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "delete", path="/v1/accounts/%s" % TEST_RESOURCE_ID
        )
        assert resource.deleted is True

    def test_can_retrieve_no_id(self, http_client_mock):
        resource = stripe.Account.retrieve()
        http_client_mock.assert_requested("get", path="/v1/account")
        assert isinstance(resource, stripe.Account)

    def test_can_reject(self, http_client_mock):
        account = stripe.Account.retrieve(TEST_RESOURCE_ID)
        resource = account.reject(reason="fraud")
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s/reject" % TEST_RESOURCE_ID,
            post_data="reason=fraud",
        )
        assert isinstance(resource, stripe.Account)
        assert resource is account

    def test_can_reject_classmethod(self, http_client_mock):
        resource = stripe.Account.reject(TEST_RESOURCE_ID, reason="fraud")
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s/reject" % TEST_RESOURCE_ID,
            post_data="reason=fraud",
        )
        assert isinstance(resource, stripe.Account)

    def test_is_deauthorizable(self, http_client_mock):
        account = stripe.Account.retrieve(TEST_RESOURCE_ID)
        http_client_mock.stub_request(
            "post",
            path="/oauth/deauthorize",
            rbody='{"stripe_user_id": "%s"}' % account.id,
        )
        account.deauthorize()
        http_client_mock.assert_requested(
            "post",
            path="/oauth/deauthorize",
            post_data="client_id=%s&stripe_user_id=%s"
            % (
                stripe.client_id,
                account.id,
            ),
        )

    def test_can_call_persons(self, http_client_mock):
        account = stripe.Account.retrieve(TEST_RESOURCE_ID)
        resources = account.persons()
        http_client_mock.assert_requested(
            "get", path="/v1/accounts/%s/persons" % TEST_RESOURCE_ID
        )
        assert isinstance(resources.data, list)
        assert isinstance(resources.data[0], stripe.Person)


class TestAccountCapabilities(object):
    def test_is_listable(self, http_client_mock):
        resources = stripe.Account.list_capabilities(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "get", path="/v1/accounts/%s/capabilities" % TEST_RESOURCE_ID
        )
        assert isinstance(resources.data, list)
        assert isinstance(resources.data[0], stripe.Capability)

    def test_is_modifiable(self, http_client_mock):
        resource = stripe.Account.modify_capability(
            TEST_RESOURCE_ID, TEST_CAPABILITY_ID, requested=True
        )
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s/capabilities/%s"
            % (TEST_RESOURCE_ID, TEST_CAPABILITY_ID),
        )
        assert isinstance(resource, stripe.Capability)

    def test_is_retrievable(self, http_client_mock):
        resource = stripe.Account.retrieve_capability(
            TEST_RESOURCE_ID, TEST_CAPABILITY_ID
        )
        http_client_mock.assert_requested(
            "get",
            path="/v1/accounts/%s/capabilities/%s"
            % (TEST_RESOURCE_ID, TEST_CAPABILITY_ID),
        )
        assert isinstance(resource, stripe.Capability)


class TestAccountExternalAccounts(object):
    def test_is_listable(self, http_client_mock):
        resources = stripe.Account.list_external_accounts(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "get", path="/v1/accounts/%s/external_accounts" % TEST_RESOURCE_ID
        )
        assert isinstance(resources.data, list)

    def test_is_retrievable(self, http_client_mock):
        resource = stripe.Account.retrieve_external_account(
            TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID
        )
        http_client_mock.assert_requested(
            "get",
            path="/v1/accounts/%s/external_accounts/%s"
            % (TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID),
        )
        assert isinstance(resource, stripe.BankAccount)

    def test_is_creatable(self, http_client_mock):
        resource = stripe.Account.create_external_account(
            TEST_RESOURCE_ID, external_account="btok_123"
        )
        http_client_mock.assert_requested(
            "post", path="/v1/accounts/%s/external_accounts" % TEST_RESOURCE_ID
        )
        assert isinstance(resource, stripe.BankAccount)

    def test_is_modifiable(self, http_client_mock):
        resource = stripe.Account.modify_external_account(
            TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID, metadata={"foo": "bar"}
        )
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s/external_accounts/%s"
            % (TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID),
        )
        assert isinstance(resource, stripe.BankAccount)

    def test_is_deletable(self, http_client_mock):
        resource = stripe.Account.delete_external_account(
            TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID
        )
        http_client_mock.assert_requested(
            "delete",
            path="/v1/accounts/%s/external_accounts/%s"
            % (TEST_RESOURCE_ID, TEST_EXTERNALACCOUNT_ID),
        )
        assert resource.deleted is True


class TestAccountLoginLinks(object):
    def test_is_creatable(self, http_client_mock):
        resource = stripe.Account.create_login_link(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "post", path="/v1/accounts/%s/login_links" % TEST_RESOURCE_ID
        )
        assert isinstance(resource, stripe.LoginLink)


class TestAccountPersons(object):
    def test_is_creatable(self, http_client_mock):
        resource = stripe.Account.create_person(
            TEST_RESOURCE_ID, dob={"day": 1, "month": 1, "year": 1980}
        )
        http_client_mock.assert_requested(
            "post", path="/v1/accounts/%s/persons" % TEST_RESOURCE_ID
        )
        assert isinstance(resource, stripe.Person)

    def test_is_deletable(self, http_client_mock):
        resource = stripe.Account.delete_person(
            TEST_RESOURCE_ID, TEST_PERSON_ID
        )
        http_client_mock.assert_requested(
            "delete",
            path="/v1/accounts/%s/persons/%s"
            % (TEST_RESOURCE_ID, TEST_PERSON_ID),
        )
        assert resource.deleted is True

    def test_is_listable(self, http_client_mock):
        resources = stripe.Account.list_persons(TEST_RESOURCE_ID)
        http_client_mock.assert_requested(
            "get", path="/v1/accounts/%s/persons" % TEST_RESOURCE_ID
        )
        assert isinstance(resources.data, list)
        assert isinstance(resources.data[0], stripe.Person)

    def test_is_modifiable(self, http_client_mock):
        resource = stripe.Account.modify_person(
            TEST_RESOURCE_ID, TEST_PERSON_ID, metadata={"foo": "bar"}
        )
        http_client_mock.assert_requested(
            "post",
            path="/v1/accounts/%s/persons/%s"
            % (TEST_RESOURCE_ID, TEST_PERSON_ID),
        )
        assert isinstance(resource, stripe.Person)

    def test_is_retrievable(self, http_client_mock):
        resource = stripe.Account.retrieve_person(
            TEST_RESOURCE_ID, TEST_PERSON_ID
        )
        http_client_mock.assert_requested(
            "get",
            path="/v1/accounts/%s/persons/%s"
            % (TEST_RESOURCE_ID, TEST_PERSON_ID),
        )
        assert isinstance(resource, stripe.Person)