From 7819ab63ed714fc9412b6a8d3ffa8cf8cb751848 Mon Sep 17 00:00:00 2001 From: Adrian Date: Tue, 12 Nov 2024 10:45:49 -0800 Subject: [PATCH] Temporarily disable trials starting for paid orgs --- codecov_auth/tests/test_admin.py | 41 ++++++++++++++++---------------- plan/service.py | 13 +++++----- plan/tests/test_plan.py | 29 +++++++++++----------- 3 files changed, 43 insertions(+), 40 deletions(-) diff --git a/codecov_auth/tests/test_admin.py b/codecov_auth/tests/test_admin.py index 6b4316b787..6f906bf07b 100644 --- a/codecov_auth/tests/test_admin.py +++ b/codecov_auth/tests/test_admin.py @@ -25,7 +25,7 @@ ) from shared.django_apps.core.tests.factories import PullFactory, RepositoryFactory -from codecov.commands.exceptions import ValidationError +# from codecov.commands.exceptions import ValidationError from codecov_auth.admin import ( AccountAdmin, InvoiceBillingAdmin, @@ -337,25 +337,26 @@ def test_extend_trial_action(self, mock_start_trial_service): assert mock_start_trial_service.called assert mock_start_trial_service.call_args.kwargs == {"is_extension": True} - @patch("plan.service.PlanService.start_trial_manually") - def test_start_trial_paid_plan(self, mock_start_trial_service): - mock_start_trial_service.side_effect = ValidationError( - "Cannot trial from a paid plan" - ) - - org_to_be_trialed = OwnerFactory() - - res = self.client.post( - reverse("admin:codecov_auth_owner_changelist"), - { - "action": "extend_trial", - ACTION_CHECKBOX_NAME: [org_to_be_trialed.pk], - "end_date": "2024-01-01 01:02:03", - "extend_trial": True, - }, - ) - assert res.status_code == 302 - assert mock_start_trial_service.called + # Temporarily comment for the time being + # @patch("plan.service.PlanService.start_trial_manually") + # def test_start_trial_paid_plan(self, mock_start_trial_service): + # mock_start_trial_service.side_effect = ValidationError( + # "Cannot trial from a paid plan" + # ) + + # org_to_be_trialed = OwnerFactory() + + # res = self.client.post( + # reverse("admin:codecov_auth_owner_changelist"), + # { + # "action": "extend_trial", + # ACTION_CHECKBOX_NAME: [org_to_be_trialed.pk], + # "end_date": "2024-01-01 01:02:03", + # "extend_trial": True, + # }, + # ) + # assert res.status_code == 302 + # assert mock_start_trial_service.called def test_account_widget(self): owner = OwnerFactory(user=UserFactory(), plan="users-enterprisey") diff --git a/plan/service.py b/plan/service.py index 0da4f2add3..c1c09d8291 100644 --- a/plan/service.py +++ b/plan/service.py @@ -219,15 +219,16 @@ def start_trial_manually(self, current_owner: Owner, end_date: datetime) -> None Returns: No value """ - # Start a new trial plan for free users currently not on trial - if self.plan_name in FREE_PLAN_REPRESENTATIONS: - self._start_trial_helper(current_owner, end_date, is_extension=False) # Extend an existing trial plan for users currently on trial - elif self.plan_name in TRIAL_PLAN_REPRESENTATION: + if self.plan_name in TRIAL_PLAN_REPRESENTATION: self._start_trial_helper(current_owner, end_date, is_extension=True) - # Paying users cannot start a trial + # Start a new trial plan for any users, used to be free but temporarily doing it for anyone + # as long as the person extending the trial is responsible to manually returning the users + # the way they were before else: - raise ValidationError("Cannot trial from a paid plan") + self._start_trial_helper(current_owner, end_date, is_extension=False) + # Paying users cannot start a trial + # raise ValidationError("Cannot trial from a paid plan") def cancel_trial(self) -> None: if not self.is_org_trialing: diff --git a/plan/tests/test_plan.py b/plan/tests/test_plan.py index 70b6becf7a..b07d4dc6ae 100644 --- a/plan/tests/test_plan.py +++ b/plan/tests/test_plan.py @@ -226,20 +226,21 @@ def test_plan_service_start_trial_manually(self): assert current_org.plan_auto_activate == True assert current_org.trial_fired_by == current_owner.ownerid - def test_plan_service_start_trial_manually_already_on_paid_plan(self): - current_org = OwnerFactory( - plan=PlanName.CODECOV_PRO_MONTHLY.value, - trial_start_date=None, - trial_end_date=None, - trial_status=TrialStatus.NOT_STARTED.value, - ) - plan_service = PlanService(current_org=current_org) - current_owner = OwnerFactory() - - with self.assertRaises(ValidationError): - plan_service.start_trial_manually( - current_owner=current_owner, end_date="2024-01-01 00:00:00" - ) + # Temporarily comment this + # def test_plan_service_start_trial_manually_already_on_paid_plan(self): + # current_org = OwnerFactory( + # plan=PlanName.CODECOV_PRO_MONTHLY.value, + # trial_start_date=None, + # trial_end_date=None, + # trial_status=TrialStatus.NOT_STARTED.value, + # ) + # plan_service = PlanService(current_org=current_org) + # current_owner = OwnerFactory() + + # with self.assertRaises(ValidationError): + # plan_service.start_trial_manually( + # current_owner=current_owner, end_date="2024-01-01 00:00:00" + # ) def test_plan_service_returns_plan_data_for_non_trial_basic_plan(self): trial_start_date = None