def test_lock_task_for_mapping_raises_error_if_user_has_not_accepted_license( self, mock_task, mock_project): # Arrange mock_task.return_value = self.task_stub mock_project.return_value = False, MappingNotAllowed.USER_NOT_ACCEPTED_LICENSE # Act / Assert with self.assertRaises(UserLicenseError): MappingService.lock_task_for_mapping(self.lock_task_dto)
def test_lock_task_for_mapping_raises_error_if_task_in_invalid_state( self, mock_task): # Arrange self.task_stub.task_status = TaskStatus.MAPPED.value mock_task.return_value = self.task_stub # Act / Assert with self.assertRaises(MappingServiceError): MappingService.lock_task_for_mapping(self.lock_task_dto)
def test_lock_task_for_mapping_raises_error_if_user_already_has_locked_task( self, mock_task, mock_project): # Arrange mock_task.return_value = self.task_stub mock_project.return_value = ( False, MappingNotAllowed.USER_ALREADY_HAS_TASK_LOCKED, ) # Act / Assert with self.assertRaises(MappingServiceError): MappingService.lock_task_for_mapping(self.lock_task_dto)
def post(self, project_id, task_id): """ Locks a task for mapping --- tags: - tasks produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token required: true type: string default: Token sessionTokenHere== - in: header name: Accept-Language description: Language user is requesting type: string required: true default: en - name: project_id in: path description: Project ID the task is associated with required: true type: integer default: 1 - name: task_id in: path description: Unique task ID required: true type: integer default: 1 responses: 200: description: Task locked 400: description: Client Error 401: description: Unauthorized - Invalid credentials 403: description: Forbidden 404: description: Task not found 409: description: User has not accepted license terms of project 500: description: Internal Server Error """ try: lock_task_dto = LockTaskDTO() lock_task_dto.user_id = token_auth.current_user() lock_task_dto.project_id = project_id lock_task_dto.task_id = task_id lock_task_dto.preferred_locale = request.environ.get( "HTTP_ACCEPT_LANGUAGE") lock_task_dto.validate() except DataError as e: current_app.logger.error(f"Error validating request: {str(e)}") return {"Error": "Unable to lock task"}, 400 try: task = MappingService.lock_task_for_mapping(lock_task_dto) return task.to_primitive(), 200 except NotFound: return {"Error": "Task Not Found"}, 404 except MappingServiceError as e: return {"Error": str(e)}, 403 except UserLicenseError: return {"Error": "User not accepted license terms"}, 409 except Exception as e: error_msg = f"Task Lock API - unhandled error: {str(e)}" current_app.logger.critical(error_msg) return {"Error": "Unable to lock task"}, 500