def test_note(self, mock_func): """ Test that a Slack message is sent with the expected payload when a comment is made on an issue """ notification = NoteActivityNotification( Activity( project=self.project, group=self.group, user=self.user, type=ActivityType.NOTE, data={ "text": "text", "mentions": [] }, )) with self.tasks(): notification.send() attachment, text = get_attachment() assert text == f"New comment by {self.name}" assert attachment["title"] == f"{self.group.title}" assert ( attachment["title_link"] == f"http://testserver/organizations/{self.organization.slug}/issues/{self.group.id}/?referrer=note-activity-slack" ) assert attachment["text"] == notification.activity.data["text"] assert ( attachment["footer"] == f"{self.project.slug} | <http://testserver/settings/account/notifications/workflow/?referrer=note-activity-slack-user|Notification Settings>" )
def setUp(self): super().setUp() self.email = NoteActivityNotification( Activity( project=self.project, group=self.group, user=self.user, type=ActivityType.NOTE, data={ "text": "text", "mentions": [] }, ))
class NoteTestCase(ActivityTestCase): def setUp(self): super().setUp() self.email = NoteActivityNotification( Activity( project=self.project, group=self.group, user=self.user, type=ActivityType.NOTE, data={ "text": "text", "mentions": [] }, )) def test_simple(self): # Defaults: SUBSCRIBE_ONLY and self_notifications:0 assert not self.email.get_participants_with_group_subscription_reason() def test_allow_self_notifications(self): NotificationSetting.objects.update_settings( ExternalProviders.EMAIL, NotificationSettingTypes.WORKFLOW, NotificationSettingOptionValues.ALWAYS, user=self.user, ) UserOption.objects.create(user=self.user, key="self_notifications", value="1") participants = self.email.get_participants_with_group_subscription_reason( )[ExternalProviders.EMAIL] assert len(participants) == 1 assert participants == { self.user: GroupSubscriptionReason.implicit, } def test_disable_self_notifications(self): NotificationSetting.objects.update_settings( ExternalProviders.EMAIL, NotificationSettingTypes.WORKFLOW, NotificationSettingOptionValues.ALWAYS, user=self.user, ) UserOption.objects.create(user=self.user, key="self_notifications", value="0") participants = self.email.get_participants_with_group_subscription_reason( )[ExternalProviders.EMAIL] assert len(participants) == 0