Skip to content

Commit 9be84f2

Browse files
committed
Add test case to check if extension duration is recorded
1 parent 0f5b2eb commit 9be84f2

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

tests/backend/integration/api/tasks/test_actions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ def test_mapping_unlock_returns_200_on_success(self):
578578
self.assertEqual(last_task_history["action"], TaskAction.STATE_CHANGE.name)
579579
self.assertEqual(last_task_history["actionText"], TaskStatus.MAPPED.name)
580580
self.assertEqual(last_task_history["actionBy"], self.test_user.username)
581+
# Check if lock duration is saved
582+
# Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING"
583+
# we need to look for second entry in task history
584+
self.assertIsNotNone(response.json[1]["taskHistory"]["actionText"])
581585

582586
def test_mapping_unlock_returns_200_on_success_with_comment(self):
583587
"""Test returns 200 on success."""
@@ -610,6 +614,11 @@ def test_mapping_unlock_returns_200_on_success_with_comment(self):
610614
self.assertEqual(last_comment_history["actionText"], "cannot map")
611615
self.assertEqual(last_comment_history["actionBy"], self.test_user.username)
612616

617+
# Check if lock duration is saved
618+
# Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING"
619+
# we need to look for third entry in task history as second entry is comment
620+
self.assertIsNotNone(response.json[2]["taskHistory"]["actionText"])
621+
613622

614623
class TestTasksActionsMappingStopAPI(BaseTestCase):
615624
def setUp(self):
@@ -1243,6 +1252,11 @@ def test_validation_stop_returns_200_if_task_locked_by_user_with_comment(self):
12431252
self.assertEqual(task_history_comment["actionText"], "Test comment")
12441253
self.assertEqual(task_history_comment["actionBy"], self.test_user.username)
12451254

1255+
# Check if lock duration is saved
1256+
# Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING"
1257+
# we need to look for third entry in task history as second entry is comment
1258+
self.assertIsNotNone(response.json[2]["taskHistory"]["actionText"])
1259+
12461260

12471261
class TestTasksActionsSplitAPI(BaseTestCase):
12481262
def setUp(self):

tests/backend/integration/services/test_mapping_service.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import datetime
22
import xml.etree.ElementTree as ET
33
from unittest.mock import patch
4-
from backend.services.mapping_service import MappingService, Task
4+
from backend.services.mapping_service import (
5+
MappingService,
6+
Task,
7+
TaskHistory,
8+
ExtendLockTimeDTO,
9+
)
510
from backend.models.postgis.task import TaskStatus
611
from tests.backend.base import BaseTestCase
712
from tests.backend.helpers.test_helpers import create_canned_project
@@ -165,3 +170,38 @@ def test_reset_all_bad_imagery(
165170
# Assert
166171
for task in self.test_project.tasks:
167172
self.assertNotEqual(task.task_status, TaskStatus.BADIMAGERY.value)
173+
174+
def test_task_extend_duration_is_recorded(self):
175+
if self.skip_tests:
176+
return
177+
178+
# Arrange
179+
task = Task.get(1, self.test_project.id)
180+
task.task_status = TaskStatus.READY.value
181+
task.update()
182+
task.lock_task_for_mapping(self.test_user.id)
183+
extend_lock_dto = ExtendLockTimeDTO()
184+
extend_lock_dto.task_ids = [task.id]
185+
extend_lock_dto.project_id = self.test_project.id
186+
extend_lock_dto.user_id = self.test_user.id
187+
# Act
188+
# Extend the task lock time twice and check the task history
189+
MappingService.extend_task_lock_time(extend_lock_dto)
190+
MappingService.extend_task_lock_time(extend_lock_dto)
191+
task.reset_lock(self.test_user.id)
192+
193+
# Assert
194+
# Check that the task history has 2 entries for EXTENDED_FOR_MAPPING and that the action_text is not None
195+
extended_task_history = (
196+
TaskHistory.query.filter_by(
197+
task_id=task.id,
198+
project_id=self.test_project.id,
199+
)
200+
.order_by(TaskHistory.action_date.desc())
201+
.limit(5)
202+
.all()
203+
)
204+
self.assertEqual(extended_task_history[0].action, "EXTENDED_FOR_MAPPING")
205+
self.assertEqual(extended_task_history[1].action, "EXTENDED_FOR_MAPPING")
206+
self.assertIsNotNone(extended_task_history[0].action_text)
207+
self.assertIsNotNone(extended_task_history[1].action_text)

0 commit comments

Comments
 (0)