Skip to content

Commit

Permalink
43 tests failing locally
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry committed Jan 18, 2025
1 parent ba68a8b commit 3b1deb6
Showing 1 changed file with 78 additions and 36 deletions.
114 changes: 78 additions & 36 deletions tests/unit/plan/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

from shared.django_apps.codecov.commands.exceptions import ValidationError
from shared.django_apps.codecov_auth.models import Service
from shared.django_apps.codecov_auth.tests.factories import OwnerFactory
from shared.django_apps.codecov_auth.tests.factories import (
OwnerFactory,
PlanFactory,
TierFactory,
)
from shared.plan.constants import (
BASIC_PLAN,
FREE_PLAN,
Expand All @@ -17,6 +21,7 @@
TRIAL_PLAN_REPRESENTATION,
TRIAL_PLAN_SEATS,
PlanName,
TierName,
TrialDaysAmount,
TrialStatus,
)
Expand Down Expand Up @@ -61,8 +66,9 @@ def test_plan_service_trial_status_ongoing(self):
def test_plan_service_expire_trial_when_upgrading_successful_if_trial_is_not_started(
self,
):
plan = PlanFactory()
current_org_with_ongoing_trial = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=None,
trial_end_date=None,
trial_status=TrialStatus.NOT_STARTED.value,
Expand All @@ -79,8 +85,9 @@ def test_plan_service_expire_trial_when_upgrading_successful_if_trial_is_ongoing
):
trial_start_date = datetime.utcnow()
trial_end_date_ongoing = trial_start_date + timedelta(days=5)
plan = PlanFactory()
current_org_with_ongoing_trial = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date_ongoing,
trial_status=TrialStatus.ONGOING.value,
Expand All @@ -98,8 +105,9 @@ def test_plan_service_expire_trial_users_pretrial_users_count_if_existing(
trial_start_date = datetime.utcnow()
trial_end_date_ongoing = trial_start_date + timedelta(days=5)
pretrial_users_count = 5
plan = PlanFactory()
current_org_with_ongoing_trial = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date_ongoing,
trial_status=TrialStatus.ONGOING.value,
Expand All @@ -117,8 +125,9 @@ def test_plan_service_start_trial_errors_if_status_is_ongoing(self):
trial_end_date = trial_start_date + timedelta(
days=TrialDaysAmount.CODECOV_SENTRY.value
)
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
trial_status=TrialStatus.ONGOING.value,
Expand All @@ -132,8 +141,9 @@ def test_plan_service_start_trial_errors_if_status_is_ongoing(self):
def test_plan_service_start_trial_errors_if_status_is_expired(self):
trial_start_date = datetime.utcnow()
trial_end_date = trial_start_date + timedelta(days=-1)
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
trial_status=TrialStatus.EXPIRED.value,
Expand All @@ -145,8 +155,9 @@ def test_plan_service_start_trial_errors_if_status_is_expired(self):
plan_service.start_trial(current_owner=current_owner)

def test_plan_service_start_trial_errors_if_status_is_cannot_trial(self):
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=None,
trial_end_date=None,
trial_status=TrialStatus.CANNOT_TRIAL.value,
Expand All @@ -158,8 +169,9 @@ def test_plan_service_start_trial_errors_if_status_is_cannot_trial(self):
plan_service.start_trial(current_owner=current_owner)

def test_plan_service_start_trial_errors_owners_plan_is_not_a_free_plan(self):
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
current_org = OwnerFactory(
plan=PlanName.CODECOV_PRO_MONTHLY.value,
plan=plan.name,
trial_start_date=None,
trial_end_date=None,
trial_status=TrialStatus.CANNOT_TRIAL.value,
Expand All @@ -174,8 +186,9 @@ def test_plan_service_start_trial_succeeds_if_trial_has_not_started(self):
trial_start_date = None
trial_end_date = None
plan_user_count = 5
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
trial_status=TrialStatus.NOT_STARTED.value,
Expand All @@ -200,8 +213,9 @@ def test_plan_service_start_trial_manually(self):
trial_start_date = None
trial_end_date = None
plan_user_count = 5
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
trial_status=TrialStatus.NOT_STARTED.value,
Expand All @@ -223,8 +237,9 @@ def test_plan_service_start_trial_manually(self):
assert current_org.trial_fired_by == current_owner.ownerid

def test_plan_service_start_trial_manually_already_on_paid_plan(self):
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
current_org = OwnerFactory(
plan=PlanName.CODECOV_PRO_MONTHLY.value,
plan=plan.name,
trial_start_date=None,
trial_end_date=None,
trial_status=TrialStatus.NOT_STARTED.value,
Expand All @@ -240,8 +255,9 @@ def test_plan_service_start_trial_manually_already_on_paid_plan(self):
def test_plan_service_returns_plan_data_for_non_trial_basic_plan(self):
trial_start_date = None
trial_end_date = None
plan = PlanFactory()
current_org = OwnerFactory(
plan=PlanName.BASIC_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
)
Expand Down Expand Up @@ -269,8 +285,9 @@ def test_plan_service_returns_plan_data_for_trialing_user_trial_plan(self):
trial_end_date = datetime.utcnow() + timedelta(
days=TrialDaysAmount.CODECOV_SENTRY.value
)
plan = PlanFactory(name=PlanName.TRIAL_PLAN_NAME.value)
current_org = OwnerFactory(
plan=PlanName.TRIAL_PLAN_NAME.value,
plan=plan.name,
trial_start_date=trial_start_date,
trial_end_date=trial_end_date,
trial_status=TrialStatus.ONGOING.value,
Expand All @@ -289,8 +306,9 @@ def test_plan_service_returns_plan_data_for_trialing_user_trial_plan(self):
assert plan_service.trial_total_days == trial_plan.trial_days

def test_plan_service_sets_default_plan_data_values_correctly(self):
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
current_org = OwnerFactory(
plan=PlanName.CODECOV_PRO_MONTHLY.value,
plan=plan.name,
stripe_subscription_id="test-sub-123",
plan_user_count=20,
plan_activated_users=[44],
Expand All @@ -307,8 +325,9 @@ def test_plan_service_sets_default_plan_data_values_correctly(self):
assert current_org.stripe_subscription_id is None

def test_plan_service_returns_if_owner_has_trial_dates(self):
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
current_org = OwnerFactory(
plan=PlanName.CODECOV_PRO_MONTHLY.value,
plan=plan.name,
trial_start_date=datetime.utcnow(),
trial_end_date=datetime.utcnow() + timedelta(days=14),
)
Expand All @@ -319,9 +338,11 @@ def test_plan_service_returns_if_owner_has_trial_dates(self):
assert plan_service.has_trial_dates == True

def test_plan_service_gitlab_with_root_org(self):
tier = TierFactory(tier_name=TierName.BASIC.value)
plan = PlanFactory(name=PlanName.FREE_PLAN_NAME.value, tier=tier)
root_owner_org = OwnerFactory(
service=Service.GITLAB.value,
plan=PlanName.FREE_PLAN_NAME.value,
plan=plan.name,
plan_user_count=1,
service_id="1234",
)
Expand All @@ -330,9 +351,11 @@ def test_plan_service_gitlab_with_root_org(self):
service_id="5678",
parent_service_id=root_owner_org.service_id,
)
tier2 = TierFactory(tier_name=TierName.PRO.value)
plan2 = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value, tier=tier2)
child_owner_org = OwnerFactory(
service=Service.GITLAB.value,
plan=PlanName.CODECOV_PRO_MONTHLY.value,
plan=plan2.name,
plan_user_count=20,
parent_service_id=middle_org.service_id,
)
Expand Down Expand Up @@ -369,7 +392,8 @@ def setUp(self):
def test_available_plans_for_basic_plan_non_trial(
self,
):
self.current_org.plan = PlanName.BASIC_PLAN_NAME.value
plan = PlanFactory(name=PlanName.BASIC_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -385,7 +409,8 @@ def test_available_plans_for_basic_plan_non_trial(
def test_available_plans_for_free_plan_non_trial(
self,
):
self.current_org.plan = PlanName.FREE_PLAN_NAME.value
plan = PlanFactory(name=PlanName.FREE_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -402,7 +427,8 @@ def test_available_plans_for_free_plan_non_trial(
def test_available_plans_for_team_plan_non_trial(
self,
):
self.current_org.plan = PlanName.TEAM_MONTHLY.value
plan = PlanFactory(name=PlanName.TEAM_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -416,7 +442,8 @@ def test_available_plans_for_team_plan_non_trial(
assert plan_service.available_plans(owner=self.owner) == expected_result

def test_available_plans_for_pro_plan_non_trial(self):
self.current_org.plan = PlanName.CODECOV_PRO_MONTHLY.value
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -434,7 +461,8 @@ def test_available_plans_for_sentry_customer_basic_plan_non_trial(
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.BASIC_PLAN_NAME.value
plan = PlanFactory(name=PlanName.BASIC_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -453,7 +481,8 @@ def test_available_plans_for_sentry_customer_team_plan_non_trial(
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.TEAM_MONTHLY.value
plan = PlanFactory(name=PlanName.TEAM_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -470,7 +499,8 @@ def test_available_plans_for_sentry_customer_team_plan_non_trial(
@patch("shared.plan.service.is_sentry_user")
def test_available_plans_for_sentry_plan_non_trial(self, is_sentry_user):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.SENTRY_MONTHLY.value
plan = PlanFactory(name=PlanName.SENTRY_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand Down Expand Up @@ -508,7 +538,8 @@ def setUp(self):
def test_available_plans_for_basic_plan_expired_trial_less_than_10_users(
self,
):
self.current_org.plan = PlanName.BASIC_PLAN_NAME.value
plan = PlanFactory(name=PlanName.BASIC_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -524,7 +555,8 @@ def test_available_plans_for_basic_plan_expired_trial_less_than_10_users(
def test_available_plans_for_team_plan_expired_trial_less_than_10_users(
self,
):
self.current_org.plan = PlanName.TEAM_MONTHLY.value
plan = PlanFactory(name=PlanName.TEAM_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -538,7 +570,8 @@ def test_available_plans_for_team_plan_expired_trial_less_than_10_users(
assert plan_service.available_plans(owner=self.owner) == expected_result

def test_available_plans_for_pro_plan_expired_trial_less_than_10_users(self):
self.current_org.plan = PlanName.CODECOV_PRO_MONTHLY.value
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -556,7 +589,8 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_less_than_
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.BASIC_PLAN_NAME.value
plan = PlanFactory(name=PlanName.BASIC_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -575,7 +609,8 @@ def test_available_plans_for_sentry_customer_team_plan_expired_trial_less_than_1
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.TEAM_MONTHLY.value
plan = PlanFactory(name=PlanName.TEAM_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -594,7 +629,8 @@ def test_available_plans_for_sentry_plan_expired_trial_less_than_10_users(
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.SENTRY_MONTHLY.value
plan = PlanFactory(name=PlanName.SENTRY_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand Down Expand Up @@ -628,7 +664,8 @@ def setUp(self):
self.owner = OwnerFactory()

def test_available_plans_for_pro_plan_expired_trial_more_than_10_users(self):
self.current_org.plan = PlanName.CODECOV_PRO_MONTHLY.value
plan = PlanFactory(name=PlanName.CODECOV_PRO_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -645,7 +682,8 @@ def test_available_plans_for_sentry_customer_basic_plan_expired_trial_more_than_
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.BASIC_PLAN_NAME.value
plan = PlanFactory(name=PlanName.BASIC_PLAN_NAME.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand All @@ -663,7 +701,8 @@ def test_available_plans_for_sentry_plan_expired_trial_more_than_10_users(
self, is_sentry_user
):
is_sentry_user.return_value = True
self.current_org.plan = PlanName.SENTRY_MONTHLY.value
plan = PlanFactory(name=PlanName.SENTRY_MONTHLY.value)
self.current_org.plan = plan.name
self.current_org.save()

plan_service = PlanService(current_org=self.current_org)
Expand Down Expand Up @@ -693,10 +732,11 @@ def setUp(self):
]

def test_currently_team_plan(self):
plan = PlanFactory(name=PlanName.TEAM_MONTHLY.value)
self.current_org = OwnerFactory(
plan_user_count=100,
plan_activated_users=[i for i in range(10)],
plan=PlanName.TEAM_MONTHLY.value,
plan=plan.name,
)
self.owner = OwnerFactory()
self.plan_service = PlanService(current_org=self.current_org)
Expand Down Expand Up @@ -769,8 +809,9 @@ class AvailablePlansOngoingTrial(TestCase):
"""

def setUp(self):
plan = PlanFactory(name=PlanName.TRIAL_PLAN_NAME.value)
self.current_org = OwnerFactory(
plan=PlanName.TRIAL_PLAN_NAME.value,
plan=plan.name,
trial_start_date=datetime.utcnow(),
trial_end_date=datetime.utcnow() + timedelta(days=14),
trial_status=TrialStatus.ONGOING.value,
Expand Down Expand Up @@ -847,8 +888,9 @@ def test_sentry_user(self, is_sentry_user):
@override_settings(IS_ENTERPRISE=False)
class PlanServiceIs___PlanTests(TestCase):
def test_is_trial_plan(self):
plan = PlanFactory(name=PlanName.TRIAL_PLAN_NAME.value)
self.current_org = OwnerFactory(
plan=PlanName.TRIAL_PLAN_NAME.value,
plan=plan.name,
trial_start_date=datetime.utcnow(),
trial_end_date=datetime.utcnow() + timedelta(days=14),
trial_status=TrialStatus.ONGOING.value,
Expand Down

0 comments on commit 3b1deb6

Please sign in to comment.