mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
Fix task_states_with_status to get only latest task state status for task (#6138)
Get status from latest task state only when annotating task states with statuses
This commit is contained in:
parent
74a8cf8036
commit
5be2d6df56
@ -2970,7 +2970,9 @@ class WorkflowState(models.Model):
|
||||
status=Subquery(
|
||||
task_states.filter(
|
||||
task_id=OuterRef('id'),
|
||||
).values('status')
|
||||
).order_by(
|
||||
'-started_at', '-id'
|
||||
).values('status')[:1]
|
||||
),
|
||||
)
|
||||
)
|
||||
|
@ -202,6 +202,31 @@ class TestWorkflows(TestCase):
|
||||
self.assertEqual(workflow_state.current_task_state.status, workflow_state.current_task_state.STATUS_IN_PROGRESS)
|
||||
self.assertEqual(workflow_state.current_task_state.task, task_2)
|
||||
|
||||
def test_tasks_with_status_on_resubmission(self):
|
||||
# test that a Workflow rejected and resumed shows the status of the latest tasks when _`all_tasks_with_status` is called
|
||||
data = self.start_workflow_on_homepage()
|
||||
workflow_state = data['workflow_state']
|
||||
|
||||
tasks = workflow_state.all_tasks_with_status()
|
||||
self.assertEqual(tasks[0].status, TaskState.STATUS_IN_PROGRESS)
|
||||
self.assertEqual(tasks[1].status_display, 'Not started')
|
||||
|
||||
workflow_state.current_task_state.approve(user=None)
|
||||
workflow_state.refresh_from_db()
|
||||
|
||||
workflow_state.current_task_state.reject(user=None)
|
||||
workflow_state.refresh_from_db()
|
||||
|
||||
tasks = workflow_state.all_tasks_with_status()
|
||||
self.assertEqual(tasks[0].status, TaskState.STATUS_APPROVED)
|
||||
self.assertEqual(tasks[1].status, TaskState.STATUS_REJECTED)
|
||||
|
||||
workflow_state.resume(user=None)
|
||||
|
||||
tasks = workflow_state.all_tasks_with_status()
|
||||
self.assertEqual(tasks[0].status, TaskState.STATUS_APPROVED)
|
||||
self.assertEqual(tasks[1].status, TaskState.STATUS_IN_PROGRESS)
|
||||
|
||||
def cancel_workflow(self):
|
||||
# test that cancelling a workflow state sets both current task state and its own statuses to cancelled, and cancels all in progress states
|
||||
data = self.start_workflow_on_homepage()
|
||||
|
Loading…
Reference in New Issue
Block a user