Browse Source

test(hc): Various fixes to unannotated test cases (#63618)

Ryan Skonnord 1 year ago
parent
commit
52c7d0700d

+ 1 - 0
src/sentry/testutils/factories.py

@@ -842,6 +842,7 @@ class Factories:
                 )
 
     @staticmethod
+    @assume_test_silo_mode(SiloMode.REGION)
     def store_event(data, project_id, assert_no_errors=True, sent_at=None):
         # Like `create_event`, but closer to how events are actually
         # ingested. Prefer to use this method over `create_event`

+ 2 - 1
src/sentry/testutils/silo.py

@@ -303,7 +303,8 @@ class _SiloModeTestModification:
             current_class = class_queue.pop(0)
             if getattr(current_class, "_silo_modes", None):
                 raise AncestorAlreadySiloDecoratedException(
-                    f"Cannot decorate class '{object_to_validate.__name__}', which inherits from a silo decorated class"
+                    f"Cannot decorate class '{object_to_validate.__name__}', "
+                    f"which inherits from a silo decorated class ({current_class.__name__})"
                 )
             class_queue.extend(current_class.__bases__)
 

+ 7 - 0
tests/relay_integration/test_sdk.py

@@ -12,6 +12,7 @@ from sentry.receivers import create_default_projects
 from sentry.testutils.asserts import assert_mock_called_once_with_partial
 from sentry.testutils.pytest.fixtures import django_db_all
 from sentry.testutils.pytest.relay import adjust_settings_for_relay_tests
+from sentry.testutils.silo import no_silo_test
 from sentry.testutils.skips import requires_kafka
 from sentry.utils.sdk import bind_organization_context, configure_sdk
 
@@ -63,6 +64,7 @@ def post_event_with_sdk(settings, relay_server, wait_for_ingest_consumer):
         yield inner
 
 
+@no_silo_test
 @override_settings(SENTRY_PROJECT=1)
 @django_db_all
 def test_simple(settings, post_event_with_sdk):
@@ -73,6 +75,7 @@ def test_simple(settings, post_event_with_sdk):
     assert event.data["logentry"]["formatted"] == "internal client test"
 
 
+@no_silo_test
 @override_settings(SENTRY_PROJECT=1)
 @django_db_all
 def test_recursion_breaker(settings, post_event_with_sdk):
@@ -90,6 +93,7 @@ def test_recursion_breaker(settings, post_event_with_sdk):
     assert_mock_called_once_with_partial(save, settings.SENTRY_PROJECT, cache_key=f"e:{event_id}:1")
 
 
+@no_silo_test
 @django_db_all
 @override_settings(SENTRY_PROJECT=1)
 def test_encoding(settings, post_event_with_sdk):
@@ -105,6 +109,7 @@ def test_encoding(settings, post_event_with_sdk):
     assert "NotJSONSerializable" in event.data["extra"]["request"]
 
 
+@no_silo_test
 @override_settings(SENTRY_PROJECT=1)
 @django_db_all
 def test_bind_organization_context(default_organization):
@@ -120,6 +125,7 @@ def test_bind_organization_context(default_organization):
     }
 
 
+@no_silo_test
 @override_settings(SENTRY_PROJECT=1)
 @django_db_all
 def test_bind_organization_context_with_callback(settings, default_organization):
@@ -135,6 +141,7 @@ def test_bind_organization_context_with_callback(settings, default_organization)
     assert Hub.current.scope._tags["organization.test"] == "1"
 
 
+@no_silo_test
 @override_settings(SENTRY_PROJECT=1)
 @django_db_all
 def test_bind_organization_context_with_callback_error(settings, default_organization):

+ 3 - 1
tests/sentry/api/endpoints/test_event_reprocessable.py

@@ -1,9 +1,10 @@
 import pytest
 
+from sentry.silo import SiloMode
 from sentry.testutils.helpers import Feature
 from sentry.testutils.helpers.datetime import before_now, iso_format
 from sentry.testutils.pytest.fixtures import django_db_all
-from sentry.testutils.silo import region_silo_test
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 from sentry.testutils.skips import requires_snuba
 
 pytestmark = [requires_snuba]
@@ -15,6 +16,7 @@ def reprocessing_feature(monkeypatch):
         yield
 
 
+@assume_test_silo_mode(SiloMode.CONTROL)
 @pytest.fixture(autouse=True)
 def auto_login(settings, client, default_user):
     assert client.login(username=default_user.username, password="admin")

