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

Commit 42488fb

Browse files
committed
fix all tests except account_viewset
1 parent 91ea64b commit 42488fb

File tree

16 files changed

+127
-102
lines changed

16 files changed

+127
-102
lines changed

billing/helpers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from django.conf import settings
22
from django.db.models import QuerySet
3-
from shared.plan.constants import TierName, PlanName, PlanPrice
4-
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
53
from shared.django_apps.codecov_auth.models import BillingRate
4+
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
5+
from shared.plan.constants import PlanName, PlanPrice, TierName
66

77
from codecov_auth.models import Owner, Plan
88

@@ -30,7 +30,6 @@ def get_all_admins_for_owners(owners: QuerySet[Owner]):
3030
return admins
3131

3232

33-
3433
def mock_all_plans_and_tiers():
3534
trial_tier = TierFactory(tier_name=TierName.TRIAL.value)
3635
PlanFactory(
@@ -179,4 +178,4 @@ def mock_all_plans_and_tiers():
179178
billing_rate=BillingRate.ANNUALLY.value,
180179
base_unit_price=PlanPrice.YEARLY.value,
181180
paid_plan=True,
182-
)
181+
)

billing/tests/test_helpers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
from django.test import TestCase, override_settings
2-
from shared.django_apps.core.tests.factories import OwnerFactory
3-
from shared.plan.constants import ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS, TierName, PlanName
42
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
3+
from shared.django_apps.core.tests.factories import OwnerFactory
4+
from shared.plan.constants import (
5+
ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS,
6+
PlanName,
7+
TierName,
8+
)
9+
510
from billing.helpers import on_enterprise_plan
611

712

billing/tests/test_views.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
1212
from shared.plan.constants import PlanName
1313

14+
from billing.helpers import mock_all_plans_and_tiers
15+
1416
from ..constants import StripeHTTPHeaders
1517

1618

@@ -70,16 +72,19 @@ def __getitem__(self, key):
7072

7173
class StripeWebhookHandlerTests(APITestCase):
7274
def setUp(self):
75+
mock_all_plans_and_tiers()
7376
self.owner = OwnerFactory(
74-
stripe_customer_id="cus_123", stripe_subscription_id="sub_123"
77+
stripe_customer_id="cus_123",
78+
stripe_subscription_id="sub_123",
7579
)
7680

7781
# Creates a second owner that shares billing details with self.owner.
7882
# This is used to test the case where owners are manually set to share a
7983
# subscription in Stripe.
8084
def add_second_owner(self):
8185
self.other_owner = OwnerFactory(
82-
stripe_customer_id="cus_123", stripe_subscription_id="sub_123"
86+
stripe_customer_id="cus_123",
87+
stripe_subscription_id="sub_123",
8388
)
8489

8590
def _send_event(self, payload, errorSig=None):
@@ -467,7 +472,7 @@ def test_invoice_payment_failed_sends_email_to_admins_no_card(
467472
mocked_send_email.assert_has_calls(expected_calls)
468473

469474
def test_customer_subscription_deleted_sets_plan_to_free(self):
470-
self.owner.plan = "users-inappy"
475+
self.owner.plan = PlanName.CODECOV_PRO_YEARLY.value
471476
self.owner.plan_user_count = 20
472477
self.owner.save()
473478

@@ -492,10 +497,10 @@ def test_customer_subscription_deleted_sets_plan_to_free(self):
492497

493498
def test_customer_subscription_deleted_sets_plan_to_free_mutliple_owner(self):
494499
self.add_second_owner()
495-
self.owner.plan = "users-inappy"
500+
self.owner.plan = PlanName.CODECOV_PRO_YEARLY.value
496501
self.owner.plan_user_count = 20
497502
self.owner.save()
498-
self.other_owner.plan = "users-inappy"
503+
self.other_owner.plan = PlanName.CODECOV_PRO_YEARLY.value
499504
self.other_owner.plan_user_count = 20
500505
self.other_owner.save()
501506

@@ -540,7 +545,7 @@ def test_customer_subscription_deleted_deactivates_all_repos(self):
540545
"object": {
541546
"id": self.owner.stripe_subscription_id,
542547
"customer": self.owner.stripe_customer_id,
543-
"plan": {"name": "users-inappm"},
548+
"plan": {"name": PlanName.CODECOV_PRO_MONTHLY.value},
544549
}
545550
},
546551
}
@@ -577,7 +582,7 @@ def test_customer_subscription_deleted_deactivates_all_repos_multiple_owner(self
577582
"object": {
578583
"id": self.owner.stripe_subscription_id,
579584
"customer": self.owner.stripe_customer_id,
580-
"plan": {"name": "users-inappm"},
585+
"plan": {"name": PlanName.CODECOV_PRO_MONTHLY.value},
581586
}
582587
},
583588
}
@@ -598,7 +603,7 @@ def test_customer_subscription_deleted_deactivates_all_repos_multiple_owner(self
598603

599604
@patch("logging.Logger.info")
600605
def test_customer_subscription_deleted_no_customer(self, log_info_mock):
601-
self.owner.plan = "users-inappy"
606+
self.owner.plan = PlanName.CODECOV_PRO_MONTHLY.value
602607
self.owner.plan_user_count = 20
603608
self.owner.save()
604609

@@ -688,7 +693,7 @@ def test_customer_subscription_created_sets_plan_info(self):
688693

689694
stripe_subscription_id = "FOEKDCDEQ"
690695
stripe_customer_id = "sdo050493"
691-
plan_name = "users-pr-inappy"
696+
plan_name = PlanName.CODECOV_PRO_YEARLY.value
692697
quantity = 20
693698

694699
self._send_event(

0 commit comments

Comments
 (0)