Skip to content
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
38 changes: 0 additions & 38 deletions apps/codecov-api/services/task/task_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
from codecov_auth.models import Owner
from compare.models import CommitComparison
from core.models import Repository
from labelanalysis.models import LabelAnalysisRequest
from shared.celery_router import route_tasks_based_on_user_plan
from shared.plan.constants import DEFAULT_FREE_PLAN
from staticanalysis.models import StaticAnalysisSuite


def _get_user_plan_from_ownerid(ownerid, *args, **kwargs) -> str:
Expand Down Expand Up @@ -38,38 +36,6 @@ def _get_user_plan_from_comparison_id(comparison_id, *args, **kwargs) -> str:
return DEFAULT_FREE_PLAN


def _get_user_plan_from_label_request_id(request_id, *args, **kwargs) -> str:
label_analysis_request = (
LabelAnalysisRequest.objects.filter(id=request_id)
.select_related("head_commit__repository__author")
.first()
)
if (
label_analysis_request
and label_analysis_request.head_commit
and label_analysis_request.head_commit.repository
and label_analysis_request.head_commit.repository.author
):
return label_analysis_request.head_commit.repository.author.plan
return DEFAULT_FREE_PLAN


def _get_user_plan_from_suite_id(suite_id, *args, **kwargs) -> str:
static_analysis_suite = (
StaticAnalysisSuite.objects.filter(id=suite_id)
.select_related("commit__repository__author")
.first()
)
if (
static_analysis_suite
and static_analysis_suite.commit
and static_analysis_suite.commit.repository
and static_analysis_suite.commit.repository.author
):
return static_analysis_suite.commit.repository.author.plan
return DEFAULT_FREE_PLAN


