Skip to content

Commit

Permalink
Add tests for cancel workflow action
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel2392 committed Apr 11, 2024
1 parent 913353f commit 249d1c9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ classifiers =
Framework :: Django
Framework :: Django :: 4.2
Framework :: Wagtail
Framework :: Wagtail :: 5.2
Framework :: Wagtail :: 6.0
Framework :: Wagtail :: 5
Framework :: Wagtail :: 6
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)
Operating System :: OS Independent
Expand Down
59 changes: 52 additions & 7 deletions wagtail_fedit/test/core/tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
)
from wagtail.models import (
Workflow,
WorkflowTask,
WorkflowContentType,
GroupApprovalTask,
)
from .base import (
BaseFEditTest,
Expand All @@ -12,7 +14,7 @@
PublishView,
SubmitView,
UnpublishView,
# CancelView,
CancelView,
)


Expand Down Expand Up @@ -76,21 +78,43 @@ def test_submit(self):
workflow = self.full_model.get_workflow()
self.assertIsNone(workflow)

workflow = Workflow.objects.create(name="test_workflow")
workflow = Workflow.objects.get_or_create(name="test_workflow")[0]
workflow_task = GroupApprovalTask.objects.create(name="test_task_1")
content_type = ContentType.objects.get_for_model(self.full_model.__class__)
WorkflowContentType.objects.create(content_type=content_type, workflow=workflow)
WorkflowTask.objects.create(
workflow=workflow, task=workflow_task, sort_order=1
)

wf = self.full_model.get_workflow()
self.assertIsNotNone(wf)
self.assertEqual(wf, workflow)
self.assertFalse(not not self.full_model.workflow_states)
self.assertFalse(not not self.full_model.workflow_states.all())

self.makeRequest("submit", self.full_model, SubmitView, 302)

self.full_model.refresh_from_db()
self.full_model = self.full_model.__class__.objects.get(pk=self.full_model.pk)
workflow: Workflow = self.full_model.get_workflow()
self.assertTrue(not not self.full_model.workflow_states)

current_state = self.full_model.workflow_states.first()

self.assertEqual(
current_state.status,
current_state.STATUS_IN_PROGRESS,
)

def test_cancel(self):
self.test_submit()

self.makeRequest("cancel", self.full_model, CancelView, 302)

self.full_model.refresh_from_db()

current_state = self.full_model.workflow_states.first()
self.assertEqual(
current_state.status,
current_state.STATUS_CANCELLED,
)

def test_lock_nopublish(self):
self.client.force_login(self.other_admin_user)

Expand Down Expand Up @@ -129,9 +153,30 @@ def test_lock_nounpublish(self):
def test_lock_nosubmit(self):
self.client.force_login(self.admin_user)

self.makeRequest("submit", self.full_model, SubmitView, 200)
self.makeRequest("submit", self.lock_model, SubmitView, 200)

self.lock_model.refresh_from_db()

self.assertTrue(self.lock_model.has_unpublished_changes)
self.assertFalse(not not self.lock_model.workflow_states)

def test_lock_nocancel(self):
self.lock_model.locked = False
self.lock_model.locked_by = None
self.lock_model.save(update_fields=["locked", "locked_by"])

self.test_submit()

self.lock_model.locked = True
self.lock_model.locked_by = self.other_admin_user
self.lock_model.save(update_fields=["locked", "locked_by"])

self.makeRequest("cancel", self.lock_model, CancelView, 200)

self.lock_model.refresh_from_db()
current_state = self.full_model.workflow_states.first()

self.assertEqual(
current_state.status,
current_state.STATUS_IN_PROGRESS,
)

0 comments on commit 249d1c9

Please sign in to comment.