Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions codecov_auth/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 7 additions & 6 deletions plan/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 15 additions & 14 deletions plan/tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading