|
1 | 1 | import datetime
|
2 | 2 | import xml.etree.ElementTree as ET
|
3 | 3 | 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 | +) |
5 | 10 | from backend.models.postgis.task import TaskStatus
|
6 | 11 | from tests.backend.base import BaseTestCase
|
7 | 12 | from tests.backend.helpers.test_helpers import create_canned_project
|
@@ -165,3 +170,38 @@ def test_reset_all_bad_imagery(
|
165 | 170 | # Assert
|
166 | 171 | for task in self.test_project.tasks:
|
167 | 172 | 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