33
44import requests
55import stripe
6- from billing .tests .mocks import mock_all_plans_and_tiers
7- from codecov_auth .models import Plan , Service
86from django .conf import settings
97from django .test import TestCase
108from freezegun import freeze_time
11- from services .billing import (AbstractPaymentService , BillingService ,
12- StripeService )
13- from shared .django_apps .core .tests .factories import OwnerFactory
14- from shared .plan .constants import DEFAULT_FREE_PLAN , PlanName
159from stripe import InvalidRequestError
1610from stripe .api_resources import PaymentIntent , SetupIntent
1711
12+ from billing .tests .mocks import mock_all_plans_and_tiers
13+ from codecov_auth .models import Plan , Service
14+ from services .billing import AbstractPaymentService , BillingService , StripeService
15+ from shared .django_apps .core .tests .factories import OwnerFactory
16+ from shared .plan .constants import DEFAULT_FREE_PLAN , PlanName
17+
1818SCHEDULE_RELEASE_OFFSET = 10
1919
2020expected_invoices = [
@@ -1947,12 +1947,13 @@ def test_update_billing_address_with_error(
19471947 retrieve_customer_mock .return_value = MagicMock (
19481948 invoice_settings = MagicMock (default_payment_method = "pm_123" )
19491949 )
1950+ # Set the side effect only for this test, and reset after
1951+ original_side_effect = modify_payment_mock .side_effect
19501952 modify_payment_mock .side_effect = stripe .error .CardError (
1951- message = "Your card was declined." ,
1952- param = "number" ,
1953- code = "card_declined"
1953+ message = "Your card was declined." , param = "number" , code = "card_declined"
19541954 )
1955-
1955+ self .addCleanup (lambda : setattr (modify_payment_mock , "side_effect" , original_side_effect ))
1956+
19561957 with self .assertRaises (stripe .error .CardError ):
19571958 self .stripe .update_billing_address (
19581959 owner ,
@@ -1962,12 +1963,8 @@ def test_update_billing_address_with_error(
19621963
19631964 retrieve_customer_mock .assert_called_once ()
19641965 modify_payment_mock .assert_called_once ()
1965- modify_customer_mock .assert_called_once_with (
1966- customer_id ,
1967- address = billing_address ,
1968- name = "John Doe" ,
1969- )
1970-
1966+ modify_customer_mock .assert_not_called ()
1967+
19711968 @patch ("services.billing.stripe.Invoice.retrieve" )
19721969 def test_get_invoice_not_found (self , retrieve_invoice_mock ):
19731970 invoice_id = "abc"
0 commit comments