Exemplo n.º 1
0
    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 = get_attachment()

        assert attachment["title"] == f"New comment by {self.name}"
        assert attachment["text"] == notification.activity.data["text"]
        assert (
            attachment["footer"] ==
            f"<http://testserver/organizations/{self.organization.slug}/issues/{self.group.id}/?referrer=NoteActivitySlack|{self.short_id}> via <http://testserver/settings/account/notifications/?referrer=NoteActivitySlack|Notification Settings>"
        )
Exemplo n.º 2
0
 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": []
             },
         ))
Exemplo n.º 3
0
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