Skip to content

Commit 997d36a

Browse files
authored
Update TaskWorkflowTemplate.create_task_workflow() method and unit test (#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
1 parent 7dfe059 commit 997d36a

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

tasks/migrations/0012_taskworkflow_assign_summary_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def assign_new_summary_task_on_workflow(apps, schema_editor):
1212
title="Workflow summarising task",
1313
description="Workflow summarising task.",
1414
)
15-
TaskWorkflow.save()
15+
task_workflow.save()
1616

1717

1818
class Migration(migrations.Migration):

tasks/models/workflow.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ def get_task_templates(self) -> models.QuerySet:
9191
)
9292

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

98+
summary_task = Task.objects.create(title=title, description=description)
9899
task_workflow = TaskWorkflow.objects.create(
99-
title=self.title,
100-
description=self.description,
100+
summary_task=summary_task,
101101
creator_template=self,
102102
)
103103

tasks/tests/test_workflow_models.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,22 @@ def test_create_task_workflow_from_task_workflow_template(
1313
):
1414
"""Test creation of TaskWorkflow instances from TaskWorkflowTemplates using
1515
its `create_task_workflow()` method."""
16+
title = "Workflow title"
17+
description = "Workflow description"
1618
task_workflow = (
17-
task_workflow_template_three_task_template_items.create_task_workflow()
19+
task_workflow_template_three_task_template_items.create_task_workflow(
20+
title=title,
21+
description=description,
22+
)
1823
)
1924

2025
# Test that workflow values are valid.
2126
assert (
2227
task_workflow.creator_template
2328
== task_workflow_template_three_task_template_items
2429
)
25-
assert task_workflow.title == task_workflow_template_three_task_template_items.title
26-
assert (
27-
task_workflow.description
28-
== task_workflow_template_three_task_template_items.description
29-
)
30+
assert task_workflow.summary_task.title == title
31+
assert task_workflow.summary_task.description == description
3032
assert task_workflow.get_items().count() == 3
3133

3234
# Validate that item positions are equivalent.

0 commit comments

Comments
 (0)