Skip to content

Commit

Permalink
resolve all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RulaKhaled committed Jan 21, 2025
1 parent 208eb10 commit a9a5eeb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions shared/django_apps/codecov_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def pretty_plan(self) -> dict | None:
We inject quantity to make plan management easier on api, see PlanSerializer
"""
plan_details = Plan.objects.get(name=self.plan)
plan_details.update({"quantity": self.plan_seat_count})
plan_details.quantity = self.plan_seat_count
plan_details.save()

return plan_details

def can_activate_user(self, user: User | None = None) -> bool:
Expand Down Expand Up @@ -599,7 +601,8 @@ def pretty_plan(self):
# some iffy data modeling

if plan_details:
plan_details.update({"quantity": self.plan_user_count})
plan_details.quantity = self.plan_user_count
plan_details.save()
return plan_details

def can_activate_user(self, owner_user: Self) -> bool:
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/django_apps/codecov_auth/test_codecov_auth_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
PlanName,
)
from shared.utils.test_utils import mock_config_helper
from tests.unit.plan.test_plan import mock_all_plans_and_tiers


class TestOwnerModel(TransactionTestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov_name", email="[email protected]")
mock_all_plans_and_tiers()

def test_repo_total_credits_returns_correct_repos_for_legacy_plan(self):
self.owner.plan = "5m"
Expand Down Expand Up @@ -384,7 +386,7 @@ def test_fields_that_account_overrides(self):
self.assertTrue(self.owner.can_activate_user(to_activate))
org_pretty_plan = asdict(BASIC_PLAN)
org_pretty_plan.update({"quantity": 1})
self.assertEqual(self.owner.pretty_plan, org_pretty_plan)
self.assertEqual(self.owner.pretty_plan.quantity, org_pretty_plan["quantity"])

self.owner.account = AccountFactory(
plan_seat_count=0, plan=PlanName.ENTERPRISE_CLOUD_YEARLY.value
Expand All @@ -396,7 +398,7 @@ def test_fields_that_account_overrides(self):
ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS[self.owner.account.plan]
)
account_pretty_plan.update({"quantity": 0})
self.assertEqual(self.owner.pretty_plan, account_pretty_plan)
self.assertEqual(self.owner.pretty_plan.quantity, account_pretty_plan["quantity"])

def test_add_admin_adds_ownerid_to_admin_array(self):
self.owner.admins = []
Expand Down Expand Up @@ -717,6 +719,7 @@ def test_account_with_billing_details(self):
self.assertTrue(stripe.is_active)

def test_account_with_users(self):
mock_all_plans_and_tiers()
user_1 = UserFactory()
OwnerFactory(user=user_1)
user_2 = UserFactory()
Expand Down Expand Up @@ -758,9 +761,10 @@ def test_account_with_users(self):
self.assertEqual(account.available_seat_count, 0)
pretty_plan = asdict(BASIC_PLAN)
pretty_plan.update({"quantity": 1})
self.assertEqual(account.pretty_plan, pretty_plan)
self.assertEqual(account.pretty_plan.quantity, pretty_plan["quantity"])

def test_create_account_for_enterprise_experience(self):
mock_all_plans_and_tiers()
# 2 separate OwnerOrgs that wish to Enterprise
stripe_customer_id = "abc123"
stripe_subscription_id = "defg456"
Expand Down Expand Up @@ -928,7 +932,7 @@ def test_create_account_for_enterprise_experience(self):
self.assertEqual(enterprise_account.available_seat_count, 57)
pretty_plan = asdict(BASIC_PLAN)
pretty_plan.update({"quantity": 50})
self.assertEqual(enterprise_account.pretty_plan, pretty_plan)
self.assertEqual(enterprise_account.pretty_plan.quantity, pretty_plan["quantity"])

def test_activate_user_onto_account(self):
user = UserFactory()
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/upload/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
insert_coverage_measurement,
query_monthly_coverage_measurements,
)
from tests.unit.plan.test_plan import mock_all_plans_and_tiers


class CoverageMeasurement(TestCase):
def setUp(self):
mock_all_plans_and_tiers()

def add_upload_measurements_records(
self,
owner: Owner,
Expand Down

0 comments on commit a9a5eeb

Please sign in to comment.