Skip to content

Commit 080fdf0

Browse files
authored
Upgrade djstripe (#12148)
Closes #9706
1 parent c9df70b commit 080fdf0

File tree

7 files changed

+36
-80
lines changed

7 files changed

+36
-80
lines changed
+14-36
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import requests_mock
12
from unittest import mock
23

34
import django_dynamic_fixture as fixture
@@ -11,44 +12,21 @@ class GoldSignalTests(TestCase):
1112
def setUp(self):
1213
self.user = fixture.get(User)
1314

14-
# Mocking
15-
self.patches = {}
16-
self.mocks = {}
17-
self.patches["requestor"] = mock.patch("stripe.api_requestor.APIRequestor")
18-
19-
for patch in self.patches:
20-
self.mocks[patch] = self.patches[patch].start()
21-
22-
self.mocks["request"] = self.mocks["requestor"].return_value
23-
24-
def tearDown(self):
25-
# TODO: refactor to use request_mocks for these. The current mock
26-
# pattern breaks tests ran after these if tearDown is not called with
27-
# the `.stop` for all the patches. It took me a lot of time to realized
28-
# about this problem.
29-
for _, patch in self.patches.items():
30-
patch.stop()
31-
32-
def mock_request(self, resp=None):
33-
if resp is None:
34-
resp = ({}, "")
35-
self.mocks["request"].request = mock.Mock(side_effect=resp)
36-
37-
def test_delete_subscription(self):
15+
@requests_mock.Mocker(kw="mock_request")
16+
def test_delete_subscription(self, mock_request):
3817
subscription = fixture.get(GoldUser, user=self.user, stripe_id="cus_123")
3918
self.assertIsNotNone(subscription)
40-
self.mock_request(
41-
[
42-
({"id": "cus_123", "object": "customer"}, ""),
43-
({"deleted": True, "customer": "cus_123"}, ""),
44-
]
19+
mock_request.get(
20+
"https://api.stripe.com/v1/customers/cus_123",
21+
json={"id": "cus_123", "object": "customer"},
22+
)
23+
mock_request.delete(
24+
"https://api.stripe.com/v1/customers/cus_123",
25+
json={"deleted": True, "customer": "cus_123"},
4526
)
4627

4728
subscription.delete()
48-
49-
self.mocks["request"].request.assert_has_calls(
50-
[
51-
mock.call("get", "/v1/customers/cus_123", {}, mock.ANY),
52-
mock.call("delete", "/v1/customers/cus_123", {}, mock.ANY),
53-
]
54-
)
29+
assert mock_request.request_history[0]._request.method == "GET"
30+
assert mock_request.request_history[0]._request.url == "https://api.stripe.com/v1/customers/cus_123"
31+
assert mock_request.request_history[1]._request.method == "DELETE"
32+
assert mock_request.request_history[1]._request.url == "https://api.stripe.com/v1/customers/cus_123"

readthedocs/subscriptions/tests/test_event_handlers.py

-13
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,3 @@ def test_subscription_precedence(self):
430430

431431
self.organization.refresh_from_db()
432432
assert self.organization.stripe_subscription == stripe_subscription
433-
434-
def test_register_events(self):
435-
def test_func():
436-
pass
437-
438-
with override_settings(RTD_ALLOW_ORGANIZATIONS=False):
439-
event_handlers.handler("event")(test_func)
440-
441-
self.assertEqual(webhooks.registrations["event"], [])
442-
443-
with override_settings(RTD_ALLOW_ORGANIZATIONS=True):
444-
event_handlers.handler("event")(test_func)
445-
self.assertEqual(webhooks.registrations["event"], [test_func])

requirements/deploy.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ distlib==0.3.9
103103
# virtualenv
104104
dj-pagination==2.5.0
105105
# via -r requirements/pip.txt
106-
dj-stripe==2.6.3
106+
dj-stripe==2.9.0
107107
# via -r requirements/pip.txt
108108
django==4.2.20
109109
# via
@@ -244,9 +244,7 @@ jmespath==1.0.1
244244
# boto3
245245
# botocore
246246
jsonfield==3.1.0
247-
# via
248-
# -r requirements/pip.txt
249-
# dj-stripe
247+
# via -r requirements/pip.txt
250248
kombu==5.5.3
251249
# via
252250
# -r requirements/pip.txt
@@ -405,7 +403,7 @@ sqlparse==0.5.3
405403
# django-debug-toolbar
406404
stack-data==0.6.3
407405
# via ipython
408-
stripe==4.2.0
406+
stripe==11.6.0
409407
# via
410408
# -r requirements/pip.txt
411409
# dj-stripe
@@ -434,6 +432,7 @@ typing-extensions==4.13.2
434432
# pydantic
435433
# pydantic-core
436434
# pygithub
435+
# stripe
437436
# typing-inspection
438437
typing-inspection==0.4.0
439438
# via

requirements/docker.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ distlib==0.3.9
111111
# virtualenv
112112
dj-pagination==2.5.0
113113
# via -r requirements/pip.txt
114-
dj-stripe==2.6.3
114+
dj-stripe==2.9.0
115115
# via -r requirements/pip.txt
116116
django==4.2.20
117117
# via
@@ -257,9 +257,7 @@ jmespath==1.0.1
257257
# boto3
258258
# botocore
259259
jsonfield==3.1.0
260-
# via
261-
# -r requirements/pip.txt
262-
# dj-stripe
260+
# via -r requirements/pip.txt
263261
kombu==5.5.3
264262
# via
265263
# -r requirements/pip.txt
@@ -433,7 +431,7 @@ sqlparse==0.5.3
433431
# django-debug-toolbar
434432
stack-data==0.6.3
435433
# via ipython
436-
stripe==4.2.0
434+
stripe==11.6.0
437435
# via
438436
# -r requirements/pip.txt
439437
# dj-stripe
@@ -461,6 +459,7 @@ typing-extensions==4.13.2
461459
# pydantic
462460
# pydantic-core
463461
# pygithub
462+
# stripe
464463
# typing-inspection
465464
typing-inspection==0.4.0
466465
# via

requirements/pip.in

+6-11
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,14 @@ orjson
7979
django-gravatar2
8080
pytz
8181

82-
# We cannot upgrade it until dj-stripe fixes this issue
83-
# https://github.com/dj-stripe/dj-stripe/issues/1842
84-
stripe==4.2.0
85-
8682
regex
8783

88-
# NOTE: djstripe overrides the stripe api version
89-
# globally, when updating make sure our code is compatible
90-
# with the version used by djstripe.
91-
# See STRIPE_API_VERSION https://dj-stripe.dev/reference/settings/.
92-
# dj-stripe==2.7.0 requires some extra actions to be upgrade
93-
# See https://github.com/readthedocs/readthedocs.org/issues/9706
94-
dj-stripe==2.6.3
84+
# Stripe is pinned because 12.0.1 fails with
85+
#
86+
# AttributeError: module 'stripe' has no attribute 'UsageRecord'
87+
stripe<12
88+
89+
dj-stripe==2.9.0
9590

9691
markdown
9792

requirements/pip.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ distlib==0.3.9
6666
# via virtualenv
6767
dj-pagination==2.5.0
6868
# via -r requirements/pip.in
69-
dj-stripe==2.6.3
69+
dj-stripe==2.9.0
7070
# via -r requirements/pip.in
7171
django==4.2.20
7272
# via
@@ -187,9 +187,7 @@ jmespath==1.0.1
187187
# boto3
188188
# botocore
189189
jsonfield==3.1.0
190-
# via
191-
# -r requirements/pip.in
192-
# dj-stripe
190+
# via -r requirements/pip.in
193191
kombu==5.5.3
194192
# via celery
195193
lexid==2021.1006
@@ -296,7 +294,7 @@ sqlparse==0.5.3
296294
# via
297295
# django
298296
# django-debug-toolbar
299-
stripe==4.2.0
297+
stripe==11.6.0
300298
# via
301299
# -r requirements/pip.in
302300
# dj-stripe
@@ -315,6 +313,7 @@ typing-extensions==4.13.2
315313
# pydantic
316314
# pydantic-core
317315
# pygithub
316+
# stripe
318317
# typing-inspection
319318
typing-inspection==0.4.0
320319
# via pydantic

requirements/testing.txt

+4-5
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ distlib==0.3.9
108108
# virtualenv
109109
dj-pagination==2.5.0
110110
# via -r requirements/pip.txt
111-
dj-stripe==2.6.3
111+
dj-stripe==2.9.0
112112
# via -r requirements/pip.txt
113113
django==4.2.20
114114
# via
@@ -253,9 +253,7 @@ jmespath==1.0.1
253253
# boto3
254254
# botocore
255255
jsonfield==3.1.0
256-
# via
257-
# -r requirements/pip.txt
258-
# dj-stripe
256+
# via -r requirements/pip.txt
259257
kombu==5.5.3
260258
# via
261259
# -r requirements/pip.txt
@@ -445,7 +443,7 @@ sqlparse==0.5.3
445443
# -r requirements/pip.txt
446444
# django
447445
# django-debug-toolbar
448-
stripe==4.2.0
446+
stripe==11.6.0
449447
# via
450448
# -r requirements/pip.txt
451449
# dj-stripe
@@ -468,6 +466,7 @@ typing-extensions==4.13.2
468466
# pydantic-core
469467
# pygithub
470468
# sphinx
469+
# stripe
471470
# typing-inspection
472471
typing-inspection==0.4.0
473472
# via

0 commit comments

Comments
 (0)