Browse Source

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

Ryan Skonnord 1 year ago
parent
commit
87488acf26

+ 1 - 2
tests/sentry/api/endpoints/test_userroles_index.py

@@ -3,6 +3,7 @@ from sentry.testutils.cases import APITestCase
 from sentry.testutils.silo import control_silo_test
 
 
+@control_silo_test
 class UserRolesTest(APITestCase):
     endpoint = "sentry-api-0-userroles"
 
@@ -31,7 +32,6 @@ class UserRolesTest(APITestCase):
         assert resp.status_code == 403
 
 
-@control_silo_test
 class UserRolesGetTest(UserRolesTest):
     def test_simple(self):
         UserRole.objects.create(name="test-role")
@@ -41,7 +41,6 @@ class UserRolesGetTest(UserRolesTest):
         assert "test-role" in [r["name"] for r in resp.data]
 
 
-@control_silo_test
 class UserRolesPostTest(UserRolesTest):
     method = "POST"
 

+ 1 - 0
tests/sentry/api/test_authentication.py

@@ -168,6 +168,7 @@ class TestOrgAuthTokenAuthentication(TestCase):
             self.auth.authenticate(request)
 
 
+@control_silo_test
 class TestTokenAuthentication(TestCase):
     def setUp(self):
         super().setUp()

+ 7 - 2
tests/sentry/api/test_invite_helper.py

@@ -7,10 +7,13 @@ from sentry.models.authprovider import AuthProvider
 from sentry.models.organizationmember import OrganizationMember
 from sentry.services.hybrid_cloud.organization import organization_service
 from sentry.signals import receivers_raise_on_send
+from sentry.silo import SiloMode
 from sentry.testutils.cases import TestCase
 from sentry.testutils.outbox import outbox_runner
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 
 
+@region_silo_test
 class ApiInviteHelperTest(TestCase):
     def setUp(self):
         super().setUp()
@@ -46,7 +49,8 @@ class ApiInviteHelperTest(TestCase):
             invite_context,
             None,
         )
-        helper.accept_invite()
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            helper.accept_invite()
 
         om = OrganizationMember.objects.get(id=self.member.id)
         assert om.email is None
@@ -100,7 +104,8 @@ class ApiInviteHelperTest(TestCase):
             invite_context,
             None,
         )
-        helper.accept_invite()
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            helper.accept_invite()
 
         # Invite cannot be accepted without AuthIdentity if SSO is required
         om = OrganizationMember.objects.get(id=self.member.id)

+ 4 - 1
tests/sentry/discover/test_models.py

@@ -4,13 +4,16 @@ from django.db import IntegrityError, router, transaction
 from sentry.discover.models import DiscoverSavedQuery, DiscoverSavedQueryProject
 from sentry.models.user import User
 from sentry.testutils.cases import TestCase
+from sentry.testutils.silo import assume_test_silo_mode_of, region_silo_test
 
 
+@region_silo_test
 class DiscoverSavedQueryTest(TestCase):
     def setUp(self):
         super().setUp()
         self.org = self.create_organization()
-        self.user = User.objects.create(email="test@sentry.io")
+        with assume_test_silo_mode_of(User):
+            self.user = User.objects.create(email="test@sentry.io")
         self.project_ids = [
             self.create_project(organization=self.org).id,
             self.create_project(organization=self.org).id,

+ 15 - 10
tests/sentry/incidents/action_handlers/test_pagerduty.py

@@ -7,12 +7,15 @@ from sentry.incidents.action_handlers import PagerDutyActionHandler
 from sentry.incidents.logic import update_incident_status
 from sentry.incidents.models import AlertRuleTriggerAction, IncidentStatus, IncidentStatusMethod
 from sentry.integrations.pagerduty.utils import add_service
+from sentry.silo import SiloMode
 from sentry.testutils.helpers.datetime import freeze_time
+from sentry.testutils.silo import assume_test_silo_mode, region_silo_test
 from sentry.utils import json
 
 from . import FireTest
 
 
+@region_silo_test
 @freeze_time()
 class PagerDutyActionHandlerTest(FireTest):
     def setUp(self):
@@ -34,11 +37,12 @@ class PagerDutyActionHandlerTest(FireTest):
             metadata={"service": service},
         )
 
