Skip to content

Commit d414c4a

Browse files
snigdhasceorourke
authored andcommitted
Fix types
1 parent 817a0c3 commit d414c4a

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

tests/sentry/issues/test_ingest_incident_integration.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
from django.utils import timezone
44

5+
from sentry.event_manager import GroupInfo
56
from sentry.incidents.grouptype import MetricIssue
67
from sentry.issues.grouptype import FeedbackGroup
78
from sentry.issues.ingest import save_issue_occurrence
8-
from sentry.issues.issue_occurrence import IssueOccurrenceData
9+
from sentry.issues.issue_occurrence import IssueOccurrence, IssueOccurrenceData
910
from sentry.models.group import GroupStatus
1011
from sentry.models.groupopenperiod import GroupOpenPeriod
1112
from sentry.testutils.cases import TestCase
@@ -14,7 +15,7 @@
1415

1516

1617
class IncidentGroupOpenPeriodIntegrationTest(TestCase):
17-
def setUp(self):
18+
def setUp(self) -> None:
1819
super().setUp()
1920
self.organization = self.create_organization()
2021
self.project = self.create_project(organization=self.organization)
@@ -24,7 +25,9 @@ def setUp(self):
2425
name="Test Alert Rule",
2526
)
2627

27-
def save_issue_occurrence(self, group_type=MetricIssue):
28+
def save_issue_occurrence(
29+
self, group_type: int = MetricIssue.type_id
30+
) -> tuple[IssueOccurrence, GroupInfo]:
2831
event = self.store_event(
2932
data={"timestamp": timezone.now().isoformat()}, project_id=self.project.id
3033
)
@@ -41,7 +44,7 @@ def save_issue_occurrence(self, group_type=MetricIssue):
4144
"evidence_display": [
4245
{"name": "Test Evidence", "value": "Test Value", "important": True}
4346
],
44-
"type": group_type.type_id,
47+
"type": group_type,
4548
"detection_time": timezone.now().timestamp(),
4649
"level": "error",
4750
"culprit": "test-culprit",
@@ -51,11 +54,11 @@ def save_issue_occurrence(self, group_type=MetricIssue):
5154
occurrence, group_info = save_issue_occurrence(occurrence_data, event)
5255

5356
assert group_info is not None
54-
assert group_info.group.type == group_type.type_id
57+
assert group_info.group.type == group_type
5558
return occurrence, group_info
5659

