kopia lustrzana https://github.com/wagtail/wagtail
Add tests for Workflow and Task creation and linking, and change related_names to be more usable
rodzic
788dd8fb5c
commit
b8cebad1ea
|
@ -358,7 +358,8 @@ class Page(AbstractPage, index.Indexed, ClusterableModel, metaclass=PageBase):
|
|||
related_name='pages',
|
||||
verbose_name=_('workflow'),
|
||||
on_delete=models.SET_NULL,
|
||||
null=True
|
||||
null=True,
|
||||
blank=True,
|
||||
)
|
||||
|
||||
search_fields = [
|
||||
|
@ -2391,8 +2392,8 @@ class GroupCollectionPermission(models.Model):
|
|||
|
||||
|
||||
class WorkflowTask(models.Model):
|
||||
workflow = models.ForeignKey('Workflow', on_delete=models.CASCADE, verbose_name=_('workflow'))
|
||||
task = models.ForeignKey('Task', on_delete=models.CASCADE, verbose_name=_('task'))
|
||||
workflow = models.ForeignKey('Workflow', on_delete=models.CASCADE, verbose_name=_('workflow_tasks'))
|
||||
task = models.ForeignKey('Task', on_delete=models.CASCADE, verbose_name=_('task'), related_name='workflow_tasks')
|
||||
sort_order = models.PositiveIntegerField(verbose_name=_('priority'))
|
||||
|
||||
class Meta:
|
||||
|
@ -2452,7 +2453,7 @@ class Task(models.Model):
|
|||
|
||||
class Workflow(models.Model):
|
||||
name = models.CharField(max_length=255, verbose_name=_('name'))
|
||||
tasks = models.ManyToManyField(Task, through=WorkflowTask)
|
||||
tasks = models.ManyToManyField(Task, through=WorkflowTask, related_name='workflows')
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
from django.test import TestCase
|
||||
|
||||
from wagtail.core.models import Task, Workflow, WorkflowTask
|
||||
|
||||
|
||||
class TestPageQuerySet(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
||||
def test_create_workflow(self):
|
||||
# test creating and retrieving an empty workflow from the db
|
||||
test_workflow = Workflow(name='test_workflow')
|
||||
test_workflow.save()
|
||||
retrieved_workflow = Workflow.objects.get(id=test_workflow.id)
|
||||
self.assertEqual(retrieved_workflow.name, 'test_workflow')
|
||||
|
||||
def test_create_task(self):
|
||||
# test creating and retrieving a base task from the db
|
||||
test_task = Task(name='test_task')
|
||||
test_task.save()
|
||||
retrieved_task = Task.objects.get(id=test_task.id)
|
||||
self.assertEqual(retrieved_task.name, 'test_task')
|
||||
|
||||
def test_add_task_to_workflow(self):
|
||||
workflow = Workflow.objects.create(name='test_workflow')
|
||||
task = Task.objects.create(name='test_task')
|
||||
workflow_task = WorkflowTask.objects.create(workflow=workflow, task=task, sort_order=1)
|
||||
self.assertIn(task, workflow.tasks.all())
|
||||
self.assertIn(workflow, task.workflows.all())
|
Ładowanie…
Reference in New Issue