+ 2 - 0
tests/sentry/api/endpoints/test_user_authenticators_index.py

@@ -3,8 +3,10 @@ from django.urls import reverse
 from sentry.models.authenticator import Authenticator
 from sentry.testutils.cases import APITestCase
 from sentry.testutils.helpers.options import override_options
+from sentry.testutils.silo import control_silo_test
 
 
+@control_silo_test
 class AuthenticatorIndex(APITestCase):
     def test_simple(self):
         user = self.create_user(email="a@example.com", is_superuser=True)

+ 1 - 3
tests/sentry/api/endpoints/test_user_permission_details.py

@@ -3,6 +3,7 @@ from sentry.testutils.cases import APITestCase
 from sentry.testutils.silo import control_silo_test
 
 
+@control_silo_test
 class UserDetailsTest(APITestCase):
     endpoint = "sentry-api-0-user-permission-details"
 
@@ -30,7 +31,6 @@ class UserDetailsTest(APITestCase):
         assert resp.status_code == 403
 
 
-@control_silo_test
 class UserPermissionDetailsGetTest(UserDetailsTest):
     def test_with_permission(self):
         UserPermission.objects.create(user=self.user, permission="broadcasts.admin")
@@ -42,7 +42,6 @@ class UserPermissionDetailsGetTest(UserDetailsTest):
         assert resp.status_code == 404
 
 
-@control_silo_test
 class UserPermissionDetailsPostTest(UserDetailsTest):
     method = "POST"
 
@@ -58,7 +57,6 @@ class UserPermissionDetailsPostTest(UserDetailsTest):
         assert UserPermission.objects.filter(user=self.user, permission="broadcasts.admin").exists()
 
 
-@control_silo_test
 class UserPermissionDetailsDeleteTest(UserDetailsTest):
     method = "DELETE"
 

+ 1 - 3
tests/sentry/api/endpoints/test_user_role_details.py

@@ -3,6 +3,7 @@ from sentry.testutils.cases import APITestCase
 from sentry.testutils.silo import control_silo_test
 
 
+@control_silo_test
 class UserUserRolesTest(APITestCase):
     endpoint = "sentry-api-0-user-userrole-details"
 
@@ -31,7 +32,6 @@ class UserUserRolesTest(APITestCase):
         assert resp.status_code == 403
 
 
-@control_silo_test
 class UserUserRolesDetailsTest(UserUserRolesTest):
     def test_lookup_self(self):
         role = UserRole.objects.create(name="support", permissions=["broadcasts.admin"])
@@ -43,7 +43,6 @@ class UserUserRolesDetailsTest(UserUserRolesTest):
         assert resp.data["name"] == "support"
 
 
-@control_silo_test
 class UserUserRolesCreateTest(UserUserRolesTest):
     method = "POST"
 
@@ -67,7 +66,6 @@ class UserUserRolesCreateTest(UserUserRolesTest):
         assert resp.status_code == 410
 
 
-@control_silo_test
 class UserUserRolesDeleteTest(UserUserRolesTest):
     method = "DELETE"
 

+ 3 - 1
tests/sentry/hybridcloud/test_user.py

@@ -2,6 +2,7 @@ from sentry.models.avatars.user_avatar import UserAvatar
 from sentry.services.hybrid_cloud.user.service import user_service
 from sentry.testutils.factories import Factories
 from sentry.testutils.pytest.fixtures import django_db_all
+from sentry.testutils.silo import assume_test_silo_mode_of
 
 
 @django_db_all(transaction=True)
@@ -15,7 +16,8 @@ def test_user_serialize_avatar_none():
 @django_db_all(transaction=True)
 def test_user_serialize_avatar():
     user = Factories.create_user()
-    avatar = UserAvatar.objects.create(user_id=user.id, avatar_type=2, ident="abc123")
+    with assume_test_silo_mode_of(UserAvatar):
+        avatar = UserAvatar.objects.create(user_id=user.id, avatar_type=2, ident="abc123")
 
     rpc_user = user_service.get_user(user_id=user.id)
     assert rpc_user

+ 16 - 9
tests/sentry/incidents/action_handlers/test_opsgenie.py

@@ -5,8 +5,10 @@ import responses
 from sentry.incidents.action_handlers import OpsgenieActionHandler
 from sentry.incidents.logic import update_incident_status
 from sentry.incidents.models import AlertRuleTriggerAction, IncidentStatus, IncidentStatusMethod
