|
@@ -10,24 +10,29 @@ from sentry.models.rulefirehistory import RuleFireHistory
|
|
|
from sentry.testutils.cases import TestCase
|
|
|
|
|
|
|
|
|
-class TestGetParentNotificationMessage(TestCase):
|
|
|
+class BaseIssueAlertNotificationMessageRepositoryTest(TestCase):
|
|
|
def setUp(self) -> None:
|
|
|
self.action_uuid = str(uuid4())
|
|
|
+ self.notify_issue_owners_action = [
|
|
|
+ {
|
|
|
+ "targetType": "IssueOwners",
|
|
|
+ "fallthroughType": "ActiveMembers",
|
|
|
+ "id": "sentry.mail.actions.NotifyEmailAction",
|
|
|
+ "targetIdentifier": "",
|
|
|
+ "uuid": self.action_uuid,
|
|
|
+ }
|
|
|
+ ]
|
|
|
self.rule = self.create_project_rule(
|
|
|
- project=self.project,
|
|
|
- action_match=[
|
|
|
- {
|
|
|
- "id": "sentry.rules.actions.notify_event_service.NotifyEventServiceAction",
|
|
|
- "service": "mail",
|
|
|
- "name": "Send a notification via mail",
|
|
|
- "uuid": self.action_uuid,
|
|
|
- },
|
|
|
- ],
|
|
|
+ project=self.project, action_match=self.notify_issue_owners_action
|
|
|
)
|
|
|
+ self.event_id = 456
|
|
|
+ self.notification_uuid = str(uuid4())
|
|
|
self.rule_fire_history = RuleFireHistory.objects.create(
|
|
|
project=self.project,
|
|
|
rule=self.rule,
|
|
|
group=self.group,
|
|
|
+ event_id=self.event_id,
|
|
|
+ notification_uuid=self.notification_uuid,
|
|
|
)
|
|
|
self.parent_notification_message = NotificationMessage.objects.create(
|
|
|
rule_fire_history=self.rule_fire_history,
|
|
@@ -36,6 +41,8 @@ class TestGetParentNotificationMessage(TestCase):
|
|
|
)
|
|
|
self.repository = IssueAlertNotificationMessageRepository.default()
|
|
|
|
|
|
+
|
|
|
+class TestGetParentNotificationMessage(BaseIssueAlertNotificationMessageRepositoryTest):
|
|
|
def test_returns_parent_notification_message(self) -> None:
|
|
|
instance = self.repository.get_parent_notification_message(
|
|
|
rule_id=self.rule.id,
|
|
@@ -79,37 +86,12 @@ class TestGetParentNotificationMessage(TestCase):
|
|
|
)
|
|
|
|
|
|
|
|
|
-class TestCreateNotificationMessage(TestCase):
|
|
|
- def setUp(self):
|
|
|
- self.action_uuid = str(uuid4())
|
|
|
- self.notify_issue_owners_action = [
|
|
|
- {
|
|
|
- "targetType": "IssueOwners",
|
|
|
- "fallthroughType": "ActiveMembers",
|
|
|
- "id": "sentry.mail.actions.NotifyEmailAction",
|
|
|
- "targetIdentifier": "",
|
|
|
- "uuid": self.action_uuid,
|
|
|
- }
|
|
|
- ]
|
|
|
- self.rule = self.create_project_rule(
|
|
|
- project=self.project, action_match=self.notify_issue_owners_action
|
|
|
- )
|
|
|
- self.event_id = 456
|
|
|
- self.notification_uuid = str(uuid4())
|
|
|
- self.rule_fire_history = RuleFireHistory.objects.create(
|
|
|
- project=self.project,
|
|
|
- rule=self.rule,
|
|
|
- group=self.group,
|
|
|
- event_id=self.event_id,
|
|
|
- notification_uuid=self.notification_uuid,
|
|
|
- )
|
|
|
- self.repository = IssueAlertNotificationMessageRepository.default()
|
|
|
-
|
|
|
+class TestCreateNotificationMessage(BaseIssueAlertNotificationMessageRepositoryTest):
|
|
|
def test_simple(self) -> None:
|
|
|
message_identifier = "1a2b3c"
|
|
|
data = NewIssueAlertNotificationMessage(
|
|
|
rule_fire_history_id=self.rule_fire_history.id,
|
|
|
- rule_action_uuid=self.action_uuid,
|
|
|
+ rule_action_uuid=str(uuid4()),
|
|
|
message_identifier=message_identifier,
|
|
|
)
|
|
|
|
|
@@ -128,7 +110,7 @@ class TestCreateNotificationMessage(TestCase):
|
|
|
}
|
|
|
data = NewIssueAlertNotificationMessage(
|
|
|
rule_fire_history_id=self.rule_fire_history.id,
|
|
|
- rule_action_uuid=self.action_uuid,
|
|
|
+ rule_action_uuid=str(uuid4()),
|
|
|
error_code=405,
|
|
|
error_details=error_detail,
|
|
|
)
|
|
@@ -136,3 +118,90 @@ class TestCreateNotificationMessage(TestCase):
|
|
|
result = self.repository.create_notification_message(data=data)
|
|
|
assert result is not None
|
|
|
assert result.error_details == error_detail
|
|
|
+
|
|
|
+
|
|
|
+class TestGetAllParentNotificationMessagesByFilters(
|
|
|
+ BaseIssueAlertNotificationMessageRepositoryTest
|
|
|
+):
|
|
|
+ def test_returns_all_when_no_filters(self) -> None:
|
|
|
+ # Create additional notification messages
|
|
|
+ additional_notification = NotificationMessage.objects.create(
|
|
|
+ rule_fire_history=self.rule_fire_history,
|
|
|
+ rule_action_uuid=str(uuid4()),
|
|
|
+ message_identifier="123abc",
|
|
|
+ )
|
|
|
+
|
|
|
+ # Call the method without any filters
|
|
|
+ parent_notifications = list(
|
|
|
+ self.repository.get_all_parent_notification_messages_by_filters()
|
|
|
+ )
|
|
|
+
|
|
|
+ result_ids = []
|
|
|
+ for parent_notification in parent_notifications:
|
|
|
+ result_ids.append(parent_notification.id)
|
|
|
+ # Check if all notification messages are returned
|
|
|
+ assert len(result_ids) == 2
|
|
|
+ assert additional_notification.id in result_ids
|
|
|
+ assert self.parent_notification_message.id in result_ids
|
|
|
+
|
|
|
+ def test_returns_filtered_messages_for_project_id(self) -> None:
|
|
|
+ # Create some notification message that should not be returned
|
|
|
+ new_project = self.create_project()
|
|
|
+ additional_rule_fire_history = RuleFireHistory.objects.create(
|
|
|
+ project=new_project,
|
|
|
+ rule=self.rule,
|
|
|
+ group=self.group,
|
|
|
+ event_id=self.event_id,
|
|
|
+ notification_uuid=str(uuid4()),
|
|
|
+ )
|
|
|
+ notification_message_that_should_not_be_returned = NotificationMessage.objects.create(
|
|
|
+ rule_fire_history=additional_rule_fire_history,
|
|
|
+ rule_action_uuid=str(uuid4()),
|
|
|
+ message_identifier="zxcvb",
|
|
|
+ )
|
|
|
+
|
|
|
+ # Call the method with filters specifying the specific project id
|
|
|
+ parent_notifications = list(
|
|
|
+ self.repository.get_all_parent_notification_messages_by_filters(
|
|
|
+ project_ids=[self.project.id]
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ result_ids = []
|
|
|
+ for parent_notification in parent_notifications:
|
|
|
+ result_ids.append(parent_notification.id)
|
|
|
+ # Check if only the notifications related to the specified project
|
|
|
+ assert len(result_ids) == 1
|
|
|
+ assert result_ids[0] == self.parent_notification_message.id
|
|
|
+ assert notification_message_that_should_not_be_returned.id not in result_ids
|
|
|
+
|
|
|
+ def test_returns_filtered_messages_for_group_id(self) -> None:
|
|
|
+ # Create some notification message that should not be returned
|
|
|
+ new_group = self.create_group(project=self.project)
|
|
|
+ additional_rule_fire_history = RuleFireHistory.objects.create(
|
|
|
+ project=self.project,
|
|
|
+ rule=self.rule,
|
|
|
+ group=new_group,
|
|
|
+ event_id=self.event_id,
|
|
|
+ notification_uuid=str(uuid4()),
|
|
|
+ )
|
|
|
+ notification_message_that_should_not_be_returned = NotificationMessage.objects.create(
|
|
|
+ rule_fire_history=additional_rule_fire_history,
|
|
|
+ rule_action_uuid=str(uuid4()),
|
|
|
+ message_identifier="zxcvb",
|
|
|
+ )
|
|
|
+
|
|
|
+ # Call the method with filters specifying the specific project id
|
|
|
+ parent_notifications = list(
|
|
|
+ self.repository.get_all_parent_notification_messages_by_filters(
|
|
|
+ group_ids=[self.group.id]
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ result_ids = []
|
|
|
+ for parent_notification in parent_notifications:
|
|
|
+ result_ids.append(parent_notification.id)
|
|
|
+ # Check if only the notifications related to the specified project
|
|
|
+ assert len(result_ids) == 1
|
|
|
+ assert result_ids[0] == self.parent_notification_message.id
|
|
|
+ assert notification_message_that_should_not_be_returned.id not in result_ids
|