|
| 1 | +import pytest |
1 | 2 | from django.db import DEFAULT_DB_ALIAS, connections |
2 | 3 | from django.test.utils import CaptureQueriesContext |
3 | 4 | from django.utils import timezone |
| 5 | +from rest_framework import serializers |
4 | 6 |
|
5 | 7 | from sentry.api.serializers import serialize |
6 | 8 | from sentry.api.serializers.models.rule import RuleSerializer, WorkflowEngineRuleSerializer |
|
29 | 31 | from sentry.workflow_engine.models import WorkflowDataConditionGroup, WorkflowFireHistory |
30 | 32 | from sentry.workflow_engine.models.data_condition import Condition |
31 | 33 |
|
| 34 | +ValidationError = serializers.ValidationError |
| 35 | + |
32 | 36 |
|
33 | 37 | @freeze_time() |
34 | 38 | class RuleSerializerTest(TestCase): |
@@ -628,3 +632,83 @@ def test_azure_devops_action(self) -> None: |
628 | 632 | include_workflow_id=False, |
629 | 633 | ) |
630 | 634 | self.assert_equal_serializers(rule) |
| 635 | + |
| 636 | + def test_sentry_app_render_label(self) -> None: |
| 637 | + schema = {"elements": [self.create_alert_rule_action_schema()]} |
| 638 | + sentry_app = self.create_sentry_app( |
| 639 | + organization=self.organization, |
| 640 | + name="Test Application", |
| 641 | + is_alertable=True, |
| 642 | + schema=schema, |
| 643 | + ) |
| 644 | + installation = self.create_sentry_app_installation( |
| 645 | + slug=sentry_app.slug, organization=self.organization |
| 646 | + ) |
| 647 | + |
| 648 | + action_data = { |
| 649 | + "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction", |
| 650 | + "sentryAppInstallationUuid": installation.uuid, |
| 651 | + } |
| 652 | + rule = self.create_project_rule( |
| 653 | + project=self.project, |
| 654 | + action_data=[action_data], |
| 655 | + condition_data=self.conditions, |
| 656 | + include_legacy_rule_id=False, |
| 657 | + include_workflow_id=False, |
| 658 | + ) |
| 659 | + self.assert_equal_serializers(rule) |
| 660 | + |
| 661 | + def test_sentry_app_render_label_no_alert_rule_action_schema(self) -> None: |
| 662 | + schema = {"elements": [self.create_issue_link_schema()]} |
| 663 | + sentry_app = self.create_sentry_app( |
| 664 | + organization=self.organization, |
| 665 | + name="Test Application", |
| 666 | + is_alertable=True, |
| 667 | + schema=schema, |
| 668 | + ) |
| 669 | + installation = self.create_sentry_app_installation( |
| 670 | + slug=sentry_app.slug, organization=self.organization |
| 671 | + ) |
| 672 | + |
| 673 | + action_data = { |
| 674 | + "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction", |
| 675 | + "sentryAppInstallationUuid": installation.uuid, |
| 676 | + } |
| 677 | + rule = self.create_project_rule( |
| 678 | + project=self.project, |
| 679 | + action_data=[action_data], |
| 680 | + condition_data=self.conditions, |
| 681 | + include_legacy_rule_id=False, |
| 682 | + include_workflow_id=False, |
| 683 | + ) |
| 684 | + with pytest.raises(ValidationError): |
| 685 | + self.assert_equal_serializers(rule) |
| 686 | + |
| 687 | + def test_sentry_app_render_label_no_installation(self) -> None: |
| 688 | + schema = {"elements": [self.create_alert_rule_action_schema()]} |
| 689 | + sentry_app = self.create_sentry_app( |
| 690 | + organization=self.organization, |
| 691 | + name="Test Application", |
| 692 | + is_alertable=True, |
| 693 | + schema=schema, |
| 694 | + ) |
| 695 | + installation = self.create_sentry_app_installation( |
| 696 | + slug=sentry_app.slug, organization=self.organization |
| 697 | + ) |
| 698 | + |
| 699 | + action_data = { |
| 700 | + "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction", |
| 701 | + "sentryAppInstallationUuid": installation.uuid, |
| 702 | + } |
| 703 | + with assume_test_silo_mode(SiloMode.CONTROL): |
| 704 | + installation.delete() |
| 705 | + |
| 706 | + rule = self.create_project_rule( |
| 707 | + project=self.project, |
| 708 | + action_data=[action_data], |
| 709 | + condition_data=self.conditions, |
| 710 | + include_legacy_rule_id=False, |
| 711 | + include_workflow_id=False, |
| 712 | + ) |
| 713 | + # actions part of response are both [] |
| 714 | + self.assert_equal_serializers(rule) |
0 commit comments