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
18 changes: 0 additions & 18 deletions codecov/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import logging

from asgiref.sync import SyncToAsync
from django.conf import settings
from django.db import close_old_connections
from django.db.models import Field, Lookup

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -69,19 +67,3 @@ def as_sql(self, compiler, connection):
rhs, rhs_params = self.process_rhs(compiler, connection)
params = tuple(lhs_params) + tuple(rhs_params)
return "%s is not %s" % (lhs, rhs), params


class DatabaseSyncToAsync(SyncToAsync):
"""
SyncToAsync version that cleans up old database connections.
"""

def thread_handler(self, loop, *args, **kwargs):
close_old_connections()
try:
return super().thread_handler(loop, *args, **kwargs)
finally:
close_old_connections()


sync_to_async = DatabaseSyncToAsync
2 changes: 1 addition & 1 deletion codecov_auth/commands/owner/interactors/cancel_trial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async
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

Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/create_api_token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, ValidationError
from codecov.db import sync_to_async
from codecov_auth.models import Session


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

import stripe
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, 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 services.billing import BillingService
Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/create_user_token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, ValidationError
from codecov.db import sync_to_async
from codecov_auth.models import UserToken


Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/commands/owner/interactors/delete_session.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async
from django.contrib.sessions.models import Session as DjangoSession

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated
from codecov.db import sync_to_async
from codecov_auth.models import Session


Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/fetch_owner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.db import sync_to_async
from codecov_auth.models import Owner


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, Unauthorized
from codecov.db import sync_to_async
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import OrganizationLevelToken

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Optional

from asgiref.sync import sync_to_async
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 services.redis_configuration import get_redis_connection

Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/is_syncing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.db import sync_to_async
from services.refresh import RefreshService


Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/commands/owner/interactors/onboard_user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async
from django import forms

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
from codecov.db import sync_to_async
from codecov_auth.models import OwnerProfile


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import uuid

from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
from codecov.db import sync_to_async
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import OrganizationLevelToken, Owner

Expand Down
3 changes: 2 additions & 1 deletion codecov_auth/commands/owner/interactors/revoke_user_token.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated
from codecov.db import sync_to_async
from codecov_auth.models import UserToken


Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from dataclasses import dataclass

from asgiref.sync import sync_to_async
from shared.django_apps.codecov_auth.models import AccountsUsers, User

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
from codecov.db import sync_to_async
from codecov_auth.models import Account, OktaSettings, Owner


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass
from typing import Any, Optional

from asgiref.sync import sync_to_async
from django.utils import timezone

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, ValidationError
from codecov.db import sync_to_async
from services.analytics import AnalyticsService


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass

from asgiref.sync import sync_to_async

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import Unauthenticated, 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

import yaml
from asgiref.sync import sync_to_async
from shared.django_apps.core.models import Repository
from shared.django_apps.utils.model_utils import get_ownerid_if_member
from shared.validation.exceptions import InvalidYamlException
Expand All @@ -14,7 +15,6 @@
Unauthorized,
ValidationError,
)
from codecov.db import sync_to_async
from codecov_auth.constants import OWNER_YAML_TO_STRING_KEY
from codecov_auth.helpers import current_user_part_of_org
from codecov_auth.models import Owner
Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/commands/owner/interactors/start_trial.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from asgiref.sync import sync_to_async
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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json

from asgiref.sync import sync_to_async
from shared.django_apps.codecov_metrics.service.codecov_metrics import (
UserOnboardingMetricsService,
)

from codecov.commands.base import BaseInteractor
from codecov.commands.exceptions import ValidationError
from codecov.db import sync_to_async
from codecov_auth.models import Owner


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from asgiref.sync import async_to_sync
from django.test import TransactionTestCase
from django.test import TestCase
from freezegun import freeze_time
from shared.django_apps.codecov.commands.exceptions import ValidationError
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
Expand All @@ -16,7 +16,7 @@
from ..cancel_trial import CancelTrialInteractor


class CancelTrialInteractorTest(TransactionTestCase):
class CancelTrialInteractorTest(TestCase):
def setUp(self):
self.tier = TierFactory(tier_name=DEFAULT_FREE_PLAN)
self.plan = PlanFactory(tier=self.tier)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.core.tests.factories import OwnerFactory

