diff --git a/setup.cfg b/setup.cfg index 2b4b2ca..4db4734 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/wagtail_fedit/test/core/tests/test_submit.py b/wagtail_fedit/test/core/tests/test_submit.py index 263fc7e..c0b5e90 100644 --- a/wagtail_fedit/test/core/tests/test_submit.py +++ b/wagtail_fedit/test/core/tests/test_submit.py @@ -3,7 +3,9 @@ ) from wagtail.models import ( Workflow, + WorkflowTask, WorkflowContentType, + GroupApprovalTask, ) from .base import ( BaseFEditTest, @@ -12,7 +14,7 @@ PublishView, SubmitView, UnpublishView, - # CancelView, + CancelView, ) @@ -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) @@ -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, + )