0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

Add tests for task views

This commit is contained in:
jacobtm 2019-11-25 12:08:44 +00:00 committed by Matt Westcott
parent 30dfaf3661
commit a10db70dfd
2 changed files with 127 additions and 2 deletions

View File

@ -1,7 +1,7 @@
from django.test import TestCase
from django.urls import reverse
from wagtail.core.models import Page, Task, Workflow, WorkflowPage, WorkflowTask
from wagtail.core.models import GroupApprovalTask, Page, Task, Workflow, WorkflowPage, WorkflowTask
from wagtail.tests.testapp.models import SimpleTask
from wagtail.tests.utils import WagtailTestUtils
@ -190,3 +190,128 @@ class TestAddWorkflowToPage(TestCase, WagtailTestUtils):
self.assertEqual(WorkflowPage.objects.filter(workflow=self.workflow, page=self.other_page).count(), 1)
class TestRemoveWorkflow(TestCase, WagtailTestUtils):
fixtures = ['test.json']
def setUp(self):
self.login()
self.workflow = Workflow.objects.create(name="workflow")
self.page = Page.objects.first()
WorkflowPage.objects.create(workflow=self.workflow, page=self.page)
def post(self, post_data={}):
return self.client.post(reverse('wagtailadmin_workflows:remove', args=[self.workflow.id, self.page.id]), post_data)
def test_post(self):
# Check that a WorkflowPage instance is removed correctly
response = self.post()
self.assertEqual(WorkflowPage.objects.filter(workflow=self.workflow, page=self.page).count(), 0)
class TestTaskIndexView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get(self, params={}):
return self.client.get(reverse('wagtailadmin_workflows:task_index'), params)
def test_simple(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/workflows/task_index.html')
# Initially there should be no tasks listed
self.assertContains(response, "No tasks have been created.")
SimpleTask.objects.create(name="test_task", active=True)
# Now the listing should contain our task
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/workflows/task_index.html')
self.assertNotContains(response, "No tasks have been created.")
self.assertContains(response, "test_task")
def test_deactivated(self):
Task.objects.create(name="test_task", active=False)
# The listing should contain our workflow, as well as marking it as disabled
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, "No tasks have been created.")
self.assertContains(response, "test_task")
self.assertContains(response, "disabled")
class TestCreateTaskView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get(self, params={}):
return self.client.get(reverse('wagtailadmin_workflows:add_task', kwargs={'app_label': SimpleTask._meta.app_label, 'model_name': SimpleTask._meta.model_name}), params)
def post(self, post_data={}):
return self.client.post(reverse('wagtailadmin_workflows:add_task', kwargs={'app_label': SimpleTask._meta.app_label, 'model_name': SimpleTask._meta.model_name}), post_data)
def test_get(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/workflows/create_task.html')
def test_post(self):
response = self.post({'name': 'test_task', 'active': 'on'})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailadmin_workflows:task_index'))
# Check that the task was created
tasks = Task.objects.filter(name="test_task", active=True)
self.assertEqual(tasks.count(), 1)
class TestSelectTaskTypeView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
def get(self):
return self.client.get(reverse('wagtailadmin_workflows:select_task_type'))
def test_get(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/workflows/select_task_type.html')
# Check that the list of available task types includes SimpleTask and GroupApprovalTask
self.assertContains(response, SimpleTask.get_verbose_name())
self.assertContains(response, GroupApprovalTask.get_verbose_name())
class TestEditTaskView(TestCase, WagtailTestUtils):
def setUp(self):
self.login()
self.task = SimpleTask.objects.create(name="test_task")
def get(self, params={}):
return self.client.get(reverse('wagtailadmin_workflows:edit_task', args=[self.task.id]), params)
def post(self, post_data={}):
return self.client.post(reverse('wagtailadmin_workflows:edit_task', args=[self.task.id]), post_data)
def test_get(self):
response = self.get()
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'wagtailadmin/workflows/edit_task.html')
def test_post(self):
response = self.post({'name': 'test_task_modified', 'active': 'on'})
# Should redirect back to index
self.assertRedirects(response, reverse('wagtailadmin_workflows:task_index'))
# Check that the task was updated
task = Task.objects.get(id=self.task.id)
self.assertEqual(task.name, "test_task_modified")

View File

@ -126,7 +126,7 @@ def remove_workflow(request, page_pk, workflow_pk=None):
if redirect_to and is_safe_url(url=redirect_to, allowed_hosts={request.get_host()}):
return redirect(redirect_to)
else:
return redirect('wagtailadmin_explore', page.get_parent().id)
return redirect('wagtailadmin_explore', page.id)
def add_to_page(request, workflow_pk):