from codecov.commands.exceptions import Unauthenticated, ValidationError

from ..create_api_token import CreateApiTokenInteractor


class CreateApiTokenInteractorTest(TransactionTestCase):
class CreateApiTokenInteractorTest(TestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov-user")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.core.tests.factories import OwnerFactory

from codecov.commands.exceptions import Unauthenticated, ValidationError
Expand All @@ -8,7 +8,7 @@
from ..create_user_token import CreateUserTokenInteractor


class CreateUserTokenInteractorTest(TransactionTestCase):
class CreateUserTokenInteractorTest(TestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov-user")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from django.test import TransactionTestCase
from asgiref.sync import sync_to_async
from django.test import TestCase
from shared.django_apps.codecov_auth.tests.factories import OwnerFactory, SessionFactory

from codecov.commands.exceptions import Unauthenticated
from codecov.db import sync_to_async
from codecov_auth.models import DjangoSession, Session
from codecov_auth.tests.factories import DjangoSessionFactory

Expand All @@ -15,7 +15,7 @@ def get_session(id):
return Session.objects.get(sessionid=id)


class DeleteSessionInteractorTest(TransactionTestCase):
class DeleteSessionInteractorTest(TestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov-user")
self.django_session = DjangoSessionFactory()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.mock import patch

from asgiref.sync import async_to_sync
from django.test import TransactionTestCase, override_settings
from django.test import TestCase, override_settings
from shared.django_apps.codecov_auth.tests.factories import (
GetAdminProviderAdapter,
OwnerFactory,
Expand All @@ -13,7 +13,7 @@
)


class GetIsCurrentUserAnAdminInteractorTest(TransactionTestCase):
class GetIsCurrentUserAnAdminInteractorTest(TestCase):
def setUp(self):
self.owner_has_admins = OwnerFactory(ownerid=0, admins=[2])
self.owner_has_no_admins = OwnerFactory(ownerid=1, admins=[])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.codecov_auth.tests.factories import (
OrganizationLevelTokenFactory,
OwnerFactory,
Expand All @@ -10,7 +10,7 @@
from ..get_org_upload_token import GetOrgUploadToken


class GetOrgUploadTokenInteractorTest(TransactionTestCase):
class GetOrgUploadTokenInteractorTest(TestCase):
def setUp(self):
self.owner_with_no_upload_token = OwnerFactory()
self.owner_with_upload_token = OwnerFactory(plan="users-enterprisem")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime, timedelta

from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
from shared.django_apps.core.tests.factories import (
CommitFactory,
Expand All @@ -16,7 +16,7 @@
from ..get_uploads_number_per_user import GetUploadsNumberPerUserInteractor


class GetUploadsNumberPerUserInteractorTest(TransactionTestCase):
class GetUploadsNumberPerUserInteractorTest(TestCase):
def setUp(self):
self.tier = TierFactory(tier_name=TierName.BASIC.value)
self.plan = PlanFactory(tier=self.tier, monthly_uploads_limit=250)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from unittest.mock import patch

from asgiref.sync import async_to_sync
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.core.tests.factories import OwnerFactory

from ..is_syncing import IsSyncingInteractor


class IsSyncingInteractorTest(TransactionTestCase):
class IsSyncingInteractorTest(TestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov-user")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.core.tests.factories import OwnerFactory

from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
from codecov_auth.commands.owner.interactors.onboard_user import OnboardUserInteractor
from codecov_auth.models import OwnerProfile


class OnboardUserInteractorTest(TransactionTestCase):
class OnboardUserInteractorTest(TestCase):
def setUp(self):
self.owner = OwnerFactory(username="codecov-user")
self.already_onboarded_owner = OwnerFactory(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pytest
from django.test import TransactionTestCase
from django.test import TestCase
from shared.django_apps.core.tests.factories import OwnerFactory

from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError

from ..regenerate_org_upload_token import RegenerateOrgUploadTokenInteractor


class RegenerateOrgUploadTokenInteractorTest(TransactionTestCase):
class RegenerateOrgUploadTokenInteractorTest(TestCase):
def setUp(self):
self.random_user = OwnerFactory()
self.owner = OwnerFactory(username="codecovv", plan="users-enterprisem")
Expand Down
Loading
Loading