-        self.service = add_service(
-            org_integration,
-            service_name=service[0]["service_name"],
-            integration_key=service[0]["integration_key"],
-        )
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            self.service = add_service(
+                org_integration,
+                service_name=service[0]["service_name"],
+                integration_key=service[0]["integration_key"],
+            )
 
         self.action = self.create_alert_rule_trigger_action(
             target_identifier=self.service["id"],
@@ -120,11 +124,12 @@ class PagerDutyActionHandlerTest(FireTest):
             },
         ]
         org_integration = self.integration.organizationintegration_set.first()
-        add_service(
-            org_integration,
-            service_name=service[0]["service_name"],
-            integration_key=service[0]["integration_key"],
-        )
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            add_service(
+                org_integration,
+                service_name=service[0]["service_name"],
+                integration_key=service[0]["integration_key"],
+            )
         self.run_fire_test()
 
     def test_resolve_metric_alert(self):

+ 128 - 79
tests/sentry/incidents/test_logic.py

@@ -73,10 +73,12 @@ from sentry.models.actor import ActorTuple, get_actor_for_user, get_actor_id_for
 from sentry.models.integrations.organization_integration import OrganizationIntegration
 from sentry.services.hybrid_cloud.integration.serial import serialize_integration
 from sentry.shared_integrations.exceptions import ApiError, ApiRateLimitedError, ApiTimeoutError
+from sentry.silo import SiloMode
 from sentry.snuba.dataset import Dataset
 from sentry.snuba.models import QuerySubscription, SnubaQuery, SnubaQueryEventType
 from sentry.testutils.cases import BaseIncidentsTest, BaseMetricsTestCase, SnubaTestCase, TestCase
 from sentry.testutils.helpers.datetime import freeze_time
+from sentry.testutils.silo import assume_test_silo_mode, assume_test_silo_mode_of, region_silo_test
 from sentry.utils import json
 
 pytestmark = [pytest.mark.sentry_metrics]
@@ -1245,6 +1247,7 @@ class BaseAlertRuleTriggerActionTest:
         return create_alert_rule_trigger(self.alert_rule, "hello", 1000)
 
 
+@region_silo_test
 class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase):
     def test(self):
         type = AlertRuleTriggerAction.Type.EMAIL
@@ -1272,7 +1275,9 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
 
     @responses.activate
     def test_slack(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="2",
             provider="slack",
             metadata={
@@ -1280,7 +1285,6 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
                 "installation_type": "born_as_bot",
             },
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel"
@@ -1317,12 +1321,13 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
         assert action.integration_id == integration.id
 
     def test_slack_not_existing(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="1",
             provider="slack",
             metadata={"access_token": "xoxp-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"},
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel_that_doesnt_exist"
@@ -1338,7 +1343,9 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
     @responses.activate
     def test_slack_rate_limiting(self):
         """Should handle 429 from Slack on new Metric Alert creation"""
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="1",
             provider="slack",
             metadata={
@@ -1346,7 +1353,6 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
                 "installation_type": "born_as_bot",
             },
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel"
@@ -1377,8 +1383,9 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
 
     @patch("sentry.integrations.msteams.utils.get_channel_id", return_value="some_id")
     def test_msteams(self, mock_get_channel_id):
-        integration = self.create_provider_integration(external_id="1", provider="msteams")
-        integration.add_organization(self.organization, self.user)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, self.user, external_id="1", provider="msteams"
+        )
         type = AlertRuleTriggerAction.Type.MSTEAMS
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "some_channel"
@@ -1404,8 +1411,9 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
 
     @patch("sentry.integrations.msteams.utils.get_channel_id", return_value=None)
     def test_msteams_not_existing(self, mock_get_channel_id):
-        integration = self.create_provider_integration(external_id="1", provider="msteams")
-        integration.add_organization(self.organization, self.user)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, self.user, external_id="1", provider="msteams"
+        )
         type = AlertRuleTriggerAction.Type.MSTEAMS
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "some_channel"
@@ -1428,18 +1436,20 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
                 "service_name": "hellboi",
             }
         ]
-        integration = self.create_provider_integration(
+        integration, org_integration = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="pagerduty",
             name="Example PagerDuty",
             external_id="example-pagerduty",
             metadata={"services": services},
         )
