mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44:07 +01:00
When move task to Todo, make it completed
This commit is contained in:
parent
797220b0a6
commit
b7bb101759
@ -81,6 +81,11 @@ class Todo(Task):
|
|||||||
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
|
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
done_list_name = "Done"
|
||||||
|
if self.list_board.name == done_list_name:
|
||||||
|
self.completed = True
|
||||||
|
Todo.objects.filter(list_board=self.list_board).update(completed=True)
|
||||||
|
|
||||||
if self.completed and not self.completion_date:
|
if self.completed and not self.completion_date:
|
||||||
self.completion_date = timezone.now()
|
self.completion_date = timezone.now()
|
||||||
elif not self.completed:
|
elif not self.completed:
|
||||||
|
|||||||
33
backend/tasks/tests/test_todo_signal.py
Normal file
33
backend/tasks/tests/test_todo_signal.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
from datetime import datetime, timedelta
|
||||||
|
from django.urls import reverse
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
from tasks.tests.utils import create_test_user
|
||||||
|
from tasks.models import Todo
|
||||||
|
from boards.models import ListBoard, Board
|
||||||
|
|
||||||
|
|
||||||
|
class TodoSignalHandlersTests(APITestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.user = create_test_user()
|
||||||
|
self.client.force_authenticate(user=self.user)
|
||||||
|
self.list_board = Board.objects.get(user=self.user).listboard_set.first()
|
||||||
|
|
||||||
|
def test_update_priority_signal_handler(self):
|
||||||
|
"""
|
||||||
|
Test the behavior of the update_priority signal handler.
|
||||||
|
"""
|
||||||
|
due_date = datetime.now() + timedelta(days=5)
|
||||||
|
data = {
|
||||||
|
'title': 'Test Task',
|
||||||
|
'type': 'habit',
|
||||||
|
'difficulty': 1,
|
||||||
|
'end_event': due_date.strftime('%Y-%m-%dT%H:%M:%S'),
|
||||||
|
'list_board': self.list_board.id,
|
||||||
|
}
|
||||||
|
response = self.client.post(reverse("todo-list"), data, format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
|
||||||
|
# Retrieve the created task and check if priority is updated
|
||||||
|
task = Todo.objects.get(title='Test Task')
|
||||||
|
self.assertIsNotNone(task.priority) # Check if priority is not None
|
||||||
Loading…
Reference in New Issue
Block a user