Skip to content

Commit

Permalink
Update TaskWorkflowTemplate.create_task_workflow() method and unit te…
Browse files Browse the repository at this point in the history
…st (#1339)

* Save Workflow instance in forward op to fix migration application

* Have TaskWorkflowTemplate.create_task_workflow() create summary task from data param

* Make explicit create_task_workflow() params
  • Loading branch information
dalecannon authored Nov 28, 2024
1 parent 7dfe059 commit 997d36a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tasks/migrations/0012_taskworkflow_assign_summary_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def assign_new_summary_task_on_workflow(apps, schema_editor):
title="Workflow summarising task",
description="Workflow summarising task.",
)
TaskWorkflow.save()
task_workflow.save()


class Migration(migrations.Migration):
Expand Down
6 changes: 3 additions & 3 deletions tasks/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def get_task_templates(self) -> models.QuerySet:
)

@atomic
def create_task_workflow(self) -> "TaskWorkflow":
def create_task_workflow(self, title: str, description: str) -> "TaskWorkflow":
"""Create a workflow and it subtasks, using values from this template
workflow and its task templates."""

summary_task = Task.objects.create(title=title, description=description)
task_workflow = TaskWorkflow.objects.create(
title=self.title,
description=self.description,
summary_task=summary_task,
creator_template=self,
)

Expand Down
14 changes: 8 additions & 6 deletions tasks/tests/test_workflow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ def test_create_task_workflow_from_task_workflow_template(
):
"""Test creation of TaskWorkflow instances from TaskWorkflowTemplates using
its `create_task_workflow()` method."""
title = "Workflow title"
description = "Workflow description"
task_workflow = (
task_workflow_template_three_task_template_items.create_task_workflow()
task_workflow_template_three_task_template_items.create_task_workflow(
title=title,
description=description,
)
)

# Test that workflow values are valid.
assert (
task_workflow.creator_template
== task_workflow_template_three_task_template_items
)
assert task_workflow.title == task_workflow_template_three_task_template_items.title
assert (
task_workflow.description
== task_workflow_template_three_task_template_items.description
)
assert task_workflow.summary_task.title == title
assert task_workflow.summary_task.description == description
assert task_workflow.get_items().count() == 3

# Validate that item positions are equivalent.
Expand Down

0 comments on commit 997d36a

Please sign in to comment.