Skip to content

Commit

Permalink
Add test case to check if extension duration is recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
Aadesh-Baral committed Sep 4, 2023
1 parent 0f5b2eb commit 4f9be01
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/backend/integration/api/tasks/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
42 changes: 41 additions & 1 deletion tests/backend/integration/services/test_mapping_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 4f9be01

Please sign in to comment.