From 4f648a13891c6df6d31b5a11ca0d0092a021d0e7 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Mon, 24 Jul 2023 15:02:23 +0300 Subject: [PATCH] Add the Tasks model to manage tasks. --- CHANGELOG.org | 2 ++ tasks/models.py | 5 +++++ tasks/tests/test_task.py | 2 +- tasks/tests/test_tasks.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tasks/tests/test_tasks.py diff --git a/CHANGELOG.org b/CHANGELOG.org index 5b205f5..a2f32d9 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -34,4 +34,6 @@ Update the database to use Postgres. ** 0.3.9 <2023-07-24 Mon> Add the CI/CD configuration. +** 0.3.10 <2023-07-24 Mon> + Add the Tasks model to manage tasks. diff --git a/tasks/models.py b/tasks/models.py index 69486d5..7be0726 100644 --- a/tasks/models.py +++ b/tasks/models.py @@ -45,3 +45,8 @@ class Task(models.Model): self.status = self.circular_next_status() self.save() +class Tasks: + @staticmethod + def get_count_by_status(status: str): + return Task.objects.filter(status=status).count() + diff --git a/tasks/tests/test_task.py b/tasks/tests/test_task.py index bb2bbda..e5bc985 100644 --- a/tasks/tests/test_task.py +++ b/tasks/tests/test_task.py @@ -1,5 +1,5 @@ from django.test import TestCase -from tasks.models import Task, Tasks +from tasks.models import Task class TaskTestCase(TestCase): def setUp(self): diff --git a/tasks/tests/test_tasks.py b/tasks/tests/test_tasks.py new file mode 100644 index 0000000..2ff2cb7 --- /dev/null +++ b/tasks/tests/test_tasks.py @@ -0,0 +1,29 @@ +from django.test import TestCase +from tasks.models import Task, Tasks + +class TasksTestCase(TestCase): + todo_count = 2 + doing_count = 3 + done_count = 4 + cancel_count = 1 + + def setUp(self): + names = [f"Test Task {i}" for i in range(10)] + description = "" + + statuses = ["TODO"] * self.todo_count + statuses += ["DOING"] * self.doing_count + statuses += ["DONE"] * self.done_count + statuses += ["CANCELED"] * self.cancel_count + + tasks = [ + Task(name=name, description=description, status=status) + for name, status in zip(names, statuses) + ] + + Task.objects.bulk_create(tasks) + + def test_done_count(self): + count = Tasks.get_count_by_status("DONE") + self.assertEqual(count, self.done_count) +