Skip to content

Commit

Permalink
chore: Migrate to using shared imports for the plan service (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
RulaKhaled authored Dec 3, 2024
1 parent 9babfac commit 1d7539e
Show file tree
Hide file tree
Showing 22 changed files with 33 additions and 1,221 deletions.
2 changes: 1 addition & 1 deletion api/internal/owner/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
TEAM_PLAN_MAX_USERS,
TEAM_PLAN_REPRESENTATIONS,
)
from shared.plan.service import PlanService

from codecov_auth.models import Owner
from plan.service import PlanService
from services.billing import BillingService
from services.sentry import send_user_webhook as send_sentry_webhook

Expand Down
2 changes: 1 addition & 1 deletion billing/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ def test_customer_subscription_created_sets_plan_info(self):
assert self.owner.plan == plan_name

@freeze_time("2023-06-19")
@patch("plan.service.PlanService.expire_trial_when_upgrading")
@patch("shared.plan.service.PlanService.expire_trial_when_upgrading")
@patch("services.billing.stripe.PaymentMethod.attach")
@patch("services.billing.stripe.Customer.modify")
def test_customer_subscription_created_can_trigger_trial_expiration(
Expand Down
2 changes: 1 addition & 1 deletion billing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from rest_framework.views import APIView
from shared.plan.service import PlanService

from codecov_auth.models import Owner
from plan.service import PlanService
from services.task.task import TaskService

from .constants import StripeHTTPHeaders, StripeWebhookEvents
Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
StripeBilling,
)
from shared.plan.constants import USER_PLAN_REPRESENTATIONS
from shared.plan.service import PlanService

from codecov.admin import AdminMixin
from codecov.commands.exceptions import ValidationError
from codecov_auth.helpers import History
from codecov_auth.models import OrganizationLevelToken, Owner, SentryUser, Session, User
from codecov_auth.services.org_level_token_service import OrgLevelTokenService
from plan.service import PlanService
from services.task import TaskService
from utils.services import get_short_service_name

Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/cancel_trial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from shared.plan.service import PlanService

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthorized, ValidationError
from codecov.db import sync_to_async
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import Owner
from plan.service import PlanService


class CancelTrialInteractor(BaseInteractor):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from shared.plan.service import PlanService
from shared.upload.utils import query_monthly_coverage_measurements

from codecov.commands.base import BaseInteractor
from codecov.db import sync_to_async
from codecov_auth.models import Owner
from plan.service import PlanService
from services.redis_configuration import get_redis_connection

redis = get_redis_connection()
Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/start_trial.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from shared.plan.service import PlanService

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthorized, ValidationError
from codecov.db import sync_to_async
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import Owner
from plan.service import PlanService


class StartTrialInteractor(BaseInteractor):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from asgiref.sync import async_to_sync
from django.test import TransactionTestCase
from freezegun import freeze_time
from shared.django_apps.codecov.commands.exceptions import ValidationError
from shared.django_apps.core.tests.factories import OwnerFactory
from shared.plan.constants import PlanName, TrialStatus

from codecov.commands.exceptions import Unauthorized, ValidationError
from codecov.commands.exceptions import Unauthorized
from codecov.commands.exceptions import ValidationError as CodecovValidationError
from codecov_auth.models import Owner

from ..cancel_trial import CancelTrialInteractor
Expand All @@ -26,7 +28,7 @@ def test_cancel_trial_raises_exception_when_owner_is_not_in_db(self):
username="random-user-123",
service="github",
)
with pytest.raises(ValidationError):
with pytest.raises(CodecovValidationError):
self.execute(current_user=current_user, org_username="some-other-username")

def test_cancel_trial_raises_exception_when_current_user_not_part_of_org(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from asgiref.sync import async_to_sync
from django.test import TransactionTestCase
from freezegun import freeze_time
from shared.django_apps.codecov.commands.exceptions import ValidationError
from shared.django_apps.core.tests.factories import OwnerFactory
from shared.plan.constants import (
TRIAL_PLAN_SEATS,
Expand All @@ -12,7 +13,8 @@
TrialStatus,
)

from codecov.commands.exceptions import Unauthorized, ValidationError
from codecov.commands.exceptions import Unauthorized
from codecov.commands.exceptions import ValidationError as CodecovValidationError
from codecov_auth.models import Owner

from ..start_trial import StartTrialInteractor
Expand All @@ -31,7 +33,7 @@ def test_start_trial_raises_exception_when_owner_is_not_in_db(self):
username="random-user-123",
service="github",
)
with pytest.raises(ValidationError):
with pytest.raises(CodecovValidationError):
self.execute(current_user=current_user, org_username="some-other-username")

