firefighter-incident 0.0.16__py3-none-any.whl → 0.0.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- firefighter/_version.py +2 -2
- firefighter/incidents/forms/edit.py +5 -3
- firefighter/incidents/forms/unified_incident.py +180 -56
- firefighter/incidents/forms/update_status.py +94 -58
- firefighter/incidents/forms/utils.py +14 -0
- firefighter/incidents/models/incident.py +3 -2
- firefighter/raid/apps.py +0 -1
- firefighter/slack/signals/__init__.py +16 -0
- firefighter/slack/signals/incident_updated.py +43 -1
- firefighter/slack/utils.py +43 -6
- firefighter/slack/views/modals/base_modal/form_utils.py +3 -1
- firefighter/slack/views/modals/downgrade_workflow.py +3 -1
- firefighter/slack/views/modals/edit.py +53 -7
- firefighter/slack/views/modals/opening/set_details.py +20 -0
- firefighter_fixtures/incidents/priorities.json +1 -1
- {firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/METADATA +1 -1
- {firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/RECORD +28 -29
- firefighter_tests/test_incidents/test_forms/test_unified_incident_form_integration.py +160 -23
- firefighter_tests/test_incidents/test_forms/test_unified_incident_form_p4_p5.py +38 -60
- firefighter_tests/test_incidents/test_forms/test_update_status_workflow.py +35 -20
- firefighter_tests/test_incidents/test_forms/test_workflow_transitions.py +8 -6
- firefighter_tests/test_slack/test_signals_downgrade.py +147 -0
- firefighter_tests/test_slack/views/modals/test_edit.py +324 -0
- firefighter_tests/test_slack/views/modals/test_opening_unified.py +42 -0
- firefighter_tests/test_slack/views/modals/test_update_status.py +72 -2
- firefighter/raid/signals/incident_created.py +0 -129
- firefighter_tests/test_raid/test_p1_p3_jira_fields.py +0 -372
- firefighter_tests/test_raid/test_priority_mapping.py +0 -267
- {firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/WHEEL +0 -0
- {firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/entry_points.txt +0 -0
- {firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"""Test priority mapping from Impact to JIRA for all priority values including P5."""
|
|
2
|
-
from __future__ import annotations
|
|
3
|
-
|
|
4
|
-
from unittest.mock import Mock, patch
|
|
5
|
-
|
|
6
|
-
import pytest
|
|
7
|
-
from django.test import TestCase
|
|
8
|
-
|
|
9
|
-
from firefighter.incidents.factories import (
|
|
10
|
-
IncidentFactory,
|
|
11
|
-
UserFactory,
|
|
12
|
-
)
|
|
13
|
-
from firefighter.incidents.models.priority import Priority
|
|
14
|
-
from firefighter.jira_app.client import JiraAPIError, JiraUserNotFoundError
|
|
15
|
-
from firefighter.jira_app.models import JiraUser
|
|
16
|
-
from firefighter.raid.signals.incident_created import create_ticket
|
|
17
|
-
from firefighter.slack.factories import IncidentChannelFactory
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
class TestPriorityMapping(TestCase):
|
|
21
|
-
"""Test priority mapping from Impact to JIRA including P5 support."""
|
|
22
|
-
|
|
23
|
-
def setUp(self):
|
|
24
|
-
"""Set up test data."""
|
|
25
|
-
self.user = UserFactory()
|
|
26
|
-
|
|
27
|
-
# Create or get priorities P1-P5 (use get_or_create to avoid duplicates)
|
|
28
|
-
self.priority_p1, _ = Priority.objects.get_or_create(
|
|
29
|
-
value=1, defaults={"name": "Critical", "order": 1}
|
|
30
|
-
)
|
|
31
|
-
self.priority_p2, _ = Priority.objects.get_or_create(
|
|
32
|
-
value=2, defaults={"name": "High", "order": 2}
|
|
33
|
-
)
|
|
34
|
-
self.priority_p3, _ = Priority.objects.get_or_create(
|
|
35
|
-
value=3, defaults={"name": "Medium", "order": 3}
|
|
36
|
-
)
|
|
37
|
-
self.priority_p4, _ = Priority.objects.get_or_create(
|
|
38
|
-
value=4, defaults={"name": "Low", "order": 4}
|
|
39
|
-
)
|
|
40
|
-
self.priority_p5, _ = Priority.objects.get_or_create(
|
|
41
|
-
value=5, defaults={"name": "Lowest", "order": 5}
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
45
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
46
|
-
def test_priority_p1_mapping(self, mock_get_jira_user, mock_client):
|
|
47
|
-
"""Test P1 priority mapping to JIRA."""
|
|
48
|
-
self._test_priority_mapping(self.priority_p1, 1, mock_get_jira_user, mock_client)
|
|
49
|
-
|
|
50
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
51
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
52
|
-
def test_priority_p2_mapping(self, mock_get_jira_user, mock_client):
|
|
53
|
-
"""Test P2 priority mapping to JIRA."""
|
|
54
|
-
self._test_priority_mapping(self.priority_p2, 2, mock_get_jira_user, mock_client)
|
|
55
|
-
|
|
56
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
57
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
58
|
-
def test_priority_p3_mapping(self, mock_get_jira_user, mock_client):
|
|
59
|
-
"""Test P3 priority mapping to JIRA."""
|
|
60
|
-
self._test_priority_mapping(self.priority_p3, 3, mock_get_jira_user, mock_client)
|
|
61
|
-
|
|
62
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
63
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
64
|
-
def test_priority_p4_mapping(self, mock_get_jira_user, mock_client):
|
|
65
|
-
"""Test P4 priority mapping to JIRA."""
|
|
66
|
-
self._test_priority_mapping(self.priority_p4, 4, mock_get_jira_user, mock_client)
|
|
67
|
-
|
|
68
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
69
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
70
|
-
def test_priority_p5_mapping(self, mock_get_jira_user, mock_client):
|
|
71
|
-
"""Test P5 priority mapping to JIRA - this should now work with our fix."""
|
|
72
|
-
self._test_priority_mapping(self.priority_p5, 5, mock_get_jira_user, mock_client)
|
|
73
|
-
|
|
74
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
75
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
76
|
-
def test_priority_invalid_value_fallback(self, mock_get_jira_user, mock_client):
|
|
77
|
-
"""Test that invalid priority values fall back to P1."""
|
|
78
|
-
# Create a priority with an invalid value (>5)
|
|
79
|
-
invalid_priority, _ = Priority.objects.get_or_create(
|
|
80
|
-
value=6, defaults={"name": "Invalid", "order": 6}
|
|
81
|
-
)
|
|
82
|
-
self._test_priority_mapping(invalid_priority, 1, mock_get_jira_user, mock_client) # Should fallback to 1
|
|
83
|
-
|
|
84
|
-
def _test_priority_mapping(self, priority: Priority, expected_jira_priority: int, mock_get_jira_user, mock_client):
|
|
85
|
-
"""Helper method to test priority mapping."""
|
|
86
|
-
# Create a real JiraUser for testing
|
|
87
|
-
jira_user = JiraUser.objects.create(id="test-user-id", user=self.user)
|
|
88
|
-
mock_get_jira_user.return_value = jira_user
|
|
89
|
-
|
|
90
|
-
# Mock the create_issue return value (exclude watchers as it's a ManyToMany field)
|
|
91
|
-
mock_client.create_issue.return_value = {
|
|
92
|
-
"id": "123456",
|
|
93
|
-
"key": "TEST-123",
|
|
94
|
-
"assignee": None,
|
|
95
|
-
"reporter": jira_user, # Return the actual JiraUser object
|
|
96
|
-
"issue_type": "Incident",
|
|
97
|
-
"project_key": "INCIDENT",
|
|
98
|
-
"description": "Test incident",
|
|
99
|
-
"summary": "Test Incident"
|
|
100
|
-
}
|
|
101
|
-
mock_client.get_jira_user_from_jira_id.return_value = jira_user
|
|
102
|
-
mock_client.jira.add_watcher = Mock()
|
|
103
|
-
mock_client.jira.remove_watcher = Mock()
|
|
104
|
-
mock_client.jira.add_simple_link = Mock()
|
|
105
|
-
|
|
106
|
-
# Create incident with the specific priority
|
|
107
|
-
incident = IncidentFactory(
|
|
108
|
-
priority=priority,
|
|
109
|
-
created_by=self.user,
|
|
110
|
-
title="Test Incident",
|
|
111
|
-
description="Test incident description"
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
# Create incident channel
|
|
115
|
-
channel = IncidentChannelFactory(incident=incident)
|
|
116
|
-
channel.add_bookmark = Mock()
|
|
117
|
-
channel.send_message_and_save = Mock()
|
|
118
|
-
|
|
119
|
-
# Call the create_ticket function
|
|
120
|
-
create_ticket(sender=None, incident=incident, channel=channel)
|
|
121
|
-
|
|
122
|
-
# Verify that create_issue was called with the expected priority
|
|
123
|
-
mock_client.create_issue.assert_called_once()
|
|
124
|
-
call_kwargs = mock_client.create_issue.call_args[1]
|
|
125
|
-
|
|
126
|
-
assert call_kwargs["priority"] == expected_jira_priority
|
|
127
|
-
assert call_kwargs["issuetype"] == "Incident"
|
|
128
|
-
assert call_kwargs["summary"] == "Test Incident"
|
|
129
|
-
|
|
130
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
131
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
132
|
-
def test_create_ticket_no_issue_id_error(self, mock_get_jira_user, mock_client):
|
|
133
|
-
"""Test error handling when create_issue returns no ID."""
|
|
134
|
-
test_user = UserFactory()
|
|
135
|
-
jira_user = JiraUser.objects.create(id="test-user-no-id", user=test_user)
|
|
136
|
-
mock_get_jira_user.return_value = jira_user
|
|
137
|
-
|
|
138
|
-
# Mock create_issue to return None ID (error case)
|
|
139
|
-
mock_client.create_issue.return_value = {
|
|
140
|
-
"id": None, # This should trigger the error
|
|
141
|
-
"key": "TEST-123",
|
|
142
|
-
"summary": "Test Incident"
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
incident = IncidentFactory(
|
|
146
|
-
priority=self.priority_p1,
|
|
147
|
-
created_by=test_user,
|
|
148
|
-
title="Test Incident"
|
|
149
|
-
)
|
|
150
|
-
channel = IncidentChannelFactory(incident=incident)
|
|
151
|
-
|
|
152
|
-
# Should raise JiraAPIError
|
|
153
|
-
with pytest.raises(JiraAPIError):
|
|
154
|
-
create_ticket(sender=None, incident=incident, channel=channel)
|
|
155
|
-
|
|
156
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
157
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
158
|
-
def test_create_ticket_jira_user_not_found_error(self, mock_get_jira_user, mock_client):
|
|
159
|
-
"""Test error handling when default JIRA user is not found."""
|
|
160
|
-
test_user = UserFactory()
|
|
161
|
-
jira_user = JiraUser.objects.create(id="test-user-not-found", user=test_user)
|
|
162
|
-
mock_get_jira_user.return_value = jira_user
|
|
163
|
-
|
|
164
|
-
mock_client.create_issue.return_value = {
|
|
165
|
-
"id": "123456",
|
|
166
|
-
"key": "TEST-123",
|
|
167
|
-
"reporter": jira_user,
|
|
168
|
-
"summary": "Test Incident"
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
# Mock get_jira_user_from_jira_id to raise JiraUserNotFoundError
|
|
172
|
-
mock_client.get_jira_user_from_jira_id.side_effect = JiraUserNotFoundError("User not found")
|
|
173
|
-
mock_client.jira.add_watcher = Mock()
|
|
174
|
-
mock_client.jira.remove_watcher = Mock()
|
|
175
|
-
mock_client.jira.add_simple_link = Mock()
|
|
176
|
-
|
|
177
|
-
incident = IncidentFactory(
|
|
178
|
-
priority=self.priority_p1,
|
|
179
|
-
created_by=test_user,
|
|
180
|
-
title="Test Incident"
|
|
181
|
-
)
|
|
182
|
-
channel = IncidentChannelFactory(incident=incident)
|
|
183
|
-
channel.add_bookmark = Mock()
|
|
184
|
-
channel.send_message_and_save = Mock()
|
|
185
|
-
|
|
186
|
-
# Should complete without error despite the exception
|
|
187
|
-
create_ticket(sender=None, incident=incident, channel=channel)
|
|
188
|
-
|
|
189
|
-
# Verify the ticket was still created
|
|
190
|
-
mock_client.create_issue.assert_called_once()
|
|
191
|
-
|
|
192
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
193
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
194
|
-
def test_create_ticket_add_watcher_error(self, mock_get_jira_user, mock_client):
|
|
195
|
-
"""Test error handling when adding watcher fails."""
|
|
196
|
-
test_user = UserFactory()
|
|
197
|
-
default_user = UserFactory()
|
|
198
|
-
jira_user = JiraUser.objects.create(id="test-user-add-watcher", user=test_user)
|
|
199
|
-
default_jira_user = JiraUser.objects.create(id="default-user-add", user=default_user)
|
|
200
|
-
mock_get_jira_user.return_value = jira_user
|
|
201
|
-
|
|
202
|
-
mock_client.create_issue.return_value = {
|
|
203
|
-
"id": "123456",
|
|
204
|
-
"key": "TEST-123",
|
|
205
|
-
"reporter": jira_user,
|
|
206
|
-
"summary": "Test Incident"
|
|
207
|
-
}
|
|
208
|
-
mock_client.get_jira_user_from_jira_id.return_value = default_jira_user
|
|
209
|
-
|
|
210
|
-
# Mock add_watcher to raise JiraAPIError
|
|
211
|
-
mock_client.jira.add_watcher.side_effect = JiraAPIError("Cannot add watcher")
|
|
212
|
-
mock_client.jira.remove_watcher = Mock()
|
|
213
|
-
mock_client.jira.add_simple_link = Mock()
|
|
214
|
-
|
|
215
|
-
incident = IncidentFactory(
|
|
216
|
-
priority=self.priority_p1,
|
|
217
|
-
created_by=test_user,
|
|
218
|
-
title="Test Incident"
|
|
219
|
-
)
|
|
220
|
-
channel = IncidentChannelFactory(incident=incident)
|
|
221
|
-
channel.add_bookmark = Mock()
|
|
222
|
-
channel.send_message_and_save = Mock()
|
|
223
|
-
|
|
224
|
-
# Should complete without error despite the exception
|
|
225
|
-
create_ticket(sender=None, incident=incident, channel=channel)
|
|
226
|
-
|
|
227
|
-
# Verify remove_watcher was called as fallback
|
|
228
|
-
mock_client.jira.remove_watcher.assert_called_once()
|
|
229
|
-
|
|
230
|
-
@patch("firefighter.raid.signals.incident_created.client")
|
|
231
|
-
@patch("firefighter.raid.signals.incident_created.get_jira_user_from_user")
|
|
232
|
-
def test_create_ticket_remove_watcher_error(self, mock_get_jira_user, mock_client):
|
|
233
|
-
"""Test error handling when removing default watcher fails."""
|
|
234
|
-
test_user = UserFactory()
|
|
235
|
-
default_user = UserFactory()
|
|
236
|
-
jira_user = JiraUser.objects.create(id="test-user-remove-watcher", user=test_user)
|
|
237
|
-
default_jira_user = JiraUser.objects.create(id="default-user-remove", user=default_user)
|
|
238
|
-
mock_get_jira_user.return_value = jira_user
|
|
239
|
-
|
|
240
|
-
mock_client.create_issue.return_value = {
|
|
241
|
-
"id": "123456",
|
|
242
|
-
"key": "TEST-123",
|
|
243
|
-
"reporter": jira_user,
|
|
244
|
-
"summary": "Test Incident"
|
|
245
|
-
}
|
|
246
|
-
mock_client.get_jira_user_from_jira_id.return_value = default_jira_user
|
|
247
|
-
|
|
248
|
-
# Mock both add_watcher and remove_watcher to raise JiraAPIError
|
|
249
|
-
mock_client.jira.add_watcher.side_effect = JiraAPIError("Cannot add watcher")
|
|
250
|
-
mock_client.jira.remove_watcher.side_effect = JiraAPIError("Cannot remove watcher")
|
|
251
|
-
mock_client.jira.add_simple_link = Mock()
|
|
252
|
-
|
|
253
|
-
incident = IncidentFactory(
|
|
254
|
-
priority=self.priority_p1,
|
|
255
|
-
created_by=test_user,
|
|
256
|
-
title="Test Incident"
|
|
257
|
-
)
|
|
258
|
-
channel = IncidentChannelFactory(incident=incident)
|
|
259
|
-
channel.add_bookmark = Mock()
|
|
260
|
-
channel.send_message_and_save = Mock()
|
|
261
|
-
|
|
262
|
-
# Should complete without error despite both exceptions
|
|
263
|
-
create_ticket(sender=None, incident=incident, channel=channel)
|
|
264
|
-
|
|
265
|
-
# Verify both operations were attempted
|
|
266
|
-
mock_client.jira.add_watcher.assert_called_once()
|
|
267
|
-
mock_client.jira.remove_watcher.assert_called_once()
|
|
File without changes
|
{firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{firefighter_incident-0.0.16.dist-info → firefighter_incident-0.0.17.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|