1
1
from datetime import datetime , timedelta
2
2
from unittest .mock import patch
3
3
4
- from django .test import TestCase
4
+ from django .test import TestCase , override_settings
5
5
from freezegun import freeze_time
6
6
7
7
from shared .django_apps .codecov .commands .exceptions import ValidationError
8
+ from shared .django_apps .codecov_auth .models import Service
8
9
from shared .django_apps .codecov_auth .tests .factories import OwnerFactory
9
10
from shared .plan .constants import (
10
11
BASIC_PLAN ,
@@ -317,6 +318,34 @@ def test_plan_service_returns_if_owner_has_trial_dates(self):
317
318
318
319
assert plan_service .has_trial_dates == True
319
320
321
+ def test_plan_service_gitlab_with_root_org (self ):
322
+ root_owner_org = OwnerFactory (
323
+ service = Service .GITLAB .value ,
324
+ plan = PlanName .FREE_PLAN_NAME .value ,
325
+ plan_user_count = 1 ,
326
+ service_id = "1234" ,
327
+ )
328
+ middle_org = OwnerFactory (
329
+ service = Service .GITLAB .value ,
330
+ service_id = "5678" ,
331
+ parent_service_id = root_owner_org .service_id ,
332
+ )
333
+ child_owner_org = OwnerFactory (
334
+ service = Service .GITLAB .value ,
335
+ plan = PlanName .CODECOV_PRO_MONTHLY .value ,
336
+ plan_user_count = 20 ,
337
+ parent_service_id = middle_org .service_id ,
338
+ )
339
+ # root_plan and child_plan should be the same
340
+ root_plan = PlanService (current_org = root_owner_org )
341
+ child_plan = PlanService (current_org = child_owner_org )
342
+
343
+ assert root_plan .is_pro_plan == child_plan .is_pro_plan == False
344
+ assert root_plan .plan_user_count == child_plan .plan_user_count == 1
345
+ assert (
346
+ root_plan .plan_name == child_plan .plan_name == PlanName .FREE_PLAN_NAME .value
347
+ )
348
+
320
349
321
350
class AvailablePlansBeforeTrial (TestCase ):
322
351
"""
@@ -815,6 +844,7 @@ def test_sentry_user(self, is_sentry_user):
815
844
assert self .plan_service .available_plans (owner = self .owner ) == expected_result
816
845
817
846
847
+ @override_settings (IS_ENTERPRISE = False )
818
848
class PlanServiceIs___PlanTests (TestCase ):
819
849
def test_is_trial_plan (self ):
820
850
self .current_org = OwnerFactory (
@@ -834,6 +864,7 @@ def test_is_trial_plan(self):
834
864
assert self .plan_service .is_free_plan == False
835
865
assert self .plan_service .is_pro_plan == False
836
866
assert self .plan_service .is_enterprise_plan == False
867
+ assert self .plan_service .is_pr_billing_plan == True
837
868
838
869
def test_is_team_plan (self ):
839
870
self .current_org = OwnerFactory (
@@ -849,6 +880,7 @@ def test_is_team_plan(self):
849
880
assert self .plan_service .is_free_plan == False
850
881
assert self .plan_service .is_pro_plan == False
851
882
assert self .plan_service .is_enterprise_plan == False
883
+ assert self .plan_service .is_pr_billing_plan == True
852
884
853
885
def test_is_sentry_plan (self ):
854
886
self .current_org = OwnerFactory (
@@ -864,6 +896,7 @@ def test_is_sentry_plan(self):
864
896
assert self .plan_service .is_free_plan == False
865
897
assert self .plan_service .is_pro_plan == True
866
898
assert self .plan_service .is_enterprise_plan == False
899
+ assert self .plan_service .is_pr_billing_plan == True
867
900
868
901
def test_is_free_plan (self ):
869
902
self .current_org = OwnerFactory (
@@ -878,6 +911,7 @@ def test_is_free_plan(self):
878
911
assert self .plan_service .is_free_plan == True
879
912
assert self .plan_service .is_pro_plan == False
880
913
assert self .plan_service .is_enterprise_plan == False
914
+ assert self .plan_service .is_pr_billing_plan == True
881
915
882
916
def test_is_pro_plan (self ):
883
917
self .current_org = OwnerFactory (
@@ -892,6 +926,7 @@ def test_is_pro_plan(self):
892
926
assert self .plan_service .is_free_plan == False
893
927
assert self .plan_service .is_pro_plan == True
894
928
assert self .plan_service .is_enterprise_plan == False
929
+ assert self .plan_service .is_pr_billing_plan == True
895
930
896
931
def test_is_enterprise_plan (self ):
897
932
self .current_org = OwnerFactory (
@@ -906,3 +941,4 @@ def test_is_enterprise_plan(self):
906
941
assert self .plan_service .is_free_plan == False
907
942
assert self .plan_service .is_pro_plan == False
908
943
assert self .plan_service .is_enterprise_plan == True
944
+ assert self .plan_service .is_pr_billing_plan == True
0 commit comments