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

Commit 1c4ca00

Browse files
authored
feat: Add new properties for is____Plan on Plan Service (#453)
* tests and properties for is___plan * fix tests * little clean up
1 parent 016eef6 commit 1c4ca00

File tree

2 files changed

+124
-2
lines changed

2 files changed

+124
-2
lines changed

shared/plan/service.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from shared.django_apps.codecov_auth.models import Owner
88
from shared.plan.constants import (
99
BASIC_PLAN,
10+
ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS,
1011
FREE_PLAN,
1112
FREE_PLAN_REPRESENTATIONS,
1213
PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS,
@@ -16,6 +17,7 @@
1617
TRIAL_PLAN_REPRESENTATION,
1718
TRIAL_PLAN_SEATS,
1819
USER_PLAN_REPRESENTATIONS,
20+
PlanBillingRate,
1921
PlanData,
2022
PlanName,
2123
TrialDaysAmount,
@@ -124,7 +126,7 @@ def marketing_name(self) -> str:
124126
return self.plan_data.marketing_name
125127

126128
@property
127-
def billing_rate(self) -> Optional[str]:
129+
def billing_rate(self) -> Optional[PlanBillingRate]:
128130
"""Returns the billing rate for the plan."""
129131
return self.plan_data.billing_rate
130132

@@ -282,7 +284,7 @@ def trial_end_date(self) -> Optional[datetime]:
282284
return self.current_org.trial_end_date
283285

284286
@property
285-
def trial_total_days(self) -> Optional[int]:
287+
def trial_total_days(self) -> Optional[TrialDaysAmount]:
286288
"""Returns the total number of trial days."""
287289
return self.plan_data.trial_days
288290

@@ -311,3 +313,30 @@ def has_seats_left(self) -> bool:
311313
self.plan_activated_users is None
312314
or len(self.plan_activated_users) < self.plan_user_count
313315
)
316+
317+
@property
318+
def is_enterprise_plan(self) -> bool:
319+
return self.plan_name in ENTERPRISE_CLOUD_USER_PLAN_REPRESENTATIONS
320+
321+
@property
322+
def is_free_plan(self) -> bool:
323+
return self.plan_name in FREE_PLAN_REPRESENTATIONS
324+
325+
@property
326+
def is_pro_plan(self) -> bool:
327+
return (
328+
self.plan_name in PR_AUTHOR_PAID_USER_PLAN_REPRESENTATIONS
329+
or self.plan_name in SENTRY_PAID_USER_PLAN_REPRESENTATIONS
330+
)
331+
332+
@property
333+
def is_sentry_plan(self) -> bool:
334+
return self.plan_name in SENTRY_PAID_USER_PLAN_REPRESENTATIONS
335+
336+
@property
337+
def is_team_plan(self) -> bool:
338+
return self.plan_name in TEAM_PLAN_REPRESENTATIONS
339+
340+
@property
341+
def is_trial_plan(self) -> bool:
342+
return self.plan_name in TRIAL_PLAN_REPRESENTATION

tests/unit/plan/test_plan.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,96 @@ def test_sentry_user(self, is_sentry_user):
786786

787787
# Can not do Team plan when at 11 activated users
788788
assert self.plan_service.available_plans(owner=self.owner) == expected_result
789+
790+
791+
class PlanServiceIs___PlanTests(TestCase):
792+
def test_is_trial_plan(self):
793+
self.current_org = OwnerFactory(
794+
plan=PlanName.TRIAL_PLAN_NAME.value,
795+
trial_start_date=datetime.utcnow(),
796+
trial_end_date=datetime.utcnow() + timedelta(days=14),
797+
trial_status=TrialStatus.ONGOING.value,
798+
plan_user_count=1000,
799+
plan_activated_users=None,
800+
)
801+
self.owner = OwnerFactory()
802+
self.plan_service = PlanService(current_org=self.current_org)
803+
804+
assert self.plan_service.is_trial_plan == True
805+
assert self.plan_service.is_sentry_plan == False
806+
assert self.plan_service.is_team_plan == False
807+
assert self.plan_service.is_free_plan == False
808+
assert self.plan_service.is_pro_plan == False
809+
assert self.plan_service.is_enterprise_plan == False
810+
811+
def test_is_team_plan(self):
812+
self.current_org = OwnerFactory(
813+
plan=PlanName.TEAM_MONTHLY.value,
814+
trial_status=TrialStatus.EXPIRED.value,
815+
)
816+
self.owner = OwnerFactory()
817+
self.plan_service = PlanService(current_org=self.current_org)
818+
819+
assert self.plan_service.is_trial_plan == False
820+
assert self.plan_service.is_sentry_plan == False
821+
assert self.plan_service.is_team_plan == True
822+
assert self.plan_service.is_free_plan == False
823+
assert self.plan_service.is_pro_plan == False
824+
assert self.plan_service.is_enterprise_plan == False
825+
826+
def test_is_sentry_plan(self):
827+
self.current_org = OwnerFactory(
828+
plan=PlanName.SENTRY_MONTHLY.value,
829+
trial_status=TrialStatus.EXPIRED.value,
830+
)
831+
self.owner = OwnerFactory()
832+
self.plan_service = PlanService(current_org=self.current_org)
833+
834+
assert self.plan_service.is_trial_plan == False
835+
assert self.plan_service.is_sentry_plan == True
836+
assert self.plan_service.is_team_plan == False
837+
assert self.plan_service.is_free_plan == False
838+
assert self.plan_service.is_pro_plan == True
839+
assert self.plan_service.is_enterprise_plan == False
840+
841+
def test_is_free_plan(self):
842+
self.current_org = OwnerFactory(
843+
plan=PlanName.FREE_PLAN_NAME.value,
844+
)
845+
self.owner = OwnerFactory()
846+
self.plan_service = PlanService(current_org=self.current_org)
847+
848+
assert self.plan_service.is_trial_plan == False
849+
assert self.plan_service.is_sentry_plan == False
850+
assert self.plan_service.is_team_plan == False
851+
assert self.plan_service.is_free_plan == True
852+
assert self.plan_service.is_pro_plan == False
853+
assert self.plan_service.is_enterprise_plan == False
854+
855+
def test_is_pro_plan(self):
856+
self.current_org = OwnerFactory(
857+
plan=PlanName.CODECOV_PRO_MONTHLY.value,
858+
)
859+
self.owner = OwnerFactory()
860+
self.plan_service = PlanService(current_org=self.current_org)
861+
862+
assert self.plan_service.is_trial_plan == False
863+
assert self.plan_service.is_sentry_plan == False
864+
assert self.plan_service.is_team_plan == False
865+
assert self.plan_service.is_free_plan == False
866+
assert self.plan_service.is_pro_plan == True
867+
assert self.plan_service.is_enterprise_plan == False
868+
869+
def test_is_enterprise_plan(self):
870+
self.current_org = OwnerFactory(
871+
plan=PlanName.ENTERPRISE_CLOUD_YEARLY.value,
872+
)
873+
self.owner = OwnerFactory()
874+
self.plan_service = PlanService(current_org=self.current_org)
875+
876+
assert self.plan_service.is_trial_plan == False
877+
assert self.plan_service.is_sentry_plan == False
878+
assert self.plan_service.is_team_plan == False
879+
assert self.plan_service.is_free_plan == False
880+
assert self.plan_service.is_pro_plan == False
881+
assert self.plan_service.is_enterprise_plan == True

0 commit comments

Comments
 (0)