def test_cancel_trial_raises_exception_when_current_user_not_part_of_org(self):
Expand Down
6 changes: 3 additions & 3 deletions codecov_auth/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def test_start_trial_ui_display(self):
assert res.status_code == 200
assert "Extending trial for:" in str(res.content)

@patch("plan.service.PlanService.start_trial_manually")
@patch("shared.plan.service.PlanService.start_trial_manually")
def test_start_trial_action(self, mock_start_trial_service):
mock_start_trial_service.return_value = None
org_to_be_trialed = OwnerFactory()
Expand All @@ -317,7 +317,7 @@ def test_start_trial_action(self, mock_start_trial_service):
assert res.status_code == 302
assert mock_start_trial_service.called

@patch("plan.service.PlanService._start_trial_helper")
@patch("shared.plan.service.PlanService._start_trial_helper")
def test_extend_trial_action(self, mock_start_trial_service):
mock_start_trial_service.return_value = None
org_to_be_trialed = OwnerFactory()
Expand All @@ -337,7 +337,7 @@ 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")
@patch("shared.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"
Expand Down
5 changes: 3 additions & 2 deletions graphql_api/tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_owner_plan_data_has_seats_left(self):
data = self.gql_request(query, owner=current_org)
assert data["owner"]["plan"] == {"hasSeatsLeft": True}

@patch("services.self_hosted.get_current_license")
@patch("shared.self_hosted.service.get_current_license")
def test_plan_user_count_for_enterprise_org(self, mocked_license):
"""
If an Org has an enterprise license, number_allowed_users from their license
Expand Down Expand Up @@ -190,10 +190,11 @@ def test_plan_user_count_for_enterprise_org(self, mocked_license):
}
""" % (enterprise_org.username)
data = self.gql_request(query, owner=enterprise_org)
print(data, "look here 1")
assert data["owner"]["plan"]["planUserCount"] == 5
assert data["owner"]["plan"]["hasSeatsLeft"] == False

@patch("services.self_hosted.get_current_license")
@patch("shared.self_hosted.service.get_current_license")
def test_plan_user_count_for_enterprise_org_invaild_license(self, mocked_license):
mock_enterprise_license = LicenseInformation(
is_valid=False,
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/types/owner/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.conf import settings
from graphql import GraphQLResolveInfo
from shared.plan.constants import FREE_PLAN_REPRESENTATIONS, PlanData, PlanName
from shared.plan.service import PlanService

import services.activation as activation
import timeseries.helpers as timeseries_helpers
Expand Down Expand Up @@ -40,7 +41,6 @@
from graphql_api.types.enums import OrderingDirection, RepositoryOrdering
from graphql_api.types.errors.errors import NotFoundError
from graphql_api.types.repository.repository import TOKEN_UNAVAILABLE
from plan.service import PlanService
from services.billing import BillingService
from services.profiling import ProfilingSummary
from services.redis_configuration import get_redis_connection
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/types/plan/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from shared.plan.constants import (
TrialStatus,
)
from shared.plan.service import PlanService

from codecov.db import sync_to_async
from graphql_api.helpers.ariadne import ariadne_load_local_graphql
from plan.service import PlanService

plan = ariadne_load_local_graphql(__file__, "plan.graphql")
plan_bindable = ObjectType("Plan")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from ariadne import ObjectType
from shared.plan.constants import PlanData
from shared.plan.service import PlanService

from graphql_api.helpers.ariadne import ariadne_load_local_graphql
from plan.service import PlanService

plan_representation = ariadne_load_local_graphql(
__file__, "plan_representation.graphql"
Expand Down
Empty file removed plan/__init__.py
Empty file.
Loading

0 comments on commit 1d7539e

Please sign in to comment.