-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
tests(alerts): Increase test coverage in incident chart test #100936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ceorourke
wants to merge
2
commits into
master
Choose a base branch
from
ceorourke/incident-chart-test-coverage
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−21
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import datetime | ||
from unittest.mock import ANY, MagicMock, patch | ||
from unittest.mock import MagicMock, patch | ||
|
||
from django.utils import timezone | ||
from django.utils.dateparse import parse_datetime | ||
|
@@ -19,7 +19,7 @@ | |
DetailedIncidentSerializerResponse, | ||
) | ||
from sentry.incidents.logic import CRITICAL_TRIGGER_LABEL | ||
from sentry.incidents.models.incident import Incident | ||
from sentry.incidents.models.incident import Incident, IncidentActivityType, IncidentStatus | ||
from sentry.incidents.typings.metric_detector import AlertContext, OpenPeriodContext | ||
from sentry.snuba.dataset import Dataset | ||
from sentry.testutils.cases import TestCase | ||
|
@@ -128,30 +128,44 @@ def test_eap_alert(self, mock_client_get: MagicMock, mock_generate_chart: MagicM | |
|
||
class FetchOpenPeriodsTest(TestCase): | ||
@freeze_time(frozen_time) | ||
@patch("sentry.incidents.charts.client.get") | ||
@with_feature("organizations:incidents") | ||
@with_feature("organizations:workflow-engine-single-process-metric-issues") | ||
def test_get_incidents_from_detector(self, mock_client_get: MagicMock) -> None: | ||
def test_get_incidents_from_detector(self) -> None: | ||
self.create_detector() # dummy so detector ID != alert rule ID | ||
detector = self.create_detector(project=self.project) | ||
alert_rule = self.create_alert_rule(organization=self.organization, projects=[self.project]) | ||
self.create_alert_rule_detector(detector=detector, alert_rule_id=alert_rule.id) | ||
incident = Incident( | ||
incident = self.create_incident( | ||
date_started=must_parse_datetime("2022-05-16T18:55:00Z"), | ||
date_closed=None, | ||
status=IncidentStatus.CRITICAL.value, | ||
alert_rule=alert_rule, | ||
) | ||
# create incident activity the same way we do in logic.py create_incident | ||
detected_activity = self.create_incident_activity( | ||
incident, | ||
IncidentActivityType.DETECTED.value, | ||
date_added=incident.date_started, | ||
) | ||
created_activity = self.create_incident_activity( | ||
incident, | ||
IncidentActivityType.CREATED.value, | ||
) | ||
|
||
time_period = incident_date_range(60, incident.date_started, incident.date_closed) | ||
|
||
fetch_metric_issue_open_periods(self.organization, detector.id, time_period) | ||
mock_client_get.assert_called_with( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recognize that I'm changing what's being tested here, but I'm not sure the previous test was adding much value. I can keep it around and add this as an additional test if necessary. |
||
auth=ANY, | ||
user=ANY, | ||
path="/organizations/baz/incidents/", | ||
params={ | ||
"alertRule": alert_rule.id, | ||
"expand": "activities", | ||
"includeSnapshots": True, | ||
"project": -1, | ||
**time_period, | ||
}, | ||
) | ||
chart_data = fetch_metric_issue_open_periods(self.organization, detector.id, time_period) | ||
assert chart_data[0]["alertRule"]["id"] == str(alert_rule.id) | ||
assert chart_data[0]["projects"] == [self.project.slug] | ||
assert chart_data[0]["dateStarted"] == incident.date_started | ||
|
||
assert len(chart_data[0]["activities"]) == 2 | ||
detected_activity_resp = chart_data[0]["activities"][0] | ||
created_activity_resp = chart_data[0]["activities"][1] | ||
|
||
assert detected_activity_resp["incidentIdentifier"] == str(incident.identifier) | ||
assert detected_activity_resp["type"] == IncidentActivityType.DETECTED.value | ||
assert detected_activity_resp["dateCreated"] == detected_activity.date_added | ||
|
||
assert created_activity_resp["incidentIdentifier"] == str(incident.identifier) | ||
assert created_activity_resp["type"] == IncidentActivityType.CREATED.value | ||
assert created_activity_resp["dateCreated"] == created_activity.date_added |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this we were actually hitting a 404 hitting the incidents endpoint, but the test didn't care to check