示例#1
0
 def get(self, request: Request) -> Response:
     organization = Organization(slug="myorg")
     user = User(id=1235, name="Hello There")
     incident = Incident(id=2,
                         identifier=123,
                         organization=organization,
                         title="Something broke")
     activity = IncidentActivity(incident=incident,
                                 user=user,
                                 type=IncidentActivityType.COMMENT.value,
                                 comment="hi")
     email = generate_incident_activity_email(activity, user)
     return MailPreview(html_template=email.html_template,
                        text_template=email.template,
                        context=email.context).render(request)
示例#2
0
 def get(self, request):
     organization = Organization(slug='myorg')
     incident = Incident(
         identifier=123,
         organization=organization,
         title='Something broke',
     )
     activity = IncidentActivity(incident=incident,
                                 user=User(name='Hello There'),
                                 type=IncidentActivityType.COMMENT.value,
                                 comment='hi')
     email = generate_incident_activity_email(activity)
     return MailPreview(
         html_template=email.html_template,
         text_template=email.template,
         context=email.context,
     ).render(request)
    def test_simple(self):
        project1 = self.create_project(
            teams=[self.team], slug="foo"
        )  # This project will return counts for this team
        user_owned_rule = self.create_alert_rule(
            organization=self.organization,
            projects=[project1],
            name="user owned rule",
            query="",
            aggregate="count()",
            time_window=1,
            threshold_type=AlertRuleThresholdType.ABOVE,
            resolve_threshold=10,
            threshold_period=1,
            owner=ActorTuple.from_actor_identifier(self.user.id),
        )
        user_owned_incident = self.create_incident(status=20, alert_rule=user_owned_rule)
        activities = []
        for i in range(1, 9):
            activities.append(
                IncidentActivity(
                    incident=user_owned_incident,
                    type=IncidentActivityType.CREATED.value,
                    value=IncidentStatus.OPEN,
                    date_added=before_now(days=i),
                )
            )
        IncidentActivity.objects.bulk_create(activities)

        self.login_as(user=self.user)
        response = self.get_success_response(self.team.organization.slug, self.team.slug)
        assert len(response.data) == 90
        for i in range(1, 9):
            assert (
                response.data[
                    str(
                        before_now(days=i)
                        .replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc)
                        .isoformat()
                    )
                ]
                == 1
            )

        for i in range(10, 90):
            assert (
                response.data[
                    str(
                        before_now(days=i)
                        .replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc)
                        .isoformat()
                    )
                ]
                == 0
            )

        response = self.get_success_response(
            self.team.organization.slug, self.team.slug, statsPeriod="7d"
        )
        assert len(response.data) == 7
        assert (
            response.data[
                str(
                    before_now(days=0)
                    .replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc)
                    .isoformat()
                )
            ]
            == 0
        )
        for i in range(1, 6):
            assert (
                response.data[
                    str(
                        before_now(days=i)
                        .replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc)
                        .isoformat()
                    )
                ]
                == 1
            )
示例#4
0
    def test(self):
        project1 = self.create_project(teams=[self.team], slug="foo")
        user_owned_rule = self.create_alert_rule(
            organization=self.organization,
            projects=[project1],
            name="user owned rule",
            owner=ActorTuple.from_actor_identifier(self.user.id),
        )

        user_owned_incident = self.create_incident(status=20, alert_rule=user_owned_rule)
        activities = []
        for i in range(0, 8):
            activities.append(
                IncidentActivity(
                    incident=user_owned_incident,
                    type=IncidentActivityType.CREATED.value,
                    value=IncidentStatus.OPEN,
                    date_added=before_now(weeks=i),
                )
            )
        team_owned_rule = self.create_alert_rule(
            organization=self.organization,
            projects=[project1],
            name="team owned rule",
            owner=ActorTuple.from_actor_identifier(f"team:{self.team.id}"),
        )
        team_owned_incident = self.create_incident(status=20, alert_rule=team_owned_rule)
        activities.append(
            IncidentActivity(
                incident=team_owned_incident,
                type=IncidentActivityType.CREATED.value,
                value=IncidentStatus.OPEN,
                date_added=before_now(weeks=0),
            )
        )

        for i in range(0, 10):
            activities.append(
                IncidentActivity(
                    incident=team_owned_incident,
                    type=IncidentActivityType.CREATED.value,
                    value=IncidentStatus.OPEN,
                    date_added=before_now(weeks=i),
                )
            )
        IncidentActivity.objects.bulk_create(activities)

        self.login_as(user=self.user)
        response = self.get_success_response(
            self.team.organization.slug, self.team.slug, statsPeriod="8w"
        )
        assert [
            {"id": row["id"], "totalThisWeek": row["totalThisWeek"], "weeklyAvg": row["weeklyAvg"]}
            for row in response.data
        ] == [
            {"id": str(team_owned_rule.id), "totalThisWeek": 2, "weeklyAvg": 1.375},
            {"id": str(user_owned_rule.id), "totalThisWeek": 1, "weeklyAvg": 1},
        ]

        response = self.get_success_response(
            self.team.organization.slug, self.team.slug, per_page=1, statsPeriod="10w"
        )
        assert [
            {"id": row["id"], "totalThisWeek": row["totalThisWeek"], "weeklyAvg": row["weeklyAvg"]}
            for row in response.data
        ] == [
            {"id": str(team_owned_rule.id), "totalThisWeek": 2, "weeklyAvg": 1.1},
        ]
        next_cursor = self.get_cursor_headers(response)[1]
        response = self.get_success_response(
            self.team.organization.slug,
            self.team.slug,
            per_page=1,
            cursor=next_cursor,
            statsPeriod="10w",
        )
        assert [
            {"id": row["id"], "totalThisWeek": row["totalThisWeek"], "weeklyAvg": row["weeklyAvg"]}
            for row in response.data
        ] == [
            {"id": str(user_owned_rule.id), "totalThisWeek": 1, "weeklyAvg": 0.8},
        ]