|
8 | 8 | from sentry.workflow_engine.models import (
|
9 | 9 | Action,
|
10 | 10 | DataConditionGroup,
|
| 11 | + Workflow, |
11 | 12 | WorkflowActionGroupStatus,
|
12 | 13 | WorkflowFireHistory,
|
13 | 14 | )
|
|
16 | 17 | create_workflow_fire_histories,
|
17 | 18 | filter_recently_fired_actions,
|
18 | 19 | filter_recently_fired_workflow_actions,
|
| 20 | + get_workflow_group_action_statuses, |
19 | 21 | is_action_permitted,
|
| 22 | + update_workflow_action_group_statuses, |
20 | 23 | )
|
21 | 24 | from sentry.workflow_engine.types import WorkflowEventData
|
22 | 25 | from tests.sentry.workflow_engine.test_base import BaseWorkflowTest
|
@@ -193,6 +196,63 @@ def test_multiple_workflows_single_action__later_fire(self):
|
193 | 196 | status.refresh_from_db()
|
194 | 197 | assert status.date_updated == timezone.now() - timedelta(hours=1)
|
195 | 198 |
|
| 199 | + def test_get_workflow_group_action_statuses(self): |
| 200 | + workflow = self.create_workflow(organization=self.organization) |
| 201 | + WorkflowActionGroupStatus.objects.create( |
| 202 | + workflow=workflow, action=self.action, group=self.group |
| 203 | + ) |
| 204 | + status = WorkflowActionGroupStatus.objects.create( |
| 205 | + workflow=self.workflow, action=self.action, group=self.group |
| 206 | + ) |
| 207 | + |
| 208 | + action_to_statuses = get_workflow_group_action_statuses( |
| 209 | + {self.action.id: {self.workflow.id}}, self.group |
| 210 | + ) |
| 211 | + assert action_to_statuses == {self.action.id: [status]} |
| 212 | + |
| 213 | + def test_update_workflow_action_group_statuses(self): |
| 214 | + workflow = self.create_workflow(organization=self.organization, config={"frequency": 1440}) |
| 215 | + action_group = self.create_data_condition_group(logic_type="any-short") |
| 216 | + self.create_data_condition_group_action( |
| 217 | + condition_group=action_group, |
| 218 | + action=self.action, |
| 219 | + ) # shared action |
| 220 | + self.create_workflow_data_condition_group(workflow, action_group) |
| 221 | + status = WorkflowActionGroupStatus.objects.create( |
| 222 | + workflow=workflow, action=self.action, group=self.group |
| 223 | + ) |
| 224 | + status.update(date_updated=timezone.now() - timedelta(hours=1)) |
| 225 | + |
| 226 | + _, action = self.create_workflow_action(workflow=workflow) |
| 227 | + status_2 = WorkflowActionGroupStatus.objects.create( |
| 228 | + workflow=workflow, action=action, group=self.group |
| 229 | + ) |
| 230 | + status_2.update(date_updated=timezone.now() - timedelta(days=1)) |
| 231 | + |
| 232 | + action_to_workflows_ids = {action.id: {workflow.id}, self.action.id: {self.workflow.id}} |
| 233 | + action_to_statuses = {action.id: [status, status_2]} |
| 234 | + workflows = Workflow.objects.all() |
| 235 | + action_ids = update_workflow_action_group_statuses( |
| 236 | + action_to_workflows_ids, action_to_statuses, workflows, self.group |
| 237 | + ) |
| 238 | + assert action_ids == {action.id, self.action.id} |
| 239 | + |
| 240 | + status_2.refresh_from_db() |
| 241 | + assert status_2.date_updated == timezone.now() |
| 242 | + |
| 243 | + status.refresh_from_db() |
| 244 | + assert status.date_updated == timezone.now() - timedelta(hours=1) # not updated |
| 245 | + |
| 246 | + assert ( |
| 247 | + WorkflowActionGroupStatus.objects.filter( |
| 248 | + workflow=self.workflow, |
| 249 | + action=self.action, |
| 250 | + group=self.group, |
| 251 | + date_updated=timezone.now(), |
| 252 | + ).count() |
| 253 | + == 1 |
| 254 | + ) # created new status |
| 255 | + |
196 | 256 |
|
197 | 257 | class TestWorkflowFireHistory(BaseWorkflowTest):
|
198 | 258 | def setUp(self):
|
|
0 commit comments