Esempio n. 1
0
    def test_notify_users_with_owners(self):
        user = self.create_user(email="*****@*****.**", is_active=True)
        user2 = self.create_user(email="*****@*****.**", is_active=True)

        organization = self.create_organization(owner=user)
        team = self.create_team(organization=organization)
        project = self.create_project(name="Test", teams=[team])
        OrganizationMemberTeam.objects.create(
            organizationmember=OrganizationMember.objects.get(
                user=user, organization=organization),
            team=team,
        )
        self.create_member(user=user2, organization=organization, teams=[team])
        self.group = self.create_group(
            first_seen=timezone.now(),
            last_seen=timezone.now(),
            project=project,
            message="hello  world",
            logger="root",
        )
        ProjectOwnership.objects.create(
            project_id=project.id,
            schema=dump_schema([
                grammar.Rule(Matcher("path", "*.py"),
                             [Owner("team", team.slug)]),
                grammar.Rule(Matcher("path", "*.jx"),
                             [Owner("user", user2.email)]),
                grammar.Rule(
                    Matcher("path", "*.cbl"),
                    [Owner("user", user.email),
                     Owner("user", user2.email)],
                ),
            ]),
            fallthrough=True,
        )

        event_all_users = self.store_event(data=make_event_data("foo.cbl"),
                                           project_id=project.id)
        self.assert_notify(event_all_users, [user.email, user2.email])

        event_team = self.store_event(data=make_event_data("foo.py"),
                                      project_id=project.id)
        self.assert_notify(event_team, [user.email, user2.email])

        event_single_user = self.store_event(data=make_event_data("foo.jx"),
                                             project_id=project.id)
        self.assert_notify(event_single_user, [user2.email])

        # Make sure that disabling mail alerts works as expected
        NotificationSetting.objects.update_settings(
            ExternalProviders.EMAIL,
            NotificationSettingTypes.ISSUE_ALERTS,
            NotificationSettingOptionValues.NEVER,
            user=user2,
            project=project,
        )
        event_all_users = self.store_event(data=make_event_data("foo.cbl"),
                                           project_id=project.id)
        self.assert_notify(event_all_users, [user.email])
Esempio n. 2
0
 def test_notify_user(self):
     user = self.create_user(email="*****@*****.**", is_active=True)
     self.create_team(organization=self.organization, members=[user])
     event = self.store_event(data=make_event_data("foo.py"),
                              project_id=self.project.id)
     self.assert_notify(event, [user.email], ActionTargetType.MEMBER,
                        str(user.id))
Esempio n. 3
0
    def test_notify_team_members(self):
        """Test that each member of a team is notified"""

        user = self.create_user(email="*****@*****.**", is_active=True)
        user2 = self.create_user(email="*****@*****.**", is_active=True)
        team = self.create_team(organization=self.organization,
                                members=[user, user2])
        project = self.create_project(teams=[team])
        event = self.store_event(data=make_event_data("foo.py"),
                                 project_id=project.id)
        self.assert_notify(event, [user.email, user2.email],
                           ActionTargetType.TEAM, str(team.id))
Esempio n. 4
0
    def test_slack_link(self):
        project = self.project
        organization = project.organization
        event = self.store_event(data=make_event_data("foo.jx"),
                                 project_id=project.id)

        with self.tasks():
            notification = Notification(event=event)
            self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)

        assert len(mail.outbox) >= 1

        msg = mail.outbox[-1]
        assert (
            f"/settings/{organization.slug}/integrations/slack/?referrer=alert_email"
            in msg.alternatives[0][0])
Esempio n. 5
0
 def store_event(self, filename: str) -> Event:
     return super().store_event(data=make_event_data(filename),
                                project_id=self.project.id)