Skip to content

Commit b7bb101

Browse files
committed
When move task to Todo, make it completed
1 parent 797220b commit b7bb101

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

backend/tasks/models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class EisenhowerMatrix(models.IntegerChoices):
8181
priority = models.PositiveSmallIntegerField(choices=EisenhowerMatrix.choices, default=EisenhowerMatrix.NOT_IMPORTANT_NOT_URGENT)
8282

8383
def save(self, *args, **kwargs):
84+
done_list_name = "Done"
85+
if self.list_board.name == done_list_name:
86+
self.completed = True
87+
Todo.objects.filter(list_board=self.list_board).update(completed=True)
88+
8489
if self.completed and not self.completion_date:
8590
self.completion_date = timezone.now()
8691
elif not self.completed:
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from datetime import datetime, timedelta
2+
from django.urls import reverse
3+
from rest_framework import status
4+
from rest_framework.test import APITestCase
5+
from tasks.tests.utils import create_test_user
6+
from tasks.models import Todo
7+
from boards.models import ListBoard, Board
8+
9+
10+
class TodoSignalHandlersTests(APITestCase):
11+
def setUp(self):
12+
self.user = create_test_user()
13+
self.client.force_authenticate(user=self.user)
14+
self.list_board = Board.objects.get(user=self.user).listboard_set.first()
15+
16+
def test_update_priority_signal_handler(self):
17+
"""
18+
Test the behavior of the update_priority signal handler.
19+
"""
20+
due_date = datetime.now() + timedelta(days=5)
21+
data = {
22+
'title': 'Test Task',
23+
'type': 'habit',
24+
'difficulty': 1,
25+
'end_event': due_date.strftime('%Y-%m-%dT%H:%M:%S'),
26+
'list_board': self.list_board.id,
27+
}
28+
response = self.client.post(reverse("todo-list"), data, format='json')
29+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
30+
31+
# Retrieve the created task and check if priority is updated
32+
task = Todo.objects.get(title='Test Task')
33+
self.assertIsNotNone(task.priority) # Check if priority is not None

0 commit comments

Comments
 (0)