5760
@with_feature("organizations:issue-open-periods")
58-
def test_save_issue_occurrence_creates_relationship_when_incident_exists(self):
61+
def test_save_issue_occurrence_creates_relationship_when_incident_exists(self) -> None:
5962
"""Test that save_issue_occurrence creates the relationship when incident exists"""
6063
incident = self.create_incident(
6164
organization=self.organization,
@@ -74,7 +77,7 @@ def test_save_issue_occurrence_creates_relationship_when_incident_exists(self):
7477
assert item.incident_identifier == incident.identifier
7578

7679
@with_feature("organizations:issue-open-periods")
77-
def test_save_issue_occurrence_creates_placeholder_when_incident_doesnt_exist(self):
80+
def test_save_issue_occurrence_creates_placeholder_when_incident_doesnt_exist(self) -> None:
7881
"""Test that save_issue_occurrence creates placeholder when incident doesn't exist"""
7982
_, group_info = self.save_issue_occurrence()
8083
group = group_info.group
@@ -86,7 +89,7 @@ def test_save_issue_occurrence_creates_placeholder_when_incident_doesnt_exist(se
8689
assert not IncidentGroupOpenPeriod.objects.filter(group_open_period=open_period).exists()
8790

8891
@with_feature("organizations:issue-open-periods")
89-
def test_save_issue_occurrence_creates_relationship_for_existing_group(self):
92+
def test_save_issue_occurrence_creates_relationship_for_existing_group(self) -> None:
9093
"""Test that save_issue_occurrence creates relationship for existing groups"""
9194
incident = self.create_incident(
9295
organization=self.organization,
@@ -114,9 +117,9 @@ def test_save_issue_occurrence_creates_relationship_for_existing_group(self):
114117
assert item.incident_identifier == incident.identifier
115118

116119
@with_feature("organizations:issue-open-periods")
117-
def test_save_issue_occurrence_no_relationship_for_non_metric_issues(self):
120+
def test_save_issue_occurrence_no_relationship_for_non_metric_issues(self) -> None:
118121
# Test that save_issue_occurrence doesn't create relationships for non-metric issues
119-
_, group_info = self.save_issue_occurrence(group_type=FeedbackGroup)
122+
_, group_info = self.save_issue_occurrence(group_type=FeedbackGroup.type_id)
120123

121124
group = group_info.group
122125
assert group is not None

tests/sentry/workflow_engine/models/test_incident_groupopenperiod.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Any
12
from unittest.mock import patch
23

34
from django.utils import timezone
@@ -12,7 +13,7 @@
1213

1314

1415
class IncidentGroupOpenPeriodTest(TestCase):
15-
def setUp(self):
16+
def setUp(self) -> None:
1617
super().setUp()
1718
self.organization = self.create_organization()
1819
self.project = self.create_project(organization=self.organization)
@@ -25,7 +26,7 @@ def setUp(self):
2526
self.group.type = MetricIssue.type_id
2627
self.group.save()
2728

28-
def save_issue_occurrence(self, group_type=MetricIssue, include_alert_id=True):
29+
def save_issue_occurrence(self, include_alert_id: bool = True) -> tuple[Any, GroupOpenPeriod]:
2930
event = self.store_event(
3031
data={"timestamp": timezone.now().isoformat()}, project_id=self.project.id
3132
)
@@ -42,7 +43,7 @@ def save_issue_occurrence(self, group_type=MetricIssue, include_alert_id=True):
4243
"evidence_display": [
4344
{"name": "Test Evidence", "value": "Test Value", "important": True}
4445
],
45-
"type": group_type.type_id,
46+
"type": MetricIssue.type_id,
4647
"detection_time": timezone.now().timestamp(),
4748
"level": "error",
4849
"culprit": "test-culprit",
@@ -52,15 +53,15 @@ def save_issue_occurrence(self, group_type=MetricIssue, include_alert_id=True):
5253
occurrence, group_info = save_issue_occurrence(occurrence_data, event)
5354

5455
assert group_info is not None
55-
assert group_info.group.type == group_type.type_id
56+
assert group_info.group.type == MetricIssue.type_id
5657

5758
open_period = GroupOpenPeriod.objects.get(group=group_info.group)
5859
assert open_period is not None
5960
assert open_period.date_ended is None
6061
return occurrence, open_period
6162

6263
@with_feature("organizations:issue-open-periods")
63-
def test_create_from_occurrence_with_existing_incident(self):
64+
def test_create_from_occurrence_with_existing_incident(self) -> None:
6465
"""Test creating relationship when incident exists"""
6566
occurrence, open_period = self.save_issue_occurrence()
6667

@@ -79,7 +80,7 @@ def test_create_from_occurrence_with_existing_incident(self):
7980
assert result.group_open_period == open_period
8081

8182
@with_feature("organizations:issue-open-periods")
82-
def test_create_from_occurrence_without_incident(self):
83+
def test_create_from_occurrence_without_incident(self) -> None:
8384
"""Test creating placeholder when incident doesn't exist"""
8485
occurrence, open_period = self.save_issue_occurrence()
8586

@@ -90,7 +91,7 @@ def test_create_from_occurrence_without_incident(self):
9091
assert open_period.data["pending_incident_alert_id"] == self.alert_rule.id
9192

9293
@with_feature("organizations:issue-open-periods")
93-
def test_create_from_occurrence_no_alert_id(self):
94+
def test_create_from_occurrence_no_alert_id(self) -> None:
9495
"""Test handling when no alert_id in evidence_data"""
9596
with patch("sentry.issues.ingest.eventstream") as _:
9697
occurrence, group_info = self.save_issue_occurrence(include_alert_id=False)
@@ -105,7 +106,7 @@ def test_create_from_occurrence_no_alert_id(self):
105106
assert result is None
106107

107108
@with_feature("organizations:issue-open-periods")
108-
def test_create_relationship_new(self):
109+
def test_create_relationship_new(self) -> None:
109110
"""Test creating a new relationship"""
110111
occurrence, open_period = self.save_issue_occurrence()
111112

@@ -124,7 +125,7 @@ def test_create_relationship_new(self):
124125
assert result.group_open_period == open_period
125126

126127
@with_feature("organizations:issue-open-periods")
127-
def test_create_relationship_existing(self):
128+
def test_create_relationship_existing(self) -> None:
128129
"""Test updating an existing relationship"""
129130
occurrence, open_period = self.save_issue_occurrence()
130131

@@ -155,7 +156,7 @@ def test_create_relationship_existing(self):
155156
assert result.group_open_period == open_period
156157

157158
@with_feature("organizations:issue-open-periods")
158-
def test_create_placeholder_relationship(self):
159+
def test_create_placeholder_relationship(self) -> None:
159160
"""Test creating a placeholder relationship"""
160161
occurrence, open_period = self.save_issue_occurrence()
161162

@@ -168,7 +169,7 @@ def test_create_placeholder_relationship(self):
168169
assert open_period.data["pending_incident_alert_id"] == self.alert_rule.id
169170

170171
@with_feature("organizations:issue-open-periods")
171-
def test_create_pending_relationships_for_incident(self):
172+
def test_create_pending_relationships_for_incident(self) -> None:
172173
"""Test creating relationships for pending open periods"""
173174
occurrence, open_period = self.save_issue_occurrence()
174175

@@ -195,7 +196,7 @@ def test_create_pending_relationships_for_incident(self):
195196
assert "pending_incident_alert_id" not in open_period.data
196197

197198
@with_feature("organizations:issue-open-periods")
198-
def test_create_pending_relationships_for_incident_no_pending(self):
199+
def test_create_pending_relationships_for_incident_no_pending(self) -> None:
199200
"""Test creating relationships when no pending relationships exist"""
200201
incident = self.create_incident(
201202
organization=self.organization,

0 commit comments

Comments
 (0)