From 4f9be01e3a78d5fb03d66defac78681543d2d62a Mon Sep 17 00:00:00 2001 From: Aadesh-Baral Date: Mon, 4 Sep 2023 16:37:49 +0545 Subject: [PATCH] Add test case to check if extension duration is recorded --- .../integration/api/tasks/test_actions.py | 14 +++++++ .../services/test_mapping_service.py | 42 ++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/tests/backend/integration/api/tasks/test_actions.py b/tests/backend/integration/api/tasks/test_actions.py index f6fba2fecc..02d316e61f 100644 --- a/tests/backend/integration/api/tasks/test_actions.py +++ b/tests/backend/integration/api/tasks/test_actions.py @@ -578,6 +578,10 @@ def test_mapping_unlock_returns_200_on_success(self): self.assertEqual(last_task_history["action"], TaskAction.STATE_CHANGE.name) self.assertEqual(last_task_history["actionText"], TaskStatus.MAPPED.name) self.assertEqual(last_task_history["actionBy"], self.test_user.username) + # Check if lock duration is saved + # Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING" + # we need to look for second entry in task history + self.assertIsNotNone(response.json["taskHistory"][1]["actionText"]) def test_mapping_unlock_returns_200_on_success_with_comment(self): """Test returns 200 on success.""" @@ -610,6 +614,11 @@ def test_mapping_unlock_returns_200_on_success_with_comment(self): self.assertEqual(last_comment_history["actionText"], "cannot map") self.assertEqual(last_comment_history["actionBy"], self.test_user.username) + # Check if lock duration is saved + # Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING" + # we need to look for third entry in task history as second entry is comment + self.assertIsNotNone(response.json["taskHistory"][2]["actionText"]) + class TestTasksActionsMappingStopAPI(BaseTestCase): def setUp(self): @@ -1243,6 +1252,11 @@ def test_validation_stop_returns_200_if_task_locked_by_user_with_comment(self): self.assertEqual(task_history_comment["actionText"], "Test comment") self.assertEqual(task_history_comment["actionBy"], self.test_user.username) + # Check if lock duration is saved + # Since locked duration is saved in entry with action as "LOCKED_FOR_MAPPING" + # we need to look for third entry in task history as second entry is comment + self.assertIsNotNone(response.json["tasks"][0]["taskHistory"][2]["actionText"]) + class TestTasksActionsSplitAPI(BaseTestCase): def setUp(self): diff --git a/tests/backend/integration/services/test_mapping_service.py b/tests/backend/integration/services/test_mapping_service.py index 4d4b052a5b..bc42ae32a9 100644 --- a/tests/backend/integration/services/test_mapping_service.py +++ b/tests/backend/integration/services/test_mapping_service.py @@ -1,7 +1,12 @@ import datetime import xml.etree.ElementTree as ET from unittest.mock import patch -from backend.services.mapping_service import MappingService, Task +from backend.services.mapping_service import ( + MappingService, + Task, + TaskHistory, + ExtendLockTimeDTO, +) from backend.models.postgis.task import TaskStatus from tests.backend.base import BaseTestCase from tests.backend.helpers.test_helpers import create_canned_project @@ -165,3 +170,38 @@ def test_reset_all_bad_imagery( # Assert for task in self.test_project.tasks: self.assertNotEqual(task.task_status, TaskStatus.BADIMAGERY.value) + + def test_task_extend_duration_is_recorded(self): + if self.skip_tests: + return + + # Arrange + task = Task.get(1, self.test_project.id) + task.task_status = TaskStatus.READY.value + task.update() + task.lock_task_for_mapping(self.test_user.id) + extend_lock_dto = ExtendLockTimeDTO() + extend_lock_dto.task_ids = [task.id] + extend_lock_dto.project_id = self.test_project.id + extend_lock_dto.user_id = self.test_user.id + # Act + # Extend the task lock time twice and check the task history + MappingService.extend_task_lock_time(extend_lock_dto) + MappingService.extend_task_lock_time(extend_lock_dto) + task.reset_lock(self.test_user.id) + + # Assert + # Check that the task history has 2 entries for EXTENDED_FOR_MAPPING and that the action_text is not None + extended_task_history = ( + TaskHistory.query.filter_by( + task_id=task.id, + project_id=self.test_project.id, + ) + .order_by(TaskHistory.action_date.desc()) + .limit(5) + .all() + ) + self.assertEqual(extended_task_history[0].action, "EXTENDED_FOR_MAPPING") + self.assertEqual(extended_task_history[1].action, "EXTENDED_FOR_MAPPING") + self.assertIsNotNone(extended_task_history[0].action_text) + self.assertIsNotNone(extended_task_history[1].action_text)