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

Commit 1af0acf

Browse files
Revert "Temporarily disable trials starting for paid orgs" (#974)
1 parent 6fa33eb commit 1af0acf

File tree

3 files changed

+40
-43
lines changed

3 files changed

+40
-43
lines changed

codecov_auth/tests/test_admin.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
)
2626
from shared.django_apps.core.tests.factories import PullFactory, RepositoryFactory
2727

28-
# from codecov.commands.exceptions import ValidationError
28+
from codecov.commands.exceptions import ValidationError
2929
from codecov_auth.admin import (
3030
AccountAdmin,
3131
InvoiceBillingAdmin,
@@ -337,26 +337,25 @@ def test_extend_trial_action(self, mock_start_trial_service):
337337
assert mock_start_trial_service.called
338338
assert mock_start_trial_service.call_args.kwargs == {"is_extension": True}
339339

340-
# Temporarily comment for the time being
341-
# @patch("plan.service.PlanService.start_trial_manually")
342-
# def test_start_trial_paid_plan(self, mock_start_trial_service):
343-
# mock_start_trial_service.side_effect = ValidationError(
344-
# "Cannot trial from a paid plan"
345-
# )
346-
347-
# org_to_be_trialed = OwnerFactory()
348-
349-
# res = self.client.post(
350-
# reverse("admin:codecov_auth_owner_changelist"),
351-
# {
352-
# "action": "extend_trial",
353-
# ACTION_CHECKBOX_NAME: [org_to_be_trialed.pk],
354-
# "end_date": "2024-01-01 01:02:03",
355-
# "extend_trial": True,
356-
# },
357-
# )
358-
# assert res.status_code == 302
359-
# assert mock_start_trial_service.called
340+
@patch("plan.service.PlanService.start_trial_manually")
341+
def test_start_trial_paid_plan(self, mock_start_trial_service):
342+
mock_start_trial_service.side_effect = ValidationError(
343+
"Cannot trial from a paid plan"
344+
)
345+
346+
org_to_be_trialed = OwnerFactory()
347+
348+
res = self.client.post(
349+
reverse("admin:codecov_auth_owner_changelist"),
350+
{
351+
"action": "extend_trial",
352+
ACTION_CHECKBOX_NAME: [org_to_be_trialed.pk],
353+
"end_date": "2024-01-01 01:02:03",
354+
"extend_trial": True,
355+
},
356+
)
357+
assert res.status_code == 302
358+
assert mock_start_trial_service.called
360359

361360
def test_account_widget(self):
362361
owner = OwnerFactory(user=UserFactory(), plan="users-enterprisey")

plan/service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,15 @@ def start_trial_manually(self, current_owner: Owner, end_date: datetime) -> None
219219
Returns:
220220
No value
221221
"""
222+
# Start a new trial plan for free users currently not on trial
223+
if self.plan_name in FREE_PLAN_REPRESENTATIONS:
224+
self._start_trial_helper(current_owner, end_date, is_extension=False)
222225
# Extend an existing trial plan for users currently on trial
223-
if self.plan_name in TRIAL_PLAN_REPRESENTATION:
226+
elif self.plan_name in TRIAL_PLAN_REPRESENTATION:
224227
self._start_trial_helper(current_owner, end_date, is_extension=True)
225-
# Start a new trial plan for any users, used to be free but temporarily doing it for anyone
226-
# as long as the person extending the trial is responsible to manually returning the users
227-
# the way they were before
228-
else:
229-
self._start_trial_helper(current_owner, end_date, is_extension=False)
230228
# Paying users cannot start a trial
231-
# raise ValidationError("Cannot trial from a paid plan")
229+
else:
230+
raise ValidationError("Cannot trial from a paid plan")
232231

233232
def cancel_trial(self) -> None:
234233
if not self.is_org_trialing:

plan/tests/test_plan.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,20 @@ def test_plan_service_start_trial_manually(self):
226226
assert current_org.plan_auto_activate == True
227227
assert current_org.trial_fired_by == current_owner.ownerid
228228

229-
# Temporarily comment this
230-
# def test_plan_service_start_trial_manually_already_on_paid_plan(self):
231-
# current_org = OwnerFactory(
232-
# plan=PlanName.CODECOV_PRO_MONTHLY.value,
233-
# trial_start_date=None,
234-
# trial_end_date=None,
235-
# trial_status=TrialStatus.NOT_STARTED.value,
236-
# )
237-
# plan_service = PlanService(current_org=current_org)
238-
# current_owner = OwnerFactory()
239-
240-
# with self.assertRaises(ValidationError):
241-
# plan_service.start_trial_manually(
242-
# current_owner=current_owner, end_date="2024-01-01 00:00:00"
243-
# )
229+
def test_plan_service_start_trial_manually_already_on_paid_plan(self):
230+
current_org = OwnerFactory(
231+
plan=PlanName.CODECOV_PRO_MONTHLY.value,
232+
trial_start_date=None,
233+
trial_end_date=None,
234+
trial_status=TrialStatus.NOT_STARTED.value,
235+
)
236+
plan_service = PlanService(current_org=current_org)
237+
current_owner = OwnerFactory()
238+
239+
with self.assertRaises(ValidationError):
240+
plan_service.start_trial_manually(
241+
current_owner=current_owner, end_date="2024-01-01 00:00:00"
242+
)
244243

245244
def test_plan_service_returns_plan_data_for_non_trial_basic_plan(self):
246245
trial_start_date = None

0 commit comments

Comments
 (0)