|
| 1 | +from unittest import mock |
| 2 | + |
| 3 | +from sentry.issues.status_change_consumer import update_status |
| 4 | +from sentry.issues.status_change_message import StatusChangeMessageData |
| 5 | +from sentry.models.group import GroupStatus |
| 6 | +from sentry.testutils.cases import TestCase |
| 7 | +from sentry.types.activity import ActivityType |
| 8 | +from sentry.types.group import GroupSubStatus |
| 9 | +from sentry.workflow_engine.tasks import workflow_status_update_handler |
| 10 | + |
| 11 | + |
| 12 | +class IssuePlatformIntegrationTests(TestCase): |
| 13 | + def test_handler_invoked__when_resolved(self): |
| 14 | + """ |
| 15 | + Integration test to ensure the `update_status` method |
| 16 | + will correctly invoke the `workflow_state_update_handler` |
| 17 | + and increment the metric. |
| 18 | + """ |
| 19 | + detector = self.create_detector() |
| 20 | + group = self.create_group( |
| 21 | + project=self.project, |
| 22 | + status=GroupStatus.UNRESOLVED, |
| 23 | + substatus=GroupSubStatus.ESCALATING, |
| 24 | + ) |
| 25 | + |
| 26 | + message = StatusChangeMessageData( |
| 27 | + id="test_message_id", |
| 28 | + project_id=self.project.id, |
| 29 | + new_status=GroupStatus.RESOLVED, |
| 30 | + new_substatus=None, |
| 31 | + fingerprint=["test_fingerprint"], |
| 32 | + detector_id=detector.id, |
| 33 | + ) |
| 34 | + |
| 35 | + with mock.patch("sentry.workflow_engine.tasks.metrics.incr") as mock_incr: |
| 36 | + update_status(group, message) |
| 37 | + mock_incr.assert_called_with( |
| 38 | + "workflow_engine.process_workflow.activity_update", |
| 39 | + tags={"activity_type": ActivityType.SET_RESOLVED.value}, |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +def WorkflowStatusUpdateHandlerTests(TestCase): |
| 44 | + def test__no_detector_id(self): |
| 45 | + """ |
| 46 | + Test that the workflow_status_update_handler does not crash |
| 47 | + when no detector_id is provided in the status change message. |
| 48 | + """ |
| 49 | + group = self.create_group(project=self.project) |
| 50 | + activity = self.create_activity( |
| 51 | + group=group, |
| 52 | + type=ActivityType.SET_RESOLVED, |
| 53 | + data={"fingerprint": ["test_fingerprint"]}, |
| 54 | + ) |
| 55 | + |
| 56 | + message = StatusChangeMessageData( |
| 57 | + id="test_message_id", |
| 58 | + project_id=self.project.id, |
| 59 | + new_status=GroupStatus.RESOLVED, |
| 60 | + new_substatus=None, |
| 61 | + fingerprint=["test_fingerprint"], |
| 62 | + detector_id=None, # No detector_id provided |
| 63 | + ) |
| 64 | + |
| 65 | + with mock.patch("sentry.workflow_engine.tasks.metrics.incr") as mock_incr: |
| 66 | + workflow_status_update_handler(group, message, activity) |
| 67 | + mock_incr.assert_called_with( |
| 68 | + "workflow_engine.error.tasks.no_detector_id", |
| 69 | + tags={"activity_type": ActivityType.SET_RESOLVED.value}, |
| 70 | + ) |
0 commit comments