+from sentry.models.integrations import Integration
 from sentry.models.integrations.organization_integration import OrganizationIntegration
 from sentry.testutils.helpers.datetime import freeze_time
+from sentry.testutils.silo import assume_test_silo_mode_of, region_silo_test
 from sentry.utils import json
 
 from . import FireTest
@@ -18,6 +20,7 @@ METADATA = {
 }
 
 
+@region_silo_test
 @freeze_time()
 class OpsgenieActionHandlerTest(FireTest):
     @responses.activate
@@ -26,12 +29,13 @@ class OpsgenieActionHandlerTest(FireTest):
         self.integration = self.create_provider_integration(
             provider="opsgenie", name="hello-world", external_id="hello-world", metadata=METADATA
         )
-        self.integration.add_organization(self.organization, self.user)
-        self.org_integration = OrganizationIntegration.objects.get(
-            organization_id=self.organization.id, integration_id=self.integration.id
-        )
-        self.org_integration.config = {"team_table": [self.og_team]}
-        self.org_integration.save()
+        with assume_test_silo_mode_of(Integration, OrganizationIntegration):
+            self.integration.add_organization(self.organization, self.user)
+            self.org_integration = OrganizationIntegration.objects.get(
+                organization_id=self.organization.id, integration_id=self.integration.id
+            )
+            self.org_integration.config = {"team_table": [self.og_team]}
+            self.org_integration.save()
 
         resp_data = {
             "result": "Integration [sentry] is valid",
@@ -133,7 +137,8 @@ class OpsgenieActionHandlerTest(FireTest):
     def test_fire_metric_alert_multiple_teams(self):
         team2 = {"id": "456-id", "team": "cooler-team", "integration_key": "1234-7890"}
         self.org_integration.config["team_table"].append(team2)
-        self.org_integration.save()
+        with assume_test_silo_mode_of(OrganizationIntegration):
+            self.org_integration.save()
 
         self.run_fire_test()
 
@@ -166,7 +171,8 @@ class OpsgenieActionHandlerTest(FireTest):
         alert_rule = self.create_alert_rule()
         incident = self.create_incident(alert_rule=alert_rule)
 
-        self.integration.delete()
+        with assume_test_silo_mode_of(Integration):
+            self.integration.delete()
 
         handler = OpsgenieActionHandler(self.action, incident, self.project)
         metric_value = 1000
@@ -186,7 +192,8 @@ class OpsgenieActionHandlerTest(FireTest):
         incident = self.create_incident(alert_rule=alert_rule)
 
         self.org_integration.config = {"team_table": []}
-        self.org_integration.save()
+        with assume_test_silo_mode_of(OrganizationIntegration):
+            self.org_integration.save()
 
         handler = OpsgenieActionHandler(self.action, incident, self.project)
         metric_value = 1000

+ 5 - 1
tests/sentry/integrations/jira/test_sentry_issue_details.py

@@ -9,8 +9,10 @@ from sentry.integrations.jira.views import UNABLE_TO_VERIFY_INSTALLATION
 from sentry.integrations.utils import AtlassianConnectValidationError
 from sentry.models.group import Group
 from sentry.models.grouplink import GroupLink
+from sentry.models.integrations import Integration
 from sentry.models.integrations.external_issue import ExternalIssue
 from sentry.testutils.cases import APITestCase
+from sentry.testutils.silo import assume_test_silo_mode_of, region_silo_test
 from sentry.testutils.skips import requires_snuba
 from sentry.utils.http import absolute_uri
 
@@ -21,6 +23,7 @@ REFRESH_REQUIRED = b"This page has expired, please refresh to view the Sentry is
 CLICK_TO_FINISH = b"Click to Finish Installation"
 
 
+@region_silo_test
 class JiraIssueHookTest(APITestCase):
     def setUp(self):
         super().setUp()
@@ -52,7 +55,8 @@ class JiraIssueHookTest(APITestCase):
                 "shared_secret": "a-super-secret-key-from-atlassian",
             },
         )
-        self.integration.add_organization(self.organization, self.user)
+        with assume_test_silo_mode_of(Integration):
+            self.integration.add_organization(self.organization, self.user)
 
         self.external_issue = ExternalIssue.objects.create(
             organization_id=group.organization.id,

Some files were not shown because too many files changed in this diff