Browse Source

chore(hybridcloud): Fewer mocks in plugin/vsts/vercel/msteams parser tests (#62860)

Same as https://github.com/getsentry/sentry/pull/62846, for the rest of
the integrations.
Leander Rodrigues 1 year ago
parent
commit
62613419c2

+ 4 - 13
tests/sentry/middleware/integrations/parsers/test_discord.py

@@ -16,17 +16,12 @@ from sentry.models.outbox import ControlOutbox
 from sentry.silo.base import SiloMode
 from sentry.testutils.cases import APITestCase, TestCase
 from sentry.testutils.outbox import assert_no_webhook_outboxes
-from sentry.testutils.region import override_regions
-from sentry.testutils.silo import control_silo_test
-from sentry.types.region import Region, RegionCategory
+from sentry.testutils.silo import control_silo_test, create_test_regions
 from sentry.utils import json
 from sentry.utils.signing import sign
 
-region = Region("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
-region_config = (region,)
 
-
-@control_silo_test
+@control_silo_test(regions=create_test_regions("us"))
 class DiscordRequestParserTest(TestCase):
     factory = RequestFactory()
     discord_id = "808"
@@ -34,7 +29,6 @@ class DiscordRequestParserTest(TestCase):
     def get_response(self, request: HttpRequest) -> HttpResponse:
         return HttpResponse(status=200, content="passthrough")
 
-    @override_regions(region_config)
     def setUp(self):
         super().setUp()
         self.integration = self.create_integration(
@@ -101,7 +95,6 @@ class DiscordRequestParserTest(TestCase):
         assert len(responses.calls) == 0
 
     @responses.activate
-    @override_regions(region_config)
     @patch("sentry.integrations.discord.requests.base.verify_signature", return_value=None)
     def test_interactions_endpoint_routing_command(self, mock_verify_signature):
         data = {
@@ -115,7 +108,7 @@ class DiscordRequestParserTest(TestCase):
 
         responses.add(
             responses.POST,
-            "https://us.testserver/extensions/discord/interactions/",
+            "http://us.testserver/extensions/discord/interactions/",
             status=202,
             body=b"region_response",
         )
@@ -145,7 +138,6 @@ class DiscordRequestParserTest(TestCase):
         assert_no_webhook_outboxes()
 
     @responses.activate
-    @override_regions(region_config)
     @patch("sentry.integrations.discord.requests.base.verify_signature", return_value=None)
     def test_interactions_endpoint_routing_message_component(self, mock_verify_signature):
         data = {
@@ -158,7 +150,7 @@ class DiscordRequestParserTest(TestCase):
 
         responses.add(
             responses.POST,
-            "https://us.testserver/extensions/discord/interactions/",
+            "http://us.testserver/extensions/discord/interactions/",
             status=201,
             body=b"region_response",
         )
@@ -195,7 +187,6 @@ class DiscordRequestParserTest(TestCase):
             assert_no_webhook_outboxes()
 
     @responses.activate
-    @override_regions(region_config)
     @patch("sentry.middleware.integrations.parsers.discord.convert_to_async_discord_response")
     @patch("sentry.integrations.discord.requests.base.verify_signature", return_value=None)
     def test_triggers_async_response(self, mock_verify_signature, mock_discord_task):

+ 50 - 76
tests/sentry/middleware/integrations/parsers/test_msteams.py

@@ -1,21 +1,17 @@
 from copy import deepcopy
-from unittest import mock
-from unittest.mock import MagicMock
 
-from django.http import HttpResponse
-from django.test import RequestFactory, override_settings
+import responses
+from django.http import HttpRequest, HttpResponse
+from django.test import RequestFactory
 from django.urls import reverse
 
 from sentry.integrations.msteams.utils import ACTION_TYPE
 from sentry.middleware.integrations.classifications import IntegrationClassification
 from sentry.middleware.integrations.parsers.msteams import MsTeamsRequestParser
-from sentry.models.integrations.integration import Integration
-from sentry.models.outbox import ControlOutbox, WebhookProviderIdentifier
-from sentry.silo.base import SiloMode
+from sentry.models.outbox import WebhookProviderIdentifier
 from sentry.testutils.cases import TestCase
-from sentry.testutils.outbox import assert_webhook_outboxes
-from sentry.testutils.silo import control_silo_test
-from sentry.types.region import Region, RegionCategory
+from sentry.testutils.outbox import assert_no_webhook_outboxes, assert_webhook_outboxes
+from sentry.testutils.silo import control_silo_test, create_test_regions
 from tests.sentry.integrations.msteams.test_helpers import (
     EXAMPLE_MENTIONED,
     EXAMPLE_PERSONAL_MEMBER_ADDED,
@@ -27,15 +23,22 @@ from tests.sentry.integrations.msteams.test_helpers import (
 )
 
 
-@control_silo_test
+@control_silo_test(regions=create_test_regions("us"))
 class MsTeamsRequestParserTest(TestCase):
-    get_response = MagicMock(return_value=HttpResponse(content=b"no-error", status=200))
     factory = RequestFactory()
     path = f"{IntegrationClassification.integration_prefix}msteams/webhook/"
-    region = Region("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
 
     def setUp(self):
         super().setUp()
+        team_id = "19:8d46058cda57449380517cc374727f2a@thread.tacv2"
+        self.user = self.create_user()
+        self.organization = self.create_organization(owner=self.user)
+        self.integration = self.create_integration(
+            organization=self.organization, external_id=team_id, provider="msteams"
+        )
+
+    def get_response(self, request: HttpRequest) -> HttpResponse:
+        return HttpResponse(status=200, content="passthrough")
 
     def generate_card_response(self, integration_id: int):
         return {
@@ -58,8 +61,8 @@ class MsTeamsRequestParserTest(TestCase):
             "replyToId": "replyToId",
         }
 
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
-    def test_routing_properly(self):
+    @responses.activate
+    def test_routing_events(self):
         # No regions identified
         request = self.factory.post(
             self.path,
@@ -69,32 +72,33 @@ class MsTeamsRequestParserTest(TestCase):
         )
         parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
 
-        with mock.patch.object(
-            parser, "get_response_from_control_silo"
-        ) as get_response_from_control_silo, mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[]
-        ):
-            parser.get_response()
-            assert get_response_from_control_silo.called
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 200
+        assert response.content == b"passthrough"
+        assert len(responses.calls) == 0
+        assert_no_webhook_outboxes()
 
         # Regions found
         request = self.factory.post(
             self.path,
-            data=self.generate_card_response(123),
+            data=self.generate_card_response(self.integration.id),
             HTTP_AUTHORIZATION=f"Bearer {TOKEN}",
             content_type="application/json",
         )
         parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 202
+        assert len(responses.calls) == 0
+        assert_webhook_outboxes(
+            factory_request=request,
+            webhook_identifier=WebhookProviderIdentifier.MSTEAMS,
+            region_names=["us"],
+        )
 
-        with mock.patch.object(
-            parser, "get_response_from_outbox_creation"
-        ) as get_response_from_outbox_creation, mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[self.region]
-        ):
-            parser.get_response()
-            assert get_response_from_outbox_creation.called
-
-        # Non-webhook urls
+    @responses.activate
+    def test_routing_control_paths(self):
         requests = [
             self.factory.get(
                 reverse("sentry-integration-msteams-configure"),
@@ -114,44 +118,15 @@ class MsTeamsRequestParserTest(TestCase):
         ]
         for request in requests:
             parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
+            response = parser.get_response()
+            assert isinstance(response, HttpResponse)
+            assert response.status_code == 200
+            assert response.content == b"passthrough"
+            assert len(responses.calls) == 0
+            assert_no_webhook_outboxes()
 
-            with mock.patch.object(
-                parser, "get_response_from_outbox_creation"
-            ) as get_response_from_outbox_creation, mock.patch.object(
-                parser, "get_response_from_control_silo"
-            ) as get_response_from_control_silo:
-                parser.get_response()
-                assert get_response_from_control_silo.called
-                assert not get_response_from_outbox_creation.called
-
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
-    def test_webhook_outbox_creation(self):
-        request = self.factory.post(
-            self.path,
-            data=self.generate_card_response(123),
-            HTTP_AUTHORIZATION=f"Bearer {TOKEN}",
-            content_type="application/json",
-        )
-        parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
-
-        # ControlOutbox creation
-        assert ControlOutbox.objects.count() == 0
-        with mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[self.region]
-        ):
-            parser.get_response()
-            assert_webhook_outboxes(
-                factory_request=request,
-                webhook_identifier=WebhookProviderIdentifier.MSTEAMS,
-                region_names=[self.region.name],
-            )
-
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
     def test_get_integration_from_request(self):
-        team_id = "19:8d46058cda57449380517cc374727f2a@thread.tacv2"
-        expected_integration = Integration.objects.create(external_id=team_id, provider="msteams")
-
-        CARD_ACTION_RESPONSE = self.generate_card_response(expected_integration.id)
+        CARD_ACTION_RESPONSE = self.generate_card_response(self.integration.id)
 
         region_silo_payloads = [
             # Integration inferred from channelData.team.id
@@ -171,7 +146,7 @@ class MsTeamsRequestParserTest(TestCase):
             )
             parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
             integration = parser.get_integration_from_request()
-            assert integration == expected_integration
+            assert integration == self.integration
 
         help_command = deepcopy(EXAMPLE_UNLINK_COMMAND)
         help_command["text"] = "Help"
@@ -187,7 +162,6 @@ class MsTeamsRequestParserTest(TestCase):
             integration = parser.get_integration_from_request()
             assert integration is None
 
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
     def test_handle_control_silo_payloads(self):
         help_command = deepcopy(EXAMPLE_UNLINK_COMMAND)
         help_command["text"] = "Help"
@@ -200,9 +174,9 @@ class MsTeamsRequestParserTest(TestCase):
                 HTTP_AUTHORIZATION=f"Bearer {TOKEN}",
             )
             parser = MsTeamsRequestParser(request=request, response_handler=self.get_response)
-
-            with mock.patch.object(
-                parser, "get_response_from_control_silo"
-            ) as get_response_from_control_silo:
-                parser.get_response()
-                assert get_response_from_control_silo.called
+            response = parser.get_response()
+            assert isinstance(response, HttpResponse)
+            assert response.status_code == 200
+            assert response.content == b"passthrough"
+            assert len(responses.calls) == 0
+            assert_no_webhook_outboxes()

+ 15 - 11
tests/sentry/middleware/integrations/parsers/test_plugin.py

@@ -1,6 +1,5 @@
-from unittest import mock
-from unittest.mock import MagicMock
-
+import responses
+from django.http import HttpRequest, HttpResponse
 from django.test import RequestFactory
 from django.urls import reverse
 
@@ -8,15 +7,18 @@ from sentry.middleware.integrations.parsers.plugin import PluginRequestParser
 from sentry.models.organizationmapping import OrganizationMapping
 from sentry.models.outbox import ControlOutbox, WebhookProviderIdentifier
 from sentry.testutils.cases import TestCase
-from sentry.testutils.outbox import assert_webhook_outboxes
+from sentry.testutils.outbox import assert_no_webhook_outboxes, assert_webhook_outboxes
 from sentry.testutils.silo import control_silo_test, create_test_regions
 
 
-@control_silo_test(regions=create_test_regions("us"), include_monolith_run=True)
+@control_silo_test(regions=create_test_regions("us"))
 class PluginRequestParserTest(TestCase):
-    get_response = MagicMock()
     factory = RequestFactory()
 
+    def get_response(self, request: HttpRequest) -> HttpResponse:
+        return HttpResponse(status=200, content="passthrough")
+
+    @responses.activate
     def test_routing_webhooks_no_region(self):
         routes = [
             reverse("sentry-plugins-github-webhook", args=[self.organization.id]),
@@ -29,11 +31,13 @@ class PluginRequestParserTest(TestCase):
         for route in routes:
             request = self.factory.post(route)
             parser = PluginRequestParser(request=request, response_handler=self.get_response)
-            with mock.patch.object(
-                parser, "get_response_from_control_silo"
-            ) as get_response_from_control_silo:
-                parser.get_response()
-                assert get_response_from_control_silo.called
+
+            response = parser.get_response()
+            assert isinstance(response, HttpResponse)
+            assert response.status_code == 200
+            assert response.content == b"passthrough"
+            assert len(responses.calls) == 0
+            assert_no_webhook_outboxes()
 
     def test_routing_webhooks_with_region(self):
         routes = [

+ 4 - 12
tests/sentry/middleware/integrations/parsers/test_slack.py

@@ -15,22 +15,16 @@ from sentry.middleware.integrations.parsers.slack import SlackRequestParser
 from sentry.models.outbox import ControlOutbox
 from sentry.testutils.cases import TestCase
 from sentry.testutils.outbox import assert_no_webhook_outboxes
-from sentry.testutils.region import override_regions
-from sentry.testutils.silo import control_silo_test
-from sentry.types.region import Region, RegionCategory
+from sentry.testutils.silo import control_silo_test, create_test_regions
 from sentry.utils import json
 from sentry.utils.signing import sign
 
-region = Region("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
-region_config = (region,)
 
-
-@control_silo_test
+@control_silo_test(regions=create_test_regions("us"))
 class SlackRequestParserTest(TestCase):
     factory = RequestFactory()
     timestamp = "123123123"
 
-    @override_regions(region_config)
     def setUp(self):
         self.user = self.create_user()
         self.organization = self.create_organization(owner=self.user)
@@ -42,7 +36,6 @@ class SlackRequestParserTest(TestCase):
         return HttpResponse(status=200, content="passthrough")
 
     @responses.activate
-    @override_regions(region_config)
     def test_webhook(self):
         # Retrieve the correct integration
         data = urlencode({"team_id": self.integration.external_id}).encode("utf-8")
@@ -61,7 +54,7 @@ class SlackRequestParserTest(TestCase):
         # Returns response from region
         responses.add(
             responses.POST,
-            "https://us.testserver/extensions/slack/commands/",
+            "http://us.testserver/extensions/slack/commands/",
             status=201,
             body=b"region_response",
         )
@@ -75,7 +68,7 @@ class SlackRequestParserTest(TestCase):
         # ...even if it returns an error
         responses.add(
             responses.POST,
-            "https://us.testserver/extensions/slack/commands/",
+            "http://us.testserver/extensions/slack/commands/",
             status=401,
             body=b"error_response",
         )
@@ -108,7 +101,6 @@ class SlackRequestParserTest(TestCase):
         assert len(responses.calls) == 0
         assert_no_webhook_outboxes()
 
-    @override_regions(region_config)
     @patch(
         "sentry.integrations.slack.requests.base.SlackRequest._check_signing_secret",
         return_value=True,

+ 14 - 18
tests/sentry/middleware/integrations/parsers/test_vercel.py

@@ -1,17 +1,16 @@
-from unittest.mock import MagicMock, patch
-
-from django.http import HttpResponse
+import responses
+from django.http import HttpRequest, HttpResponse
 from django.test import RequestFactory
 from django.urls import reverse
 
 from sentry.middleware.integrations.parsers.vercel import VercelRequestParser
 from sentry.testutils.cases import TestCase
+from sentry.testutils.outbox import assert_no_webhook_outboxes
 from sentry.testutils.silo import control_silo_test
 
 
 @control_silo_test
 class VercelRequestParserTest(TestCase):
-    get_response = MagicMock()
     factory = RequestFactory()
     vercel_dummy_requests = [
         factory.get(reverse("sentry-extensions-vercel-configure")),
@@ -19,20 +18,17 @@ class VercelRequestParserTest(TestCase):
         factory.post(reverse("sentry-extensions-vercel-webhook"), data={}),
     ]
 
+    def get_response(self, request: HttpRequest) -> HttpResponse:
+        return HttpResponse(status=200, content="passthrough")
+
+    @responses.activate
     def test_routing_all_to_control(self):
         for request in self.vercel_dummy_requests:
             parser = VercelRequestParser(request=request, response_handler=self.get_response)
-
-            expected_response = HttpResponse({"ok": True})
-            with patch.object(
-                parser, "get_response_from_outbox_creation"
-            ) as mock_response_from_outbox, patch.object(
-                parser, "get_responses_from_region_silos"
-            ) as mock_response_from_region, patch.object(
-                parser, "get_response_from_control_silo", return_value=expected_response
-            ) as mock_response_from_control:
-                actual_response = parser.get_response()
-                assert not mock_response_from_outbox.called
-                assert not mock_response_from_region.called
-                assert mock_response_from_control.called
-                assert actual_response == expected_response
+            assert parser.get_integration_from_request() is None
+            response = parser.get_response()
+            assert isinstance(response, HttpResponse)
+            assert response.status_code == 200
+            assert response.content == b"passthrough"
+            assert len(responses.calls) == 0
+            assert_no_webhook_outboxes()

+ 88 - 89
tests/sentry/middleware/integrations/parsers/test_vsts.py

@@ -1,108 +1,110 @@
 from copy import deepcopy
-from unittest import mock
-from unittest.mock import MagicMock
 
-from django.http import HttpResponse
-from django.test import RequestFactory, override_settings
+import responses
+from django.http import HttpRequest, HttpResponse
+from django.test import RequestFactory
 from django.urls import reverse
 
 from fixtures.vsts import WORK_ITEM_UNASSIGNED, WORK_ITEM_UPDATED, WORK_ITEM_UPDATED_STATUS
 from sentry.middleware.integrations.classifications import IntegrationClassification
 from sentry.middleware.integrations.parsers.vsts import VstsRequestParser
-from sentry.models.integrations.integration import Integration
-from sentry.models.outbox import ControlOutbox, WebhookProviderIdentifier
-from sentry.silo.base import SiloMode
+from sentry.models.outbox import WebhookProviderIdentifier
 from sentry.testutils.cases import TestCase
-from sentry.testutils.outbox import assert_webhook_outboxes
-from sentry.testutils.silo import control_silo_test
-from sentry.types.region import Region, RegionCategory
+from sentry.testutils.outbox import assert_no_webhook_outboxes, assert_webhook_outboxes
+from sentry.testutils.silo import control_silo_test, create_test_regions
 
 
-@control_silo_test
+@control_silo_test(regions=create_test_regions("us"))
 class VstsRequestParserTest(TestCase):
-    get_response = MagicMock(return_value=HttpResponse(content=b"no-error", status=200))
     factory = RequestFactory()
+    shared_secret = "1234567890"
     path = f"{IntegrationClassification.integration_prefix}vsts/issue-updated/"
-    region = Region("us", 1, "https://us.testserver", RegionCategory.MULTI_TENANT)
 
     def setUp(self):
         super().setUp()
-        self.shared_secret = "1234567890"
-
-    def set_workitem_state(self, old_value, new_value):
-        work_item = deepcopy(WORK_ITEM_UPDATED_STATUS)
-        state = work_item["resource"]["fields"]["System.State"]
-
-        if old_value is None:
-            del state["oldValue"]
-        else:
-            state["oldValue"] = old_value
-        state["newValue"] = new_value
+        self.user = self.create_user()
+        self.organization = self.create_organization(owner=self.user)
+        account_id = WORK_ITEM_UPDATED["resourceContainers"]["collection"]["id"]
+        self.integration = self.create_integration(
+            organization=self.organization,
+            external_id=account_id,
+            provider="vsts",
+            name="vsts_name",
+            metadata={
+                "domain_name": "https://instance.visualstudio.com/",
+                "subscription": {"id": 1234, "secret": self.shared_secret},
+            },
+        )
 
-        return work_item
+    def get_response(self, request: HttpRequest) -> HttpResponse:
+        return HttpResponse(status=200, content="passthrough")
 
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
-    def test_routing_properly(self):
+    @responses.activate
+    def test_routing_work_item_webhook(self):
+        # No integration found for request...
+        data = deepcopy(WORK_ITEM_UPDATED)
+        data["resourceContainers"]["collection"]["id"] = "non-existant"
         request = self.factory.post(
             self.path,
-            json=WORK_ITEM_UPDATED,
+            data=data,
+            content_type="application/json",
             HTTP_SHARED_SECRET=self.shared_secret,
         )
         parser = VstsRequestParser(request=request, response_handler=self.get_response)
 
-        # No regions identified
-        with mock.patch.object(
-            parser, "get_response_from_control_silo"
-        ) as get_response_from_control_silo, mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[]
-        ):
-            parser.get_response()
-            assert get_response_from_control_silo.called
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 200
+        assert response.content == b"passthrough"
+        assert len(responses.calls) == 0
+        assert_no_webhook_outboxes()
 
         # Regions found
-        with mock.patch.object(
-            parser, "get_response_from_outbox_creation"
-        ) as get_response_from_outbox_creation, mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[self.region]
-        ):
-            parser.get_response()
-            assert get_response_from_outbox_creation.called
-
-        # Non-webhook urls
-        with mock.patch.object(
-            parser, "get_response_from_outbox_creation"
-        ) as get_response_from_outbox_creation, mock.patch.object(
-            parser, "get_response_from_control_silo"
-        ) as get_response_from_control_silo:
-            parser.request = self.factory.get(
-                reverse("vsts-extension-configuration"), data={"targetId": "1", "targetName": "foo"}
-            )
-            parser.get_response()
-            assert get_response_from_control_silo.called
-            assert not get_response_from_outbox_creation.called
-
-            parser.request = self.factory.get(
-                reverse(
-                    "sentry-extensions-vsts-search",
-                    kwargs={"organization_slug": "albertos-apples", "integration_id": 1234},
-                ),
-            )
-            parser.get_response()
-            assert get_response_from_control_silo.called
+        request = self.factory.post(
+            self.path,
+            data=WORK_ITEM_UPDATED,
+            content_type="application/json",
+            HTTP_SHARED_SECRET=self.shared_secret,
+        )
+        parser = VstsRequestParser(request=request, response_handler=self.get_response)
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 202
+        assert_webhook_outboxes(
+            factory_request=request,
+            webhook_identifier=WebhookProviderIdentifier.VSTS,
+            region_names=["us"],
+        )
 
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
-    def test_get_integration_from_request(self):
-        account_id = "80ded3e8-3cd3-43b1-9f96-52032624aa3a"
-        expected_integration = Integration.objects.create(
-            provider="vsts",
-            external_id=account_id,
-            name="vsts_name",
-            metadata={
-                "domain_name": "https://instance.visualstudio.com/",
-                "subscription": {"id": 1234, "secret": self.shared_secret},
-            },
+    @responses.activate
+    def test_routing_control_paths(self):
+        config_request = self.factory.get(
+            reverse("vsts-extension-configuration"),
+            data={"targetId": "1", "targetName": "foo"},
+        )
+        parser = VstsRequestParser(request=config_request, response_handler=self.get_response)
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 200
+        assert response.content == b"passthrough"
+        assert len(responses.calls) == 0
+        assert_no_webhook_outboxes()
+
+        search_request = self.factory.get(
+            reverse(
+                "sentry-extensions-vsts-search",
+                kwargs={"organization_slug": "albertos-apples", "integration_id": 1234},
+            ),
         )
+        parser = VstsRequestParser(request=search_request, response_handler=self.get_response)
+        response = parser.get_response()
+        assert isinstance(response, HttpResponse)
+        assert response.status_code == 200
+        assert response.content == b"passthrough"
+        assert len(responses.calls) == 0
+        assert_no_webhook_outboxes()
 
+    def test_get_integration_from_request(self):
         region_silo_payloads = [WORK_ITEM_UNASSIGNED, WORK_ITEM_UPDATED, WORK_ITEM_UPDATED_STATUS]
 
         for payload in region_silo_payloads:
@@ -114,7 +116,7 @@ class VstsRequestParserTest(TestCase):
             )
             parser = VstsRequestParser(request=request, response_handler=self.get_response)
             integration = parser.get_integration_from_request()
-            assert integration == expected_integration
+            assert integration == self.integration
 
         # Invalid payload or content-type
         request = self.factory.post(
@@ -127,22 +129,19 @@ class VstsRequestParserTest(TestCase):
         integration = parser.get_integration_from_request()
         assert integration is None
 
-    @override_settings(SILO_MODE=SiloMode.CONTROL)
     def test_webhook_outbox_creation(self):
         request = self.factory.post(
             self.path,
-            json=WORK_ITEM_UPDATED,
+            data=WORK_ITEM_UPDATED,
+            content_type="application/json",
             HTTP_SHARED_SECRET=self.shared_secret,
         )
         parser = VstsRequestParser(request=request, response_handler=self.get_response)
 
-        assert ControlOutbox.objects.count() == 0
-        with mock.patch.object(
-            parser, "get_regions_from_organizations", return_value=[self.region]
-        ):
-            parser.get_response()
-            assert_webhook_outboxes(
-                factory_request=request,
-                webhook_identifier=WebhookProviderIdentifier.VSTS,
-                region_names=[self.region.name],
-            )
+        assert_no_webhook_outboxes()
+        parser.get_response()
+        assert_webhook_outboxes(
+            factory_request=request,
+            webhook_identifier=WebhookProviderIdentifier.VSTS,
+            region_names=["us"],
+        )