-        org_integration = integration.add_organization(self.organization, self.user)
-        service = add_service(
-            org_integration,
-            service_name=services[0]["service_name"],
-            integration_key=services[0]["integration_key"],
-        )
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            service = add_service(
+                org_integration,
+                service_name=services[0]["service_name"],
+                integration_key=services[0]["integration_key"],
+            )
         type = AlertRuleTriggerAction.Type.PAGERDUTY
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         target_identifier = service["id"]
@@ -1458,12 +1468,13 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
         assert action.integration_id == integration.id
 
     def test_pagerduty_not_existing(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="pagerduty",
             name="Example PagerDuty",
             external_id="example-pagerduty",
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.PAGERDUTY
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         target_identifier = 1
@@ -1485,13 +1496,14 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
             "name": "Server Name",
             "type": ChannelType.GUILD_TEXT.value,
         }
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=guild_id,
             metadata=metadata,
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_id = "channel-id"
@@ -1521,13 +1533,14 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
             "name": "Server Name",
             "type": ChannelType.GUILD_TEXT.value,
         }
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             external_id=guild_id,
             metadata=metadata,
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_id = "channel-id"
@@ -1542,6 +1555,7 @@ class CreateAlertRuleTriggerActionTest(BaseAlertRuleTriggerActionTest, TestCase)
             )
 
 
+@region_silo_test
 class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
     @cached_property
     def action(self):
@@ -1565,7 +1579,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
 
     @responses.activate
     def test_slack(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="1",
             provider="slack",
             metadata={
@@ -1573,7 +1589,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
                 "installation_type": "born_as_bot",
             },
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel"
@@ -1610,12 +1625,13 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         assert action.integration_id == integration.id
 
     def test_slack_not_existing(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="1",
             provider="slack",
             metadata={"access_token": "xoxp-xxxxxxxxx-xxxxxxxxxx-xxxxxxxxxxxx"},
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel_that_doesnt_exist"
@@ -1631,7 +1647,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
     @responses.activate
     def test_slack_rate_limiting(self):
         """Should handle 429 from Slack on existing Metric Alert update"""
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             external_id="1",
             provider="slack",
             metadata={
@@ -1639,7 +1657,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
                 "installation_type": "born_as_bot",
             },
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.SLACK
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "#some_channel"
@@ -1670,8 +1687,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
 
     @patch("sentry.integrations.msteams.utils.get_channel_id", return_value="some_id")
     def test_msteams(self, mock_get_channel_id):
-        integration = self.create_provider_integration(external_id="1", provider="msteams")
-        integration.add_organization(self.organization, self.user)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, self.user, external_id="1", provider="msteams"
+        )
         type = AlertRuleTriggerAction.Type.MSTEAMS
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "some_channel"
@@ -1697,8 +1715,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
 
     @patch("sentry.integrations.msteams.utils.get_channel_id", return_value=None)
     def test_msteams_not_existing(self, mock_get_channel_id):
-        integration = self.create_provider_integration(external_id="1", provider="msteams")
-        integration.add_organization(self.organization, self.user)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, self.user, external_id="1", provider="msteams"
+        )
         type = AlertRuleTriggerAction.Type.MSTEAMS
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         channel_name = "some_channel"
@@ -1721,18 +1740,20 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
                 "service_name": "hellboi",
             }
         ]
-        integration = self.create_provider_integration(
+        integration, org_integration = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="pagerduty",
             name="Example PagerDuty",
             external_id="example-pagerduty",
             metadata={"services": services},
         )
-        org_integration = integration.add_organization(self.organization, self.user)
-        service = add_service(
-            org_integration,
-            service_name=services[0]["service_name"],
-            integration_key=services[0]["integration_key"],
-        )
+        with assume_test_silo_mode(SiloMode.CONTROL):
+            service = add_service(
+                org_integration,
+                service_name=services[0]["service_name"],
+                integration_key=services[0]["integration_key"],
+            )
         type = AlertRuleTriggerAction.Type.PAGERDUTY
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         target_identifier = service["id"]
@@ -1752,12 +1773,13 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         assert action.integration_id == integration.id
 
     def test_pagerduty_not_existing(self):
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="pagerduty",
             name="Example PagerDuty",
             external_id="example-pagerduty",
         )
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.PAGERDUTY
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         target_identifier = 1
@@ -1779,15 +1801,17 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             "domain_name": "test-app.app.opsgenie.com",
         }
         team = {"id": "123-id", "team": "cool-team", "integration_key": "1234-5678"}
