diff --git a/tests/backend/integration/api/tasks/test_actions.py b/tests/backend/integration/api/tasks/test_actions.py index 4d7bb034aa..f6fba2fecc 100644 --- a/tests/backend/integration/api/tasks/test_actions.py +++ b/tests/backend/integration/api/tasks/test_actions.py @@ -561,9 +561,8 @@ def test_mapping_unlock_returns_200_on_success(self): """Test returns 200 on success.""" # Arrange task = Task.get(1, self.test_project.id) - task.task_status = TaskStatus.LOCKED_FOR_MAPPING.value - task.locked_by = self.test_user.id - task.update() + task.status = TaskStatus.READY.value + task.lock_task_for_mapping(self.test_user.id) # Act response = self.client.post( self.url, @@ -584,9 +583,8 @@ def test_mapping_unlock_returns_200_on_success_with_comment(self): """Test returns 200 on success.""" # Arrange task = Task.get(1, self.test_project.id) - task.task_status = TaskStatus.LOCKED_FOR_MAPPING.value - task.locked_by = self.test_user.id - task.update() + task.status = TaskStatus.READY.value + task.lock_task_for_mapping(self.test_user.id) # Act response = self.client.post( self.url, @@ -685,9 +683,8 @@ def test_mapping_stop_returns_200_on_success(self): """Test returns 200 on success.""" # Arrange task = Task.get(1, self.test_project.id) - task.task_status = TaskStatus.LOCKED_FOR_MAPPING.value - task.locked_by = self.test_user.id - task.update() + task.status = TaskStatus.READY.value + task.lock_task_for_mapping(self.test_user.id) # Act response = self.client.post( self.url, @@ -703,9 +700,8 @@ def test_mapping_stop_returns_200_on_success_with_comment(self): """Test returns 200 on success.""" # Arrange task = Task.get(1, self.test_project.id) - task.task_status = TaskStatus.LOCKED_FOR_MAPPING.value - task.locked_by = self.test_user.id - task.update() + task.status = TaskStatus.READY.value + task.lock_task_for_mapping(self.test_user.id) # Act response = self.client.post( self.url, @@ -992,11 +988,14 @@ def test_validation_unlock_returns_403_if_task_not_locked_for_validation(self): def lock_task_for_validation(task_id, project_id, user_id, mapped_by=None): """Lock task for validation.""" task = Task.get(task_id, project_id) - task.task_status = TaskStatus.LOCKED_FOR_VALIDATION.value - task.locked_by = user_id + if mapped_by: - task.mapped_by = mapped_by - task.update() + task.status = TaskStatus.READY.value + task.lock_task_for_mapping(mapped_by) + task.unlock_task(mapped_by, TaskStatus.MAPPED) + + task.status = TaskStatus.MAPPED.value + task.lock_task_for_validating(user_id) def test_validation_unlock_returns_403_if_task_locked_by_other_user(self): """Test returns 403 if task locked by other user.""" @@ -1197,7 +1196,6 @@ def test_validation_stop_returns_200_if_task_locked_by_user(self): """Test returns 200 if task locked by user.""" # Arrange task = Task.get(1, self.test_project.id) - task.unlock_task(self.test_user.id, TaskStatus.MAPPED) last_task_status = TaskStatus(task.task_status).name TestTasksActionsValidationUnlockAPI.lock_task_for_validation( 1, self.test_project.id, self.test_user.id, self.test_user.id @@ -1218,7 +1216,6 @@ def test_validation_stop_returns_200_if_task_locked_by_user_with_comment(self): """Test returns 200 if task locked by user with comment.""" # Arrange task = Task.get(1, self.test_project.id) - task.unlock_task(self.test_user.id, TaskStatus.MAPPED) last_task_status = TaskStatus(task.task_status).name TestTasksActionsValidationUnlockAPI.lock_task_for_validation( 1, self.test_project.id, self.test_user.id, self.test_user.id diff --git a/tests/backend/unit/services/test_mapping_service.py b/tests/backend/unit/services/test_mapping_service.py index 21700db801..5e51f1b57b 100644 --- a/tests/backend/unit/services/test_mapping_service.py +++ b/tests/backend/unit/services/test_mapping_service.py @@ -1,4 +1,5 @@ from unittest.mock import patch, MagicMock + from backend.services.mapping_service import ( MappingService, Task, @@ -127,6 +128,7 @@ def test_if_new_state_not_acceptable_raise_error(self, mock_task): with self.assertRaises(MappingServiceError): MappingService.unlock_task_after_mapping(self.mapped_task_dto) + @patch.object(TaskHistory, "get_last_action") @patch.object(ProjectService, "send_email_on_project_progress") @patch.object(ProjectInfo, "get_dto_for_locale") @patch.object(Task, "get_per_task_instructions") @@ -147,6 +149,7 @@ def test_unlock_with_comment_sets_history( mock_state, mock_project_name, mock_send_email, + mock_last_action, ): # Arrange self.task_stub.task_status = TaskStatus.LOCKED_FOR_MAPPING.value @@ -154,6 +157,10 @@ def test_unlock_with_comment_sets_history( mock_task.return_value = self.task_stub mock_state.return_value = TaskStatus.LOCKED_FOR_MAPPING mock_project_name.name.return_value = "Test project" + history = TaskHistory(1, 1, 1) + history.action = TaskAction.LOCKED_FOR_MAPPING.name + mock_last_action.return_value = history + # Act test_task = MappingService.unlock_task_after_mapping(self.mapped_task_dto) @@ -163,6 +170,7 @@ def test_unlock_with_comment_sets_history( self.assertEqual(TaskAction.COMMENT.name, test_task.task_history[0].action) self.assertEqual(test_task.task_history[0].action_text, "Test comment") + @patch.object(TaskHistory, "get_last_action") @patch.object(ProjectService, "send_email_on_project_progress") @patch.object(Task, "get_per_task_instructions") @patch.object(StatsService, "update_stats_after_task_state_change") @@ -179,11 +187,15 @@ def test_unlock_with_status_change_sets_history( mock_instructions, mock_state, mock_send_email, + mock_last_action, ): # Arrange self.task_stub.task_status = TaskStatus.LOCKED_FOR_MAPPING.value mock_task.return_value = self.task_stub mock_state.return_value = TaskStatus.LOCKED_FOR_MAPPING + history = TaskHistory(1, 1, 1) + history.action = TaskAction.LOCKED_FOR_MAPPING.name + mock_last_action.return_value = history # Act test_task = MappingService.unlock_task_after_mapping(self.mapped_task_dto)