|
@@ -1,7 +1,10 @@
|
|
|
|
+import responses
|
|
|
|
+
|
|
from sentry.api.serializers import serialize
|
|
from sentry.api.serializers import serialize
|
|
from sentry.incidents.logic import create_alert_rule_trigger, create_alert_rule_trigger_action
|
|
from sentry.incidents.logic import create_alert_rule_trigger, create_alert_rule_trigger_action
|
|
from sentry.incidents.models import AlertRuleTriggerAction
|
|
from sentry.incidents.models import AlertRuleTriggerAction
|
|
from sentry.incidents.serializers import ACTION_TARGET_TYPE_TO_STRING
|
|
from sentry.incidents.serializers import ACTION_TARGET_TYPE_TO_STRING
|
|
|
|
+from sentry.models.integrations.integration import Integration
|
|
from sentry.testutils.cases import TestCase
|
|
from sentry.testutils.cases import TestCase
|
|
|
|
|
|
|
|
|
|
@@ -34,3 +37,40 @@ class AlertRuleTriggerActionSerializerTest(TestCase):
|
|
)
|
|
)
|
|
result = serialize(action)
|
|
result = serialize(action)
|
|
self.assert_action_serialized(action, result)
|
|
self.assert_action_serialized(action, result)
|
|
|
|
+ assert result["desc"] == action.target_display
|
|
|
|
+
|
|
|
|
+ @responses.activate
|
|
|
|
+ def test_discord(self):
|
|
|
|
+ base_url: str = "https://discord.com/api/v10"
|
|
|
|
+ responses.add(
|
|
|
|
+ method=responses.GET,
|
|
|
|
+ url=f"{base_url}/channels/channel-id",
|
|
|
|
+ json={
|
|
|
|
+ "guild_id": "guild_id",
|
|
|
|
+ "name": "guild_id",
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ alert_rule = self.create_alert_rule()
|
|
|
|
+ integration = Integration.objects.create(
|
|
|
|
+ provider="discord",
|
|
|
|
+ name="Example Discord",
|
|
|
|
+ external_id="guild_id",
|
|
|
|
+ metadata={
|
|
|
|
+ "guild_id": "guild_id",
|
|
|
|
+ "name": "guild_name",
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ trigger = create_alert_rule_trigger(alert_rule, "hi", 1000)
|
|
|
|
+ with self.feature("organizations:integrations-discord-metric-alerts"):
|
|
|
|
+ action = create_alert_rule_trigger_action(
|
|
|
|
+ trigger,
|
|
|
|
+ AlertRuleTriggerAction.Type.DISCORD,
|
|
|
|
+ AlertRuleTriggerAction.TargetType.SPECIFIC,
|
|
|
|
+ target_identifier="channel-id",
|
|
|
|
+ integration_id=integration.id,
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ result = serialize(action)
|
|
|
|
+ self.assert_action_serialized(action, result)
|
|
|
|
+ assert str(action.target_display) in result["desc"]
|