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

Commit 3616116

Browse files
authored
feat: Map helper functions to available plans (#457)
1 parent 2674ae9 commit 3616116

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

shared/plan/constants.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ class PlanData:
9090
monthly_uploads_limit: Optional[MonthlyUploadLimits]
9191
trial_days: Optional[TrialDaysAmount]
9292

93+
def convert_to_DTO(self) -> dict:
94+
return {
95+
"marketing_name": self.marketing_name,
96+
"value": self.value,
97+
"billing_rate": self.billing_rate,
98+
"base_unit_price": self.base_unit_price,
99+
"benefits": self.benefits,
100+
"tier_name": self.tier_name,
101+
"monthly_uploads_limit": self.monthly_uploads_limit,
102+
"trial_days": self.trial_days,
103+
"is_free_plan": self.tier_name == TierName.BASIC,
104+
"is_pro_plan": self.tier_name == TierName.PRO,
105+
"is_team_plan": self.tier_name == TierName.TEAM,
106+
"is_enterprise_plan": self.tier_name == TierName.ENTERPRISE,
107+
"is_sentry_plan": self.value in SENTRY_PAID_USER_PLAN_REPRESENTATIONS,
108+
}
109+
93110

94111
NON_PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS = {
95112
PlanName.CODECOV_PRO_MONTHLY_LEGACY.value: PlanData(

shared/plan/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def available_plans(self, owner: Owner) -> List[PlanData]:
173173
):
174174
available_plans += TEAM_PLAN_REPRESENTATIONS.values()
175175

176-
return available_plans
176+
return [plan.convert_to_DTO() for plan in available_plans]
177177

178178
def _start_trial_helper(
179179
self,

tests/unit/plan/test_plan.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def test_available_plans_for_basic_plan_non_trial(
349349
expected_result.append(BASIC_PLAN)
350350
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
351351
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
352+
expected_result = [result.convert_to_DTO() for result in expected_result]
352353

353354
assert plan_service.available_plans(owner=self.owner) == expected_result
354355

@@ -365,6 +366,7 @@ def test_available_plans_for_free_plan_non_trial(
365366
expected_result.append(FREE_PLAN)
366367
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
367368
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
369+
expected_result = [result.convert_to_DTO() for result in expected_result]
368370

369371
assert plan_service.available_plans(owner=self.owner) == expected_result
370372

@@ -380,6 +382,7 @@ def test_available_plans_for_team_plan_non_trial(
380382
expected_result.append(BASIC_PLAN)
381383
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
382384
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
385+
expected_result = [result.convert_to_DTO() for result in expected_result]
383386

384387
assert plan_service.available_plans(owner=self.owner) == expected_result
385388

@@ -393,6 +396,7 @@ def test_available_plans_for_pro_plan_non_trial(self):
393396
expected_result.append(BASIC_PLAN)
394397
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
395398
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
399+
expected_result = [result.convert_to_DTO() for result in expected_result]
396400

397401
assert plan_service.available_plans(owner=self.owner) == expected_result
398402

@@ -411,6 +415,7 @@ def test_available_plans_for_sentry_customer_basic_plan_non_trial(
411415
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
412416
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
413417
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
418+
expected_result = [result.convert_to_DTO() for result in expected_result]
414419

415420
assert plan_service.available_plans(owner=self.owner) == expected_result
416421

@@ -429,6 +434,7 @@ def test_available_plans_for_sentry_customer_team_plan_non_trial(
429434
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
430435
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
431436
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
437+
expected_result = [result.convert_to_DTO() for result in expected_result]
432438

433439
assert plan_service.available_plans(owner=self.owner) == expected_result
434440

@@ -445,6 +451,7 @@ def test_available_plans_for_sentry_plan_non_trial(self, is_sentry_user):
445451
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
446452
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
447453
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
454+
expected_result = [result.convert_to_DTO() for result in expected_result]
448455

449456
assert plan_service.available_plans(owner=self.owner) == expected_result
450457

@@ -481,6 +488,7 @@ def test_available_plans_for_basic_plan_expired_trial_less_than_10_users(
481488
expected_result.append(BASIC_PLAN)
482489
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
483490
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
491+
expected_result = [result.convert_to_DTO() for result in expected_result]
484492

485493
assert plan_service.available_plans(owner=self.owner) == expected_result
486494

@@ -496,6 +504,7 @@ def test_available_plans_for_team_plan_expired_trial_less_than_10_users(
496504
expected_result.append(BASIC_PLAN)
497505
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
498506
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
507+
expected_result = [result.convert_to_DTO() for result in expected_result]
499508

500509
assert plan_service.available_plans(owner=self.owner) == expected_result
501510

@@ -509,6 +518,7 @@ def test_available_plans_for_pro_plan_expired_trial_less_than_10_users(self):
509518
expected_result.append(BASIC_PLAN)
510519
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
511520
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
521+
expected_result = [result.convert_to_DTO() for result in expected_result]
512522

513523
assert plan_service.available_plans(owner=self.owner) == expected_result
514524

@@ -527,6 +537,7 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_less_than_
527537
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
528538
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
529539
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
540+
expected_result = [result.convert_to_DTO() for result in expected_result]
530541

531542
assert plan_service.available_plans(owner=self.owner) == expected_result
532543

@@ -545,6 +556,7 @@ def test_available_plans_for_sentry_customer_team_plan_expired_trial_less_than_1
545556
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
546557
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
547558
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
559+
expected_result = [result.convert_to_DTO() for result in expected_result]
548560

549561
assert plan_service.available_plans(owner=self.owner) == expected_result
550562

@@ -563,6 +575,7 @@ def test_available_plans_for_sentry_plan_expired_trial_less_than_10_users(
563575
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
564576
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
565577
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
578+
expected_result = [result.convert_to_DTO() for result in expected_result]
566579

567580
assert plan_service.available_plans(owner=self.owner) == expected_result
568581

@@ -594,6 +607,7 @@ def test_available_plans_for_pro_plan_expired_trial_more_than_10_users(self):
594607
expected_result = []
595608
expected_result.append(BASIC_PLAN)
596609
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
610+
expected_result = [result.convert_to_DTO() for result in expected_result]
597611

598612
assert plan_service.available_plans(owner=self.owner) == expected_result
599613

@@ -611,6 +625,7 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_more_than_
611625
expected_result.append(BASIC_PLAN)
612626
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
613627
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
628+
expected_result = [result.convert_to_DTO() for result in expected_result]
614629

615630
assert plan_service.available_plans(owner=self.owner) == expected_result
616631

@@ -628,6 +643,7 @@ def test_available_plans_for_sentry_plan_expired_trial_more_than_10_users(
628643
expected_result.append(BASIC_PLAN)
629644
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
630645
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
646+
expected_result = [result.convert_to_DTO() for result in expected_result]
631647

632648
assert plan_service.available_plans(owner=self.owner) == expected_result
633649

@@ -643,6 +659,9 @@ def setUp(self):
643659
self.expected_result.append(BASIC_PLAN)
644660
self.expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
645661
self.expected_result += TEAM_PLAN_REPRESENTATIONS.values()
662+
self.expected_result = [
663+
result.convert_to_DTO() for result in self.expected_result
664+
]
646665

647666
def test_currently_team_plan(self):
648667
self.current_org = OwnerFactory(
@@ -700,6 +719,10 @@ def test_trial_not_started(self):
700719
self.expected_result.append(BASIC_PLAN)
701720
self.expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
702721
self.expected_result += TEAM_PLAN_REPRESENTATIONS.values()
722+
self.expected_result = [
723+
result.convert_to_DTO() for result in self.expected_result
724+
]
725+
703726
assert (
704727
self.plan_service.available_plans(owner=self.owner) == self.expected_result
705728
)
@@ -734,6 +757,7 @@ def test_non_sentry_user(self):
734757
expected_result.append(BASIC_PLAN)
735758
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
736759
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
760+
expected_result = [result.convert_to_DTO() for result in expected_result]
737761

738762
# Can do Team plan when plan_activated_users is null
739763
assert self.plan_service.available_plans(owner=self.owner) == expected_result
@@ -751,6 +775,7 @@ def test_non_sentry_user(self):
751775
expected_result = []
752776
expected_result.append(BASIC_PLAN)
753777
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
778+
expected_result = [result.convert_to_DTO() for result in expected_result]
754779

755780
# Can not do Team plan when at 11 activated users
756781
assert self.plan_service.available_plans(owner=self.owner) == expected_result
@@ -765,6 +790,7 @@ def test_sentry_user(self, is_sentry_user):
765790
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
766791
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
767792
expected_result += TEAM_PLAN_REPRESENTATIONS.values()
793+
expected_result = [result.convert_to_DTO() for result in expected_result]
768794

769795
# Can do Team plan when plan_activated_users is null
770796
assert self.plan_service.available_plans(owner=self.owner) == expected_result
@@ -783,6 +809,7 @@ def test_sentry_user(self, is_sentry_user):
783809
expected_result.append(BASIC_PLAN)
784810
expected_result += PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS.values()
785811
expected_result += SENTRY_PAID_USER_PLAN_REPRESENTATIONS.values()
812+
expected_result = [result.convert_to_DTO() for result in expected_result]
786813

787814
# Can not do Team plan when at 11 activated users
788815
assert self.plan_service.available_plans(owner=self.owner) == expected_result

0 commit comments

Comments
 (0)