Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit ce5a4cf

Browse files
fix tests
1 parent 4327e66 commit ce5a4cf

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

services/billing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ def update_plan(self, owner, desired_plan):
929929
if owner.stripe_subscription_id is not None:
930930
# if the existing subscription is incomplete, clean it up and create a new checkout session
931931
subscription = self.payment_service.get_subscription(owner)
932+
932933
if subscription and subscription.status == "incomplete":
933934
self._cleanup_incomplete_subscription(subscription, owner)
934935
return self.payment_service.create_checkout_session(
@@ -1023,4 +1024,3 @@ def _cleanup_incomplete_subscription(
10231024
error=str(e),
10241025
),
10251026
)
1026-
return None

services/tests/test_billing.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from unittest.mock import MagicMock, call, patch
33

44
import requests
5+
import stripe
56
from django.conf import settings
67
from django.test import TestCase
78
from freezegun import freeze_time
@@ -106,7 +107,7 @@
106107
"next_payment_attempt": None,
107108
"number": "EF0A41E-0001",
108109
"paid": True,
109-
"payment_intent": None,
110+
"payment_intent": {"id": "pi_3P4567890123456789012345", "status": "completed"},
110111
"period_end": 1489789420,
111112
"period_start": 1487370220,
112113
"post_payment_credit_notes_amount": 0,
@@ -1622,15 +1623,21 @@ def test_update_payment_method_when_no_subscription(self):
16221623
@patch("services.billing.stripe.PaymentMethod.attach")
16231624
@patch("services.billing.stripe.Customer.modify")
16241625
@patch("services.billing.stripe.Subscription.modify")
1626+
@patch("services.billing.StripeService._is_unverified_payment_method")
16251627
def test_update_payment_method(
1626-
self, modify_sub_mock, modify_customer_mock, attach_payment_mock
1628+
self,
1629+
is_unverified_mock,
1630+
modify_sub_mock,
1631+
modify_customer_mock,
1632+
attach_payment_mock,
16271633
):
16281634
payment_method_id = "pm_1234567"
16291635
subscription_id = "sub_abc"
16301636
customer_id = "cus_abc"
16311637
owner = OwnerFactory(
16321638
stripe_subscription_id=subscription_id, stripe_customer_id=customer_id
16331639
)
1640+
is_unverified_mock.return_value = False
16341641
self.stripe.update_payment_method(owner, payment_method_id)
16351642
attach_payment_mock.assert_called_once_with(
16361643
payment_method_id, customer=customer_id
@@ -2166,17 +2173,31 @@ def test_update_plan_to_users_basic_sets_plan_if_no_subscription_id(
21662173
@patch("services.tests.test_billing.MockPaymentService.create_checkout_session")
21672174
@patch("services.tests.test_billing.MockPaymentService.modify_subscription")
21682175
@patch("services.tests.test_billing.MockPaymentService.delete_subscription")
2176+
@patch("services.tests.test_billing.MockPaymentService.get_subscription")
21692177
def test_update_plan_modifies_subscription_if_user_plan_and_subscription_exists(
21702178
self,
2179+
get_subscription_mock,
21712180
delete_subscription_mock,
21722181
modify_subscription_mock,
21732182
create_checkout_session_mock,
21742183
set_default_plan_data,
21752184
):
21762185
owner = OwnerFactory(stripe_subscription_id=10)
21772186
desired_plan = {"value": PlanName.CODECOV_PRO_YEARLY.value, "quantity": 10}
2178-
self.billing_service.update_plan(owner, desired_plan)
21792187

2188+
get_subscription_mock.return_value = stripe.util.convert_to_stripe_object(
2189+
{
2190+
"schedule": None,
2191+
"current_period_start": 1489799420,
2192+
"current_period_end": 1492477820,
2193+
"quantity": 10,
2194+
"name": PlanName.CODECOV_PRO_YEARLY.value,
2195+
"id": 215,
2196+
"status": "active",
2197+
}
2198+
)
2199+
2200+
self.billing_service.update_plan(owner, desired_plan)
21802201
modify_subscription_mock.assert_called_once_with(owner, desired_plan)
21812202

21822203
set_default_plan_data.assert_not_called()

0 commit comments

Comments
 (0)