-        integration = self.create_provider_integration(
-            provider="opsgenie", name="test-app", external_id="test-app", metadata=metadata
-        )
-        integration.add_organization(self.organization, self.user)
-        org_integration = OrganizationIntegration.objects.get(
-            organization_id=self.organization.id, integration_id=integration.id
+        integration, org_integration = self.create_provider_integration_for(
+            self.organization,
+            self.user,
+            provider="opsgenie",
+            name="test-app",
+            external_id="test-app",
+            metadata=metadata,
         )
-        org_integration.config = {"team_table": [team]}
-        org_integration.save()
+        with assume_test_silo_mode_of(OrganizationIntegration):
+            org_integration.config = {"team_table": [team]}
+            org_integration.save()
 
         resp_data = {
             "result": "Integration [sentry] is valid",
@@ -1823,8 +1847,13 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             "base_url": "https://api.opsgenie.com/",
             "domain_name": "test-app.app.opsgenie.com",
         }
-        integration = self.create_provider_integration(
-            provider="opsgenie", name="test-app", external_id="test-app", metadata=metadata
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
+            provider="opsgenie",
+            name="test-app",
+            external_id="test-app",
+            metadata=metadata,
         )
 
         type = AlertRuleTriggerAction.Type.OPSGENIE
@@ -1847,7 +1876,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -1858,7 +1889,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(
@@ -1892,7 +1922,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -1903,7 +1935,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(method=responses.GET, url=f"{base_url}/channels/{channel_id}", status=404)
@@ -1924,7 +1955,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -1935,7 +1968,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(
@@ -1975,7 +2007,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -1986,7 +2020,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(
@@ -2014,7 +2047,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -2025,7 +2060,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(
@@ -2054,7 +2088,9 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
         guild_id = "example-discord-server"
         guild_name = "Server Name"
 
-        integration = self.create_provider_integration(
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="discord",
             name="Example Discord",
             external_id=f"{guild_id}",
@@ -2065,7 +2101,6 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             },
         )
 
-        integration.add_organization(self.organization, self.user)
         type = AlertRuleTriggerAction.Type.DISCORD
         target_type = AlertRuleTriggerAction.TargetType.SPECIFIC
         responses.add(
@@ -2088,6 +2123,7 @@ class UpdateAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             )
 
 
+@region_silo_test
 class DeleteAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
     @cached_property
     def action(self):
@@ -2105,6 +2141,7 @@ class DeleteAlertRuleTriggerAction(BaseAlertRuleTriggerActionTest, TestCase):
             AlertRuleTriggerAction.objects.get(id=action_id)
 
 
+@region_silo_test
 class GetActionsForTriggerTest(BaseAlertRuleTriggerActionTest, TestCase):
     def test(self):
         assert list(get_actions_for_trigger(self.trigger)) == []
@@ -2117,42 +2154,52 @@ class GetActionsForTriggerTest(BaseAlertRuleTriggerActionTest, TestCase):
         assert list(get_actions_for_trigger(self.trigger)) == [action]
 
 
+@region_silo_test
 class GetAvailableActionIntegrationsForOrgTest(TestCase):
     def test_none(self):
         assert list(get_available_action_integrations_for_org(self.organization)) == []
 
     def test_unregistered(self):
-        integration = self.create_provider_integration(external_id="1", provider="something_random")
-        integration.add_organization(self.organization)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, user=None, external_id="1", provider="something_random"
+        )
         assert list(get_available_action_integrations_for_org(self.organization)) == []
 
     def test_registered(self):
-        integration = self.create_provider_integration(external_id="1", provider="slack")
-        integration.add_organization(self.organization)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, user=None, external_id="1", provider="slack"
+        )
         assert list(get_available_action_integrations_for_org(self.organization)) == [
             serialize_integration(integration)
         ]
 
     def test_mixed(self):
-        integration = self.create_provider_integration(external_id="1", provider="slack")
-        integration.add_organization(self.organization)
-        other_integration = self.create_provider_integration(external_id="12345", provider="random")
-        other_integration.add_organization(self.organization)
+        integration, _ = self.create_provider_integration_for(
+            self.organization, user=None, external_id="1", provider="slack"
+        )
+        other_integration, _ = self.create_provider_integration_for(
+            self.organization, user=None, external_id="12345", provider="random"
+        )
         assert list(get_available_action_integrations_for_org(self.organization)) == [
             serialize_integration(integration)
         ]
 
     def test_disabled_integration(self):
-        integration = self.create_provider_integration(
-            external_id="1", provider="slack", status=ObjectStatus.DISABLED
+        integration, _ = self.create_provider_integration_for(
+            self.organization,
+            user=None,
+            external_id="1",
+            provider="slack",
+            status=ObjectStatus.DISABLED,
         )
-        integration.add_organization(self.organization)
         assert list(get_available_action_integrations_for_org(self.organization)) == []
 
     def test_disabled_org_integration(self):
-        integration = self.create_provider_integration(external_id="1", provider="slack")
-        org_integration = integration.add_organization(self.organization)
-        org_integration.update(status=ObjectStatus.DISABLED)
+        integration, org_integration = self.create_provider_integration_for(
+            self.organization, user=None, external_id="1", provider="slack"
+        )
+        with assume_test_silo_mode_of(OrganizationIntegration):
+            org_integration.update(status=ObjectStatus.DISABLED)
         assert list(get_available_action_integrations_for_org(self.organization)) == []
 
 
@@ -2269,7 +2316,9 @@ class TestDeduplicateTriggerActions(TestCase):
         super().setUp()
         self.alert_rule = self.create_alert_rule()
         self.incident = self.create_incident(alert_rule=self.alert_rule)
-        self.integration = self.create_provider_integration(
+        self.integration, _ = self.create_provider_integration_for(
+            self.organization,
+            self.user,
             provider="slack",
             name="Team A",
             external_id="TXXXXXXX1",

+ 5 - 2
tests/sentry/manager/test_group_manager.py

@@ -1,11 +1,13 @@
 from sentry.models.group import Group
 from sentry.services.hybrid_cloud.integration.serial import serialize_integration
 from sentry.testutils.cases import TestCase
+from sentry.testutils.silo import region_silo_test
 from sentry.testutils.skips import requires_snuba
 
 pytestmark = requires_snuba
 
 
+@region_silo_test
 class SentryManagerTest(TestCase):
     def test_valid_only_message(self):
         proj = self.create_project()
@@ -17,13 +19,14 @@ class SentryManagerTest(TestCase):
     def test_get_groups_by_external_issue(self):
         external_issue_key = "api-123"
         group = self.create_group()
-        integration_model = self.create_provider_integration(
+        integration_model, _ = self.create_provider_integration_for(
+            group.organization,
+            self.user,
             provider="jira",
             external_id="some_id",
             name="Hello world",
             metadata={"base_url": "https://example.com"},
         )
-        integration_model.add_organization(group.organization, self.user)
         integration = serialize_integration(integration=integration_model)
         self.create_integration_external_issue(
             group=group, integration=integration, key=external_issue_key

+ 2 - 2
tests/sentry/models/test_avatar.py

@@ -4,7 +4,7 @@ from sentry.models.avatars.user_avatar import UserAvatar
 from sentry.models.files.control_file import ControlFile
 from sentry.models.files.file import File
 from sentry.testutils.cases import TestCase
-from sentry.testutils.silo import control_silo_test, region_silo_test
+from sentry.testutils.silo import control_silo_test, no_silo_test, region_silo_test
 
 
 @control_silo_test
@@ -28,7 +28,7 @@ class UserAvatarTestCase(TestCase):
             assert UserAvatar.objects.get(id=avatar.id).get_file() is None
 
 
-# Not siloed, this logic will be removed after data is moved.
+@no_silo_test  # Not siloed, this logic will be removed after data is moved.
 class AvatarMigrationTestCase(TestCase):
     def test_transition_to_control(self):
         user = self.create_user("foo@example.com")

+ 22 - 12
tests/sentry/tasks/test_auto_enable_codecov.py

@@ -9,8 +9,11 @@ from sentry.tasks.auto_enable_codecov import enable_for_org
 from sentry.testutils.cases import TestCase
 from sentry.testutils.helpers import apply_feature_flag_on_cls
 from sentry.testutils.helpers.features import with_feature
+from sentry.testutils.outbox import outbox_runner
+from sentry.testutils.silo import assume_test_silo_mode_of, region_silo_test
 
 
+@region_silo_test
 @apply_feature_flag_on_cls("organizations:auto-enable-codecov")
 class AutoEnableCodecovTest(TestCase):
     def setUp(self):
@@ -40,19 +43,22 @@ class AutoEnableCodecovTest(TestCase):
     )
     @with_feature("organizations:codecov-integration")
     def test_has_codecov_integration(self, mock_get_repositories):
-        AuditLogEntry.objects.all().delete()
+        with assume_test_silo_mode_of(AuditLogEntry):
+            AuditLogEntry.objects.all().delete()
         assert not self.organization.flags.codecov_access.is_set
-        enable_for_org(self.organization.id)
+        with outbox_runner():
+            enable_for_org(self.organization.id)
 
         assert mock_get_repositories.call_count == 1
 
         org = Organization.objects.get(id=self.organization.id)
         assert org.flags.codecov_access
 
-        audit = AuditLogEntry.objects.filter(
-            organization_id=org.id, event=audit_log.get_event_id("ORG_EDIT")
-        )
-        assert audit.exists()
+        with assume_test_silo_mode_of(AuditLogEntry):
+            audit = AuditLogEntry.objects.filter(
+                organization_id=org.id, event=audit_log.get_event_id("ORG_EDIT")
+            )
+            assert audit.exists()
 
     @responses.activate
     @patch(
@@ -62,7 +68,8 @@ class AutoEnableCodecovTest(TestCase):
     @with_feature("organizations:codecov-integration")
     def test_no_codecov_integration(self, mock_get_repositories):
         assert not self.organization.flags.codecov_access.is_set
-        enable_for_org(self.organization.id)
+        with outbox_runner():
+            enable_for_org(self.organization.id)
 
         assert mock_get_repositories.call_count == 1
 
@@ -71,14 +78,17 @@ class AutoEnableCodecovTest(TestCase):
 
     @responses.activate
     def test_disables_codecov(self):
-        AuditLogEntry.objects.all().delete()
+        with assume_test_silo_mode_of(AuditLogEntry):
+            AuditLogEntry.objects.all().delete()
         self.organization.flags.codecov_access = True
         self.organization.save()
 
-        enable_for_org(self.organization.id)
+        with outbox_runner():
+            enable_for_org(self.organization.id)
 
         org = Organization.objects.get(id=self.organization.id)
         assert not org.flags.codecov_access.is_set
-        audit_log = AuditLogEntry.objects.filter(organization_id=org.id)
-        assert len(audit_log) == 1
-        assert audit_log.first().data == {"codecov_access": "to False"}
+        with assume_test_silo_mode_of(AuditLogEntry):
+            audit_log = AuditLogEntry.objects.filter(organization_id=org.id)
+            assert len(audit_log) == 1
+            assert audit_log.first().data == {"codecov_access": "to False"}

+ 9 - 14
tests/sentry/web/test_client_config.py

@@ -23,7 +23,7 @@ from sentry.testutils.requests import (
     make_user_request_from_org,
     request_factory,
 )
-from sentry.testutils.silo import control_silo_test, create_test_regions
+from sentry.testutils.silo import control_silo_test, create_test_regions, no_silo_test
 from sentry.types import region
 from sentry.web.client_config import get_client_config
 
@@ -58,6 +58,7 @@ def clear_env_request():
     env.clear()
 
 
+@no_silo_test
 @pytest.mark.parametrize(
     "request_factory",
     [
@@ -85,19 +86,13 @@ def test_client_config_in_silo_modes(request_factory: RequestFactory):
     base_line["links"].pop("regionUrl")
     cache.clear()
 
-    with override_settings(SILO_MODE=SiloMode.REGION):
-        result = get_client_config(request)
-        result.pop("regions")
-        result["links"].pop("regionUrl")
-        assert result == base_line
-        cache.clear()
-
-    with override_settings(SILO_MODE=SiloMode.CONTROL):
-        result = get_client_config(request)
-        result.pop("regions")
-        result["links"].pop("regionUrl")
-        assert result == base_line
-        cache.clear()
+    for silo_mode in SiloMode:
+        with override_settings(SILO_MODE=silo_mode):
+            result = get_client_config(request)
+            result.pop("regions")
+            result["links"].pop("regionUrl")
+            assert result == base_line
+            cache.clear()
 
 
 @django_db_all(transaction=True)

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