def _get_user_plan_from_task(task_name: str, task_kwargs: dict) -> str:
owner_plan_lookup_funcs = {
# from ownerid
Expand All @@ -84,10 +50,6 @@ def _get_user_plan_from_task(task_name: str, task_kwargs: dict) -> str:
shared_celery_config.pulls_task_name: _get_user_plan_from_repoid,
# from comparison_id
shared_celery_config.compute_comparison_task_name: _get_user_plan_from_comparison_id,
# from label_request_id
shared_celery_config.label_analysis_task_name: _get_user_plan_from_label_request_id,
# from suite_id
shared_celery_config.static_analysis_task_name: _get_user_plan_from_suite_id,
}
func_to_use = owner_plan_lookup_funcs.get(
task_name, lambda *args, **kwargs: DEFAULT_FREE_PLAN
Expand Down
62 changes: 0 additions & 62 deletions apps/codecov-api/services/tests/test_task_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@

import shared.celery_config as shared_celery_config
from compare.tests.factories import CommitComparisonFactory
from labelanalysis.tests.factories import LabelAnalysisRequestFactory
from services.task.task_router import (
_get_user_plan_from_comparison_id,
_get_user_plan_from_label_request_id,
_get_user_plan_from_ownerid,
_get_user_plan_from_repoid,
_get_user_plan_from_suite_id,
_get_user_plan_from_task,
route_task,
)
from shared.django_apps.core.tests.factories import OwnerFactory, RepositoryFactory
from shared.plan.constants import DEFAULT_FREE_PLAN, PlanName
from staticanalysis.tests.factories import StaticAnalysisSuiteFactory


@pytest.fixture
Expand Down Expand Up @@ -51,30 +47,6 @@ def fake_compare_commit(db, fake_repos):
return (compare_commit, compare_commit_enterprise)


@pytest.fixture
def fake_label_analysis_request(db, fake_repos):
(repo, repo_enterprise_cloud) = fake_repos
label_analysis_request = LabelAnalysisRequestFactory(head_commit__repository=repo)
label_analysis_request_enterprise = LabelAnalysisRequestFactory(
head_commit__repository=repo_enterprise_cloud
)
label_analysis_request.save()
label_analysis_request_enterprise.save()
return (label_analysis_request, label_analysis_request_enterprise)


@pytest.fixture
def fake_static_analysis_suite(db, fake_repos):
(repo, repo_enterprise_cloud) = fake_repos
static_analysis_suite = StaticAnalysisSuiteFactory(commit__repository=repo)
static_analysis_suite_enterprise = StaticAnalysisSuiteFactory(
commit__repository=repo_enterprise_cloud
)
static_analysis_suite.save()
static_analysis_suite_enterprise.save()
return (static_analysis_suite, static_analysis_suite_enterprise)


def test_get_owner_plan_from_ownerid(fake_owners):
(owner, owner_enterprise_cloud) = fake_owners
assert (
Expand Down Expand Up @@ -110,40 +82,6 @@ def test_get_user_plan_from_comparison_id(fake_compare_commit):
assert _get_user_plan_from_comparison_id(10000000) == DEFAULT_FREE_PLAN


def test_get_user_plan_from_label_request_id(fake_label_analysis_request):
(
label_analysis_request,
label_analysis_request_enterprise,
) = fake_label_analysis_request
assert (
_get_user_plan_from_label_request_id(request_id=label_analysis_request.id)
== PlanName.CODECOV_PRO_MONTHLY.value
)
assert (
_get_user_plan_from_label_request_id(
request_id=label_analysis_request_enterprise.id
)
== PlanName.ENTERPRISE_CLOUD_YEARLY.value
)
assert _get_user_plan_from_label_request_id(10000000) == DEFAULT_FREE_PLAN


def test_get_user_plan_from_static_analysis_suite(fake_static_analysis_suite):
(
static_analysis_suite,
static_analysis_suite_enterprise,
) = fake_static_analysis_suite
assert (
_get_user_plan_from_suite_id(suite_id=static_analysis_suite.id)
== PlanName.CODECOV_PRO_MONTHLY.value
)
assert (
_get_user_plan_from_suite_id(suite_id=static_analysis_suite_enterprise.id)
== PlanName.ENTERPRISE_CLOUD_YEARLY.value
)
assert _get_user_plan_from_suite_id(10000000) == DEFAULT_FREE_PLAN


def test_get_user_plan_from_task(
fake_repos,
fake_compare_commit,
Expand Down
34 changes: 0 additions & 34 deletions apps/worker/celery_task_router.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import shared.celery_config as shared_celery_config
from database.engine import get_db_session
from database.models.core import Commit, CompareCommit, Owner, Repository
from database.models.labelanalysis import LabelAnalysisRequest
from database.models.staticanalysis import StaticAnalysisSuite
from shared.celery_router import route_tasks_based_on_user_plan
from shared.plan.constants import DEFAULT_FREE_PLAN

Expand Down Expand Up @@ -44,34 +42,6 @@ def _get_user_plan_from_comparison_id(dbsession, comparison_id, *args, **kwargs)
return DEFAULT_FREE_PLAN


def _get_user_plan_from_label_request_id(dbsession, request_id, *args, **kwargs) -> str:
result = (
dbsession.query(Owner.plan)
.join(LabelAnalysisRequest.head_commit)
.join(Commit.repository)
.join(Repository.owner)
.filter(LabelAnalysisRequest.id_ == request_id)
.first()
)
if result:
return result.plan
return DEFAULT_FREE_PLAN


def _get_user_plan_from_suite_id(dbsession, suite_id, *args, **kwargs) -> str:
result = (
dbsession.query(Owner.plan)
.join(StaticAnalysisSuite.commit)
.join(Commit.repository)
.join(Repository.owner)
.filter(StaticAnalysisSuite.id_ == suite_id)
.first()
)
if result:
return result.plan
return DEFAULT_FREE_PLAN


def _get_user_plan_from_task(dbsession, task_name: str, task_kwargs: dict) -> str:
owner_plan_lookup_funcs = {
# from ownerid
Expand All @@ -95,10 +65,6 @@ def _get_user_plan_from_task(dbsession, task_name: str, task_kwargs: dict) -> st
shared_celery_config.manual_upload_completion_trigger_task_name: _get_user_plan_from_repoid,
# from comparison_id
shared_celery_config.compute_comparison_task_name: _get_user_plan_from_comparison_id,
# from label_request_id
shared_celery_config.label_analysis_task_name: _get_user_plan_from_label_request_id,
# from suite_id
shared_celery_config.static_analysis_task_name: _get_user_plan_from_suite_id,
}
func_to_use = owner_plan_lookup_funcs.get(
task_name, lambda *args, **kwargs: DEFAULT_FREE_PLAN
Expand Down
188 changes: 0 additions & 188 deletions apps/worker/services/static_analysis/__init__.py

This file was deleted.

Loading