Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TaskWorkflowTemplate.create_task_workflow() method and unit test #1339

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 9 additions & 5 deletions tasks/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ def get_task_templates(self) -> models.QuerySet:
)

@atomic
def create_task_workflow(self) -> "TaskWorkflow":
"""Create a workflow and it subtasks, using values from this template
workflow and its task templates."""
def create_task_workflow(self, summary_data: dict) -> "TaskWorkflow":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be preferable, better documenting this API, to be explicit stating which fields are required or expected to create a TaskWorkflow, with TaskWorkflow.summary_task being kept as an internal detail?

Suggested change
def create_task_workflow(self, summary_data: dict) -> "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.

The `summary_data` param is used to populate the details of the `TaskWorkflow.summary_task` instance.
"""

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

Expand Down
15 changes: 9 additions & 6 deletions tasks/tests/test_workflow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ def test_create_task_workflow_from_task_workflow_template(
):
"""Test creation of TaskWorkflow instances from TaskWorkflowTemplates using
its `create_task_workflow()` method."""
summary_data = {
"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(
summary_data,
)
)

# 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 == summary_data["title"]
assert task_workflow.summary_task.description == summary_data["description"]
assert task_workflow.get_items().count() == 3

# Validate that item positions are equivalent.
Expand Down