diff --git a/src/sentry/integrations/msteams/__init__.py b/src/sentry/integrations/msteams/__init__.py index bb14961b9ff4d2..1a03c043b5ca16 100644 --- a/src/sentry/integrations/msteams/__init__.py +++ b/src/sentry/integrations/msteams/__init__.py @@ -1,5 +1,6 @@ from sentry.integrations.msteams.spec import MsTeamsMessagingSpec from .handlers import MSTeamsActionHandler # noqa: F401,F403 +from .notifications import * # noqa: F401,F403 MsTeamsMessagingSpec().initialize() diff --git a/src/sentry/notifications/apps.py b/src/sentry/notifications/apps.py index 2184060fa175d4..e4be76f88a81fe 100644 --- a/src/sentry/notifications/apps.py +++ b/src/sentry/notifications/apps.py @@ -5,14 +5,9 @@ class Config(AppConfig): name = "sentry.notifications" def ready(self) -> None: - import sentry.notifications.platform.sample # NOQA - - # Register the NotificationProviders for the platform - from sentry.notifications.platform.discord.provider import ( # NOQA - DiscordNotificationProvider, - ) - from sentry.notifications.platform.email.provider import EmailNotificationProvider # NOQA - from sentry.notifications.platform.msteams.provider import ( # NOQA - MSTeamsNotificationProvider, - ) - from sentry.notifications.platform.slack.provider import SlackNotificationProvider # NOQA + # Register the providers and templates for the new platform + import sentry.notifications.platform.discord.provider # noqa: F401 + import sentry.notifications.platform.email.provider # noqa: F401 + import sentry.notifications.platform.msteams.provider # noqa: F401 + import sentry.notifications.platform.slack.provider # noqa: F401 + import sentry.notifications.platform.templates # noqa: F401 diff --git a/src/sentry/notifications/platform/templates/__init__.py b/src/sentry/notifications/platform/templates/__init__.py new file mode 100644 index 00000000000000..aa845e6e05e485 --- /dev/null +++ b/src/sentry/notifications/platform/templates/__init__.py @@ -0,0 +1,4 @@ +# All templates should be imported here so they are registered in the notifications Django app. +# See sentry/notifications/apps.py + +from .sample import * # noqa: F401,F403 diff --git a/src/sentry/notifications/platform/sample.py b/src/sentry/notifications/platform/templates/sample.py similarity index 100% rename from src/sentry/notifications/platform/sample.py rename to src/sentry/notifications/platform/templates/sample.py diff --git a/tests/sentry/notifications/test_apps.py b/tests/sentry/notifications/test_apps.py new file mode 100644 index 00000000000000..744d36f3a690aa --- /dev/null +++ b/tests/sentry/notifications/test_apps.py @@ -0,0 +1,31 @@ +from sentry.integrations.types import ExternalProviders +from sentry.notifications.platform.types import NotificationProviderKey +from sentry.testutils.cases import TestCase + + +class NotificationsDjangoAppTest(TestCase): + + def test_registers_legacy_providers(self) -> None: + """ + This django app doesn't actually register these legacy providers because it would result + in some circular breakages from all the __init__.py imports. We'll still test it here + to make sure it doesn't break in the future. + + If this test is failing for you, ensure all `@register_notification_provider` decorators + are triggered by an initialization import. + """ + from sentry.notifications.notify import registry + + assert len(registry) == 3 + assert registry[ExternalProviders.EMAIL] is not None + assert registry[ExternalProviders.SLACK] is not None + assert registry[ExternalProviders.MSTEAMS] is not None + + def test_registers_platform_providers(self) -> None: + from sentry.notifications.platform.registry import provider_registry + + assert len(provider_registry.registrations) == 4 + assert provider_registry.get(NotificationProviderKey.DISCORD) is not None + assert provider_registry.get(NotificationProviderKey.EMAIL) is not None + assert provider_registry.get(NotificationProviderKey.MSTEAMS) is not None + assert provider_registry.get(NotificationProviderKey.SLACK) is not None