Skip to content

Commit

Permalink
ref: copy test_plugins from getsentry
Browse files Browse the repository at this point in the history
this was not testing anythign in getsentry and makes it difficult to delete a plugin
  • Loading branch information
asottile-sentry committed Jan 31, 2025
1 parent 1f0d5ad commit 9659c1f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 6 deletions.
13 changes: 10 additions & 3 deletions tests/sentry/integrations/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from __future__ import annotations

from collections.abc import Generator
from unittest.mock import patch

import pytest
from django.db import router

from sentry.integrations.example import AliasedIntegrationProvider, ExampleIntegrationProvider
Expand Down Expand Up @@ -28,9 +32,6 @@ class ExamplePlugin(IssuePlugin2):
slug = "example"


plugins.register(ExamplePlugin)


def naive_build_integration(data):
return data

Expand All @@ -43,6 +44,12 @@ def naive_build_integration(data):
class FinishPipelineTestCase(IntegrationTestCase):
provider = ExampleIntegrationProvider

@pytest.fixture(autouse=True)
def _register_example_plugin(self) -> Generator[None]:
plugins.register(ExamplePlugin)
yield
plugins.unregister(ExamplePlugin)

def setUp(self):
super().setUp()
self.external_id = "dummy_id-123"
Expand Down
15 changes: 12 additions & 3 deletions tests/sentry/plugins/test_migrate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
from __future__ import annotations

from collections.abc import Generator

import pytest

from sentry.integrations.example import ExampleIntegrationProvider
from sentry.integrations.services.integration.serial import serialize_integration
from sentry.models.repository import Repository
Expand All @@ -12,10 +18,13 @@ class ExamplePlugin(IssuePlugin2):
slug = "example"


plugins.register(ExamplePlugin)


class MigratorTest(TestCase):
@pytest.fixture(autouse=True)
def _register_example_plugin(self) -> Generator[None]:
plugins.register(ExamplePlugin)
yield
plugins.unregister(ExamplePlugin)

def setUp(self):
super().setUp()

Expand Down
75 changes: 75 additions & 0 deletions tests/sentry/plugins/test_plugins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from django.conf import settings

from sentry.plugins.base import plugins
from sentry.runner.importer import install_plugin_apps
from sentry.testutils.cases import TestCase

plugin_slugs = [
"amazon-sqs",
"asana",
"bitbucket",
"browsers",
"device",
"github",
"gitlab",
"heroku",
"interface_types",
"javaplugin",
"javascriptplugin",
"jira",
"opsgenie",
"os",
"pagerduty",
"phabricator",
"pivotal",
"pushover",
"redmine",
"segment",
"sessionstack",
"slack",
"splunk",
"trello",
"twilio",
"urls",
"victorops",
"webhooks",
]


sentry_app_names = [
"auth_github",
"auth_saml2.onelogin",
"auth_saml2.generic",
"auth_saml2.okta",
"auth_saml2.rippling",
"auth_saml2.auth0",
"jira",
"opsgenie",
"redmine",
"sessionstack",
"trello",
"twilio",
]


class TestPluginsInstalled(TestCase):
def test_plugin_slugs(self):
all_plugins = sorted(plugin.slug for plugin in plugins.all(version=None))
# issuetrackingplugin2 is a test plugin from sentry pytest utils
all_plugins.remove("issuetrackingplugin2")
assert all_plugins == plugin_slugs

def test_sentry_apps(self):
install_plugin_apps("sentry.apps", settings)

normalized_apps = set(
map(
lambda x: x.replace("sentry_plugins.", "")
.replace("sentry.auth.providers.", "auth_")
.replace("sentry_", ""),
settings.INSTALLED_APPS,
)
)

for app in sentry_app_names:
assert app in normalized_apps

0 comments on commit 9659c1f

Please sign in to comment.