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

Commit 786d94a

Browse files
authored
Replace usage of TransactionTestCase (#1183)
1 parent a74ce80 commit 786d94a

File tree

189 files changed

+344
-335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+344
-335
lines changed

codecov/db/__init__.py

-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22

3-
from asgiref.sync import SyncToAsync
43
from django.conf import settings
5-
from django.db import close_old_connections
64
from django.db.models import Field, Lookup
75

86
log = logging.getLogger(__name__)
@@ -69,19 +67,3 @@ def as_sql(self, compiler, connection):
6967
rhs, rhs_params = self.process_rhs(compiler, connection)
7068
params = tuple(lhs_params) + tuple(rhs_params)
7169
return "%s is not %s" % (lhs, rhs), params
72-
73-
74-
class DatabaseSyncToAsync(SyncToAsync):
75-
"""
76-
SyncToAsync version that cleans up old database connections.
77-
"""
78-
79-
def thread_handler(self, loop, *args, **kwargs):
80-
close_old_connections()
81-
try:
82-
return super().thread_handler(loop, *args, **kwargs)
83-
finally:
84-
close_old_connections()
85-
86-
87-
sync_to_async = DatabaseSyncToAsync

codecov_auth/commands/owner/interactors/cancel_trial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from shared.plan.service import PlanService
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.helpers import current_user_part_of_org
77
from codecov_auth.models import Owner
88

codecov_auth/commands/owner/interactors/create_api_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, ValidationError
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import Session
56

67

codecov_auth/commands/owner/interactors/create_stripe_setup_intent.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import logging
22

33
import stripe
4+
from asgiref.sync import sync_to_async
45

56
from codecov.commands.base import BaseInteractor
67
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
7-
from codecov.db import sync_to_async
88
from codecov_auth.helpers import current_user_part_of_org
99
from codecov_auth.models import Owner
1010
from services.billing import BillingService

codecov_auth/commands/owner/interactors/create_user_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, ValidationError
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import UserToken
56

67

codecov_auth/commands/owner/interactors/delete_session.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django.contrib.sessions.models import Session as DjangoSession
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthenticated
5-
from codecov.db import sync_to_async
66
from codecov_auth.models import Session
77

88

codecov_auth/commands/owner/interactors/fetch_owner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from codecov_auth.models import Owner
45

56

codecov_auth/commands/owner/interactors/get_org_upload_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated, Unauthorized
3-
from codecov.db import sync_to_async
45
from codecov_auth.helpers import current_user_part_of_org
56
from codecov_auth.models import OrganizationLevelToken
67

codecov_auth/commands/owner/interactors/get_uploads_number_per_user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional
22

3+
from asgiref.sync import sync_to_async
34
from shared.plan.service import PlanService
45
from shared.upload.utils import query_monthly_coverage_measurements
56

67
from codecov.commands.base import BaseInteractor
7-
from codecov.db import sync_to_async
88
from codecov_auth.models import Owner
99
from services.redis_configuration import get_redis_connection
1010

codecov_auth/commands/owner/interactors/is_syncing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
2-
from codecov.db import sync_to_async
34
from services.refresh import RefreshService
45

56

codecov_auth/commands/owner/interactors/onboard_user.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from django import forms
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.models import OwnerProfile
77

88

codecov_auth/commands/owner/interactors/regenerate_org_upload_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import uuid
22

3+
from asgiref.sync import sync_to_async
4+
35
from codecov.commands.base import BaseInteractor
46
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
67
from codecov_auth.helpers import current_user_part_of_org
78
from codecov_auth.models import OrganizationLevelToken, Owner
89

codecov_auth/commands/owner/interactors/revoke_user_token.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
from asgiref.sync import sync_to_async
2+
13
from codecov.commands.base import BaseInteractor
24
from codecov.commands.exceptions import Unauthenticated
3-
from codecov.db import sync_to_async
45
from codecov_auth.models import UserToken
56

67

codecov_auth/commands/owner/interactors/save_okta_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from dataclasses import dataclass
22

3+
from asgiref.sync import sync_to_async
34
from shared.django_apps.codecov_auth.models import AccountsUsers, User
45

56
from codecov.commands.base import BaseInteractor
67
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
7-
from codecov.db import sync_to_async
88
from codecov_auth.models import Account, OktaSettings, Owner
99

1010

codecov_auth/commands/owner/interactors/save_terms_agreement.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from dataclasses import dataclass
22
from typing import Any, Optional
33

4+
from asgiref.sync import sync_to_async
45
from django.utils import timezone
56

67
from codecov.commands.base import BaseInteractor
78
from codecov.commands.exceptions import Unauthenticated, ValidationError
8-
from codecov.db import sync_to_async
99
from services.analytics import AnalyticsService
1010

1111

codecov_auth/commands/owner/interactors/set_upload_token_required.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from dataclasses import dataclass
22

3+
from asgiref.sync import sync_to_async
4+
35
from codecov.commands.base import BaseInteractor
46
from codecov.commands.exceptions import Unauthenticated, Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
67
from codecov_auth.helpers import current_user_part_of_org
78
from codecov_auth.models import Owner
89

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Optional
33

44
import yaml
5+
from asgiref.sync import sync_to_async
56
from shared.django_apps.core.models import Repository
67
from shared.django_apps.utils.model_utils import get_ownerid_if_member
78
from shared.validation.exceptions import InvalidYamlException
@@ -14,7 +15,6 @@
1415
Unauthorized,
1516
ValidationError,
1617
)
17-
from codecov.db import sync_to_async
1818
from codecov_auth.constants import OWNER_YAML_TO_STRING_KEY
1919
from codecov_auth.helpers import current_user_part_of_org
2020
from codecov_auth.models import Owner

codecov_auth/commands/owner/interactors/start_trial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from asgiref.sync import sync_to_async
12
from shared.plan.service import PlanService
23

34
from codecov.commands.base import BaseInteractor
45
from codecov.commands.exceptions import Unauthorized, ValidationError
5-
from codecov.db import sync_to_async
66
from codecov_auth.helpers import current_user_part_of_org
77
from codecov_auth.models import Owner
88

codecov_auth/commands/owner/interactors/store_codecov_metric.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import json
22

3+
from asgiref.sync import sync_to_async
34
from shared.django_apps.codecov_metrics.service.codecov_metrics import (
45
UserOnboardingMetricsService,
56
)
67

78
from codecov.commands.base import BaseInteractor
89
from codecov.commands.exceptions import ValidationError
9-
from codecov.db import sync_to_async
1010
from codecov_auth.models import Owner
1111

1212

codecov_auth/commands/owner/interactors/tests/test_cancel_trial.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from asgiref.sync import async_to_sync
5-
from django.test import TransactionTestCase
5+
from django.test import TestCase
66
from freezegun import freeze_time
77
from shared.django_apps.codecov.commands.exceptions import ValidationError
88
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
@@ -16,7 +16,7 @@
1616
from ..cancel_trial import CancelTrialInteractor
1717

1818

19-
class CancelTrialInteractorTest(TransactionTestCase):
19+
class CancelTrialInteractorTest(TestCase):
2020
def setUp(self):
2121
self.tier = TierFactory(tier_name=DEFAULT_FREE_PLAN)
2222
self.plan = PlanFactory(tier=self.tier)

codecov_auth/commands/owner/interactors/tests/test_create_api_token.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from django.test import TestCase
33
from shared.django_apps.core.tests.factories import OwnerFactory
44

55
from codecov.commands.exceptions import Unauthenticated, ValidationError
66

77
from ..create_api_token import CreateApiTokenInteractor
88

99

10-
class CreateApiTokenInteractorTest(TransactionTestCase):
10+
class CreateApiTokenInteractorTest(TestCase):
1111
def setUp(self):
1212
self.owner = OwnerFactory(username="codecov-user")
1313

codecov_auth/commands/owner/interactors/tests/test_create_user_token.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from django.test import TestCase
33
from shared.django_apps.core.tests.factories import OwnerFactory
44

55
from codecov.commands.exceptions import Unauthenticated, ValidationError
@@ -8,7 +8,7 @@
88
from ..create_user_token import CreateUserTokenInteractor
99

1010

11-
class CreateUserTokenInteractorTest(TransactionTestCase):
11+
class CreateUserTokenInteractorTest(TestCase):
1212
def setUp(self):
1313
self.owner = OwnerFactory(username="codecov-user")
1414

codecov_auth/commands/owner/interactors/tests/test_delete_session.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from asgiref.sync import sync_to_async
3+
from django.test import TestCase
34
from shared.django_apps.codecov_auth.tests.factories import OwnerFactory, SessionFactory
45

56
from codecov.commands.exceptions import Unauthenticated
6-
from codecov.db import sync_to_async
77
from codecov_auth.models import DjangoSession, Session
88
from codecov_auth.tests.factories import DjangoSessionFactory
99

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

1717

18-
class DeleteSessionInteractorTest(TransactionTestCase):
18+
class DeleteSessionInteractorTest(TestCase):
1919
def setUp(self):
2020
self.owner = OwnerFactory(username="codecov-user")
2121
self.django_session = DjangoSessionFactory()

codecov_auth/commands/owner/interactors/tests/test_get_is_current_user_an_admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest.mock import patch
22

33
from asgiref.sync import async_to_sync
4-
from django.test import TransactionTestCase, override_settings
4+
from django.test import TestCase, override_settings
55
from shared.django_apps.codecov_auth.tests.factories import (
66
GetAdminProviderAdapter,
77
OwnerFactory,
@@ -13,7 +13,7 @@
1313
)
1414

1515

16-
class GetIsCurrentUserAnAdminInteractorTest(TransactionTestCase):
16+
class GetIsCurrentUserAnAdminInteractorTest(TestCase):
1717
def setUp(self):
1818
self.owner_has_admins = OwnerFactory(ownerid=0, admins=[2])
1919
self.owner_has_no_admins = OwnerFactory(ownerid=1, admins=[])

codecov_auth/commands/owner/interactors/tests/test_get_org_upload_token.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from django.test import TestCase
33
from shared.django_apps.codecov_auth.tests.factories import (
44
OrganizationLevelTokenFactory,
55
OwnerFactory,
@@ -10,7 +10,7 @@
1010
from ..get_org_upload_token import GetOrgUploadToken
1111

1212

13-
class GetOrgUploadTokenInteractorTest(TransactionTestCase):
13+
class GetOrgUploadTokenInteractorTest(TestCase):
1414
def setUp(self):
1515
self.owner_with_no_upload_token = OwnerFactory()
1616
self.owner_with_upload_token = OwnerFactory(plan="users-enterprisem")

codecov_auth/commands/owner/interactors/tests/test_get_uploads_number_per_user.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import datetime, timedelta
22

3-
from django.test import TransactionTestCase
3+
from django.test import TestCase
44
from shared.django_apps.codecov_auth.tests.factories import PlanFactory, TierFactory
55
from shared.django_apps.core.tests.factories import (
66
CommitFactory,
@@ -16,7 +16,7 @@
1616
from ..get_uploads_number_per_user import GetUploadsNumberPerUserInteractor
1717

1818

19-
class GetUploadsNumberPerUserInteractorTest(TransactionTestCase):
19+
class GetUploadsNumberPerUserInteractorTest(TestCase):
2020
def setUp(self):
2121
self.tier = TierFactory(tier_name=TierName.BASIC.value)
2222
self.plan = PlanFactory(tier=self.tier, monthly_uploads_limit=250)

codecov_auth/commands/owner/interactors/tests/test_is_syncing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
from unittest.mock import patch
22

33
from asgiref.sync import async_to_sync
4-
from django.test import TransactionTestCase
4+
from django.test import TestCase
55
from shared.django_apps.core.tests.factories import OwnerFactory
66

77
from ..is_syncing import IsSyncingInteractor
88

99

10-
class IsSyncingInteractorTest(TransactionTestCase):
10+
class IsSyncingInteractorTest(TestCase):
1111
def setUp(self):
1212
self.owner = OwnerFactory(username="codecov-user")
1313

codecov_auth/commands/owner/interactors/tests/test_onboard_user.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from django.test import TestCase
33
from shared.django_apps.core.tests.factories import OwnerFactory
44

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

99

10-
class OnboardUserInteractorTest(TransactionTestCase):
10+
class OnboardUserInteractorTest(TestCase):
1111
def setUp(self):
1212
self.owner = OwnerFactory(username="codecov-user")
1313
self.already_onboarded_owner = OwnerFactory(

codecov_auth/commands/owner/interactors/tests/test_regenerate_org_upload_token.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import pytest
2-
from django.test import TransactionTestCase
2+
from django.test import TestCase
33
from shared.django_apps.core.tests.factories import OwnerFactory
44

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

77
from ..regenerate_org_upload_token import RegenerateOrgUploadTokenInteractor
88

99

10-
class RegenerateOrgUploadTokenInteractorTest(TransactionTestCase):
10+
class RegenerateOrgUploadTokenInteractorTest(TestCase):
1111
def setUp(self):
1212
self.random_user = OwnerFactory()
1313
self.owner = OwnerFactory(username="codecovv", plan="users-enterprisem")

0 commit comments

Comments
 (0)