|
@@ -2,6 +2,7 @@ from unittest.mock import call, patch
|
|
|
|
|
|
from sentry.mediators.sentry_app_components import Preparer
|
|
|
from sentry.testutils import TestCase
|
|
|
+from sentry.utils import json
|
|
|
|
|
|
|
|
|
class TestPreparerIssueLink(TestCase):
|
|
@@ -99,3 +100,101 @@ class TestPreparerStacktraceLink(TestCase):
|
|
|
self.component.schema["url"]
|
|
|
== f"https://example.com/redirection?installationId={self.install.uuid}&projectSlug={self.project.slug}"
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+class TestPreparerAlertRuleAction(TestCase):
|
|
|
+ def setUp(self):
|
|
|
+ super().setUp()
|
|
|
+
|
|
|
+ self.sentry_app = self.create_sentry_app(
|
|
|
+ name="Pied Piper",
|
|
|
+ organization=self.project.organization,
|
|
|
+ schema={
|
|
|
+ "elements": [
|
|
|
+ {
|
|
|
+ "type": "alert-rule-action",
|
|
|
+ "title": "Create a Issue",
|
|
|
+ "settings": {
|
|
|
+ "type": "alert-rule-settings",
|
|
|
+ "uri": "/hooks/sentry/alert-rule-action",
|
|
|
+ "description": "When the alert fires automatically create an issue with the following properties.",
|
|
|
+ "required_fields": [
|
|
|
+ {
|
|
|
+ "name": "teamId",
|
|
|
+ "label": "Team",
|
|
|
+ "type": "select",
|
|
|
+ "uri": "/hooks/sentry/issues/teams",
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "optional_fields": [
|
|
|
+ {
|
|
|
+ "name": "assigneeId",
|
|
|
+ "label": "Assignee",
|
|
|
+ "type": "select",
|
|
|
+ "uri": "/hooks/sentry/issues/assignees",
|
|
|
+ "depends_on": ["teamId"],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "labelId",
|
|
|
+ "label": "Label",
|
|
|
+ "type": "select",
|
|
|
+ "uri": "/hooks/sentry/issues/labels",
|
|
|
+ "depends_on": ["teamId"],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ )
|
|
|
+ self.install = self.create_sentry_app_installation(
|
|
|
+ slug="pied-piper", organization=self.project.organization
|
|
|
+ )
|
|
|
+
|
|
|
+ self.component = self.sentry_app.components.first()
|
|
|
+ self.project = self.install.organization.project_set.first()
|
|
|
+
|
|
|
+ @patch("sentry.mediators.external_requests.SelectRequester.run")
|
|
|
+ def test_prepares_components_requiring_requests(self, run):
|
|
|
+ self.preparer = Preparer(
|
|
|
+ component=self.component,
|
|
|
+ install=self.install,
|
|
|
+ project=self.project,
|
|
|
+ values=[
|
|
|
+ {"name": "teamId", "value": "Ecosystem"},
|
|
|
+ {"name": "assigneeId", "value": "3"},
|
|
|
+ {"name": "labelId", "value": "Priority"},
|
|
|
+ ],
|
|
|
+ )
|
|
|
+
|
|
|
+ self.preparer.call()
|
|
|
+
|
|
|
+ assert (
|
|
|
+ call(
|
|
|
+ install=self.install,
|
|
|
+ project=self.project,
|
|
|
+ uri="/hooks/sentry/issues/teams",
|
|
|
+ dependent_data=None,
|
|
|
+ )
|
|
|
+ in run.mock_calls
|
|
|
+ )
|
|
|
+
|
|
|
+ assert (
|
|
|
+ call(
|
|
|
+ install=self.install,
|
|
|
+ project=self.project,
|
|
|
+ uri="/hooks/sentry/issues/assignees",
|
|
|
+ dependent_data=json.dumps({"teamId": "Ecosystem"}),
|
|
|
+ )
|
|
|
+ in run.mock_calls
|
|
|
+ )
|
|
|
+
|
|
|
+ assert (
|
|
|
+ call(
|
|
|
+ install=self.install,
|
|
|
+ project=self.project,
|
|
|
+ uri="/hooks/sentry/issues/labels",
|
|
|
+ dependent_data=json.dumps({"teamId": "Ecosystem"}),
|
|
|
+ )
|
|
|
+ in run.mock_calls
|
|
|
+ )
|