@@ -65,6 +65,7 @@ def __getitem__(self, key):
6565class MockPaymentIntent (object ):
6666 def __init__ (self , noCard = False ):
6767 self .payment_method = MockPaymentMethod (noCard )
68+ self .status = "succeeded"
6869
6970 def __getitem__ (self , key ):
7071 return getattr (self , key )
@@ -285,6 +286,7 @@ def test_invoice_payment_failed_sets_owner_delinquent_true(
285286 "total" : 24000 ,
286287 "hosted_invoice_url" : "https://stripe.com" ,
287288 "payment_intent" : "payment_intent_asdf" ,
289+ "default_payment_method" : {},
288290 }
289291 },
290292 }
@@ -316,6 +318,7 @@ def test_invoice_payment_failed_sets_multiple_owners_delinquent_true(
316318 "total" : 24000 ,
317319 "hosted_invoice_url" : "https://stripe.com" ,
318320 "payment_intent" : "payment_intent_asdf" ,
321+ "default_payment_method" : {},
319322 }
320323 },
321324 }
@@ -354,6 +357,7 @@ def test_invoice_payment_failed_sends_email_to_admins(
354357 "total" : 24000 ,
355358 "hosted_invoice_url" : "https://stripe.com" ,
356359 "payment_intent" : "payment_intent_asdf" ,
360+ "default_payment_method" : {},
357361 }
358362 },
359363 }
@@ -428,7 +432,10 @@ def test_invoice_payment_failed_sends_email_to_admins_no_card(
428432 "default_payment_method" : None ,
429433 "total" : 24000 ,
430434 "hosted_invoice_url" : "https://stripe.com" ,
431- "payment_intent" : "payment_intent_asdf" ,
435+ "payment_intent" : {
436+ "id" : "payment_intent_asdf" ,
437+ "status" : "succeeded" ,
438+ },
432439 }
433440 },
434441 }
@@ -488,6 +495,7 @@ def test_customer_subscription_deleted_sets_plan_to_free(self):
488495 "id" : self .owner .stripe_subscription_id ,
489496 "customer" : self .owner .stripe_customer_id ,
490497 "plan" : {"name" : self .owner .plan },
498+ "status" : "active" ,
491499 }
492500 },
493501 }
@@ -516,6 +524,7 @@ def test_customer_subscription_deleted_sets_plan_to_free_mutliple_owner(self):
516524 "id" : self .owner .stripe_subscription_id ,
517525 "customer" : self .owner .stripe_customer_id ,
518526 "plan" : {"name" : self .owner .plan },
527+ "status" : "active" ,
519528 }
520529 },
521530 }
@@ -550,6 +559,7 @@ def test_customer_subscription_deleted_deactivates_all_repos(self):
550559 "id" : self .owner .stripe_subscription_id ,
551560 "customer" : self .owner .stripe_customer_id ,
552561 "plan" : {"name" : PlanName .CODECOV_PRO_MONTHLY .value },
562+ "status" : "active" ,
553563 }
554564 },
555565 }
@@ -587,6 +597,7 @@ def test_customer_subscription_deleted_deactivates_all_repos_multiple_owner(self
587597 "id" : self .owner .stripe_subscription_id ,
588598 "customer" : self .owner .stripe_customer_id ,
589599 "plan" : {"name" : PlanName .CODECOV_PRO_MONTHLY .value },
600+ "status" : "active" ,
590601 }
591602 },
592603 }
@@ -619,6 +630,7 @@ def test_customer_subscription_deleted_no_customer(self, log_info_mock):
619630 "id" : "HUH" ,
620631 "customer" : "nah" ,
621632 "plan" : {"name" : self .owner .plan },
633+ "status" : "active" ,
622634 }
623635 },
624636 }
@@ -690,7 +702,11 @@ def test_customer_subscription_created_does_nothing_if_plan_not_paid_user_plan(
690702 assert self .owner .stripe_subscription_id is None
691703 assert self .owner .stripe_customer_id is None
692704
693- def test_customer_subscription_created_sets_plan_info (self ):
705+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
706+ def test_customer_subscription_created_sets_plan_info (
707+ self , has_unverified_initial_payment_method_mock
708+ ):
709+ has_unverified_initial_payment_method_mock .return_value = False
694710 self .owner .stripe_subscription_id = None
695711 self .owner .stripe_customer_id = None
696712 self .owner .save ()
@@ -724,12 +740,18 @@ def test_customer_subscription_created_sets_plan_info(self):
724740 assert self .owner .plan == plan_name
725741
726742 @freeze_time ("2023-06-19" )
743+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
727744 @patch ("shared.plan.service.PlanService.expire_trial_when_upgrading" )
728745 @patch ("services.billing.stripe.PaymentMethod.attach" )
729746 @patch ("services.billing.stripe.Customer.modify" )
730747 def test_customer_subscription_created_can_trigger_trial_expiration (
731- self , c_mock , pm_mock , expire_trial_when_upgrading_mock
748+ self ,
749+ c_mock ,
750+ pm_mock ,
751+ expire_trial_when_upgrading_mock ,
752+ has_unverified_initial_payment_method_mock ,
732753 ):
754+ has_unverified_initial_payment_method_mock .return_value = False
733755 stripe_subscription_id = "FOEKDCDEQ"
734756 stripe_customer_id = "sdo050493"
735757 quantity = 20
@@ -752,11 +774,16 @@ def test_customer_subscription_created_can_trigger_trial_expiration(
752774
753775 expire_trial_when_upgrading_mock .assert_called_once ()
754776
777+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
755778 @patch ("services.billing.stripe.PaymentMethod.attach" )
756779 @patch ("services.billing.stripe.Customer.modify" )
757780 def test_customer_subscription_updated_does_not_change_subscription_if_not_paid_user_plan (
758- self , c_mock , pm_mock
781+ self ,
782+ c_mock ,
783+ pm_mock ,
784+ has_unverified_initial_payment_method_mock ,
759785 ):
786+ has_unverified_initial_payment_method_mock .return_value = False
760787 self .owner .plan = PlanName .BASIC_PLAN_NAME .value
761788 self .owner .plan_user_count = 0
762789 self .owner .plan_auto_activate = False
@@ -792,12 +819,18 @@ def test_customer_subscription_updated_does_not_change_subscription_if_not_paid_
792819 invoice_settings = {"default_payment_method" : "pm_1LhiRsGlVGuVgOrkQguJXdeV" },
793820 )
794821
822+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
795823 @patch ("logging.Logger.info" )
796824 @patch ("services.billing.stripe.PaymentMethod.attach" )
797825 @patch ("services.billing.stripe.Customer.modify" )
798826 def test_customer_subscription_updated_does_not_change_subscription_if_there_is_a_schedule (
799- self , c_mock , pm_mock , log_info_mock
827+ self ,
828+ c_mock ,
829+ pm_mock ,
830+ log_info_mock ,
831+ has_unverified_initial_payment_method_mock ,
800832 ):
833+ has_unverified_initial_payment_method_mock .return_value = False
801834 self .owner .plan = "users-pr-inappy"
802835 self .owner .plan_user_count = 10
803836 self .owner .plan_auto_activate = False
@@ -838,11 +871,16 @@ def test_customer_subscription_updated_does_not_change_subscription_if_there_is_
838871 extra = {"stripe_webhook_event" : "customer.subscription.updated" },
839872 )
840873
874+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
841875 @patch ("services.billing.stripe.PaymentMethod.attach" )
842876 @patch ("services.billing.stripe.Customer.modify" )
843877 def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_incomplete_expired (
844- self , c_mock , pm_mock
878+ self ,
879+ c_mock ,
880+ pm_mock ,
881+ has_unverified_initial_payment_method_mock ,
845882 ):
883+ has_unverified_initial_payment_method_mock .return_value = False
846884 self .owner .plan = "users-pr-inappy"
847885 self .owner .plan_user_count = 10
848886 self .owner .plan_auto_activate = False
@@ -889,7 +927,11 @@ def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_in
889927 invoice_settings = {"default_payment_method" : "pm_1LhiRsGlVGuVgOrkQguJXdeV" },
890928 )
891929
892- def test_customer_subscription_updated_payment_failed (self ):
930+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
931+ def test_customer_subscription_updated_payment_failed (
932+ self , has_unverified_initial_payment_method_mock
933+ ):
934+ has_unverified_initial_payment_method_mock .return_value = False
893935 self .owner .delinquent = False
894936 self .owner .save ()
895937
@@ -923,11 +965,16 @@ def test_customer_subscription_updated_payment_failed(self):
923965 self .owner .refresh_from_db ()
924966 assert self .owner .delinquent == True
925967
968+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
926969 @patch ("services.billing.stripe.PaymentMethod.attach" )
927970 @patch ("services.billing.stripe.Customer.modify" )
928971 def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_incomplete_expired_multiple_owner (
929- self , c_mock , pm_mock
972+ self ,
973+ c_mock ,
974+ pm_mock ,
975+ has_unverified_initial_payment_method_mock ,
930976 ):
977+ has_unverified_initial_payment_method_mock .return_value = False
931978 self .add_second_owner ()
932979 self .owner .plan = "users-pr-inappy"
933980 self .owner .plan_user_count = 10
@@ -992,11 +1039,16 @@ def test_customer_subscription_updated_sets_free_and_deactivates_all_repos_if_in
9921039 invoice_settings = {"default_payment_method" : "pm_1LhiRsGlVGuVgOrkQguJXdeV" },
9931040 )
9941041
1042+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
9951043 @patch ("services.billing.stripe.PaymentMethod.attach" )
9961044 @patch ("services.billing.stripe.Customer.modify" )
9971045 def test_customer_subscription_updated_sets_fields_on_success (
998- self , c_mock , pm_mock
1046+ self ,
1047+ c_mock ,
1048+ pm_mock ,
1049+ has_unverified_initial_payment_method_mock ,
9991050 ):
1051+ has_unverified_initial_payment_method_mock .return_value = False
10001052 self .owner .plan = "users-free"
10011053 self .owner .plan_user_count = 5
10021054 self .owner .plan_auto_activate = False
@@ -1034,11 +1086,16 @@ def test_customer_subscription_updated_sets_fields_on_success(
10341086 invoice_settings = {"default_payment_method" : "pm_1LhiRsGlVGuVgOrkQguJXdeV" },
10351087 )
10361088
1089+ @patch ("billing.views.StripeWebhookHandler._has_unverified_initial_payment_method" )
10371090 @patch ("services.billing.stripe.PaymentMethod.attach" )
10381091 @patch ("services.billing.stripe.Customer.modify" )
10391092 def test_customer_subscription_updated_sets_fields_on_success_multiple_owner (
1040- self , c_mock , pm_mock
1093+ self ,
1094+ c_mock ,
1095+ pm_mock ,
1096+ has_unverified_initial_payment_method_mock ,
10411097 ):
1098+ has_unverified_initial_payment_method_mock .return_value = False
10421099 self .add_second_owner ()
10431100 self .owner .plan = "users-free"
10441101 self .owner .plan_user_count = 5
0 commit comments