File tree Expand file tree Collapse file tree 3 files changed +23
-1
lines changed
Expand file tree Collapse file tree 3 files changed +23
-1
lines changed Original file line number Diff line number Diff line change 1+ import requests_mock
2+ from django .test import TestCase
3+
4+ from readthedocs .payments .tests .utils import PaymentMixin
5+ from readthedocs .payments .utils import cancel_subscription
6+
7+
8+ class TestUtils (PaymentMixin , TestCase ):
9+
10+ @requests_mock .Mocker (kw = "mock_request" )
11+ def test_cancel_subscription (self , mock_request ):
12+ subscription_id = "sub_1234567890"
13+ delete_request = mock_request .delete (
14+ f"https://api.stripe.com/v1/subscriptions/{ subscription_id } " ,
15+ json = {
16+ "id" : subscription_id ,
17+ "object" : "subscription" ,
18+ "status" : "canceled" ,
19+ },
20+ )
21+ cancel_subscription (subscription_id )
22+ assert delete_request .called
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ def cancel_subscription(subscription_id):
5050 "Canceling stripe subscription." ,
5151 stripe_subscription = subscription_id ,
5252 )
53- return stripe_client .subscriptions .delete (subscription_id )
53+ return stripe_client .subscriptions .cancel (subscription_id )
5454 except stripe .error .StripeError :
5555 log .exception (
5656 "Subscription not cancelled. Subscription not found on Stripe. " ,
You can’t perform that action at this time.
0 commit comments