Skip to content

Commit 441484a

Browse files
committed
test sub functions
1 parent ffcbecb commit 441484a

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/sentry/workflow_engine/processors/action.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def filter_recently_fired_actions(
138138
return filtered_actions
139139

140140

141-
def get_workflow_group_action_statuses(action_to_workflows_ids: dict[int, set[int]], group: Group):
141+
def get_workflow_group_action_statuses(
142+
action_to_workflows_ids: dict[int, set[int]], group: Group
143+
) -> dict[int, list[WorkflowActionGroupStatus]]:
142144
all_statuses = WorkflowActionGroupStatus.objects.filter(
143145
group=group, action_id__in=action_to_workflows_ids.keys()
144146
)

tests/sentry/workflow_engine/processors/test_action.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from sentry.workflow_engine.models import (
99
Action,
1010
DataConditionGroup,
11+
Workflow,
1112
WorkflowActionGroupStatus,
1213
WorkflowFireHistory,
1314
)
@@ -16,7 +17,9 @@
1617
create_workflow_fire_histories,
1718
filter_recently_fired_actions,
1819
filter_recently_fired_workflow_actions,
20+
get_workflow_group_action_statuses,
1921
is_action_permitted,
22+
update_workflow_action_group_statuses,
2023
)
2124
from sentry.workflow_engine.types import WorkflowEventData
2225
from tests.sentry.workflow_engine.test_base import BaseWorkflowTest
@@ -193,6 +196,63 @@ def test_multiple_workflows_single_action__later_fire(self):
193196
status.refresh_from_db()
194197
assert status.date_updated == timezone.now() - timedelta(hours=1)
195198

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+
196256

197257
class TestWorkflowFireHistory(BaseWorkflowTest):
198258
def setUp(self):

0 commit comments

Comments
 (0)