Skip to content

Commit

Permalink
Fix failing test cases due to missing task lock history.
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Sep 1, 2023
1 parent ead59cb commit b601cc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tests/backend/integration/api/tasks/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -992,8 +988,8 @@ 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
task.status = TaskStatus.READY.value
task.lock_task_for_validating(user_id)
if mapped_by:
task.mapped_by = mapped_by
task.update()
Expand Down Expand Up @@ -1197,6 +1193,8 @@ 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.status = TaskStatus.READY.value
task.lock_task_for_mapping(self.test_user.id)
task.unlock_task(self.test_user.id, TaskStatus.MAPPED)
last_task_status = TaskStatus(task.task_status).name
TestTasksActionsValidationUnlockAPI.lock_task_for_validation(
Expand All @@ -1218,6 +1216,8 @@ 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.status = TaskStatus.READY.value
task.lock_task_for_mapping(self.test_user.id)
task.unlock_task(self.test_user.id, TaskStatus.MAPPED)
last_task_status = TaskStatus(task.task_status).name
TestTasksActionsValidationUnlockAPI.lock_task_for_validation(
Expand Down
12 changes: 12 additions & 0 deletions tests/backend/unit/services/test_mapping_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest.mock import patch, MagicMock

from backend.services.mapping_service import (
MappingService,
Task,
Expand Down Expand Up @@ -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")
Expand All @@ -147,13 +149,18 @@ 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
self.mapped_task_dto.comment = "Test comment"
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)

Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit b601cc8

Please sign in to comment.