def test_mapper_level_updates_correctly(self, mock_user, mock_osm, mock_save): # Arrange test_user = User() test_user.mapping_level = MappingLevel.BEGINNER.value mock_user.return_value = test_user test_osm = UserOSMDTO() test_osm.changeset_count = 350 mock_osm.return_value = test_osm # Act UserService.check_and_update_mapper_level(123) #Assert self.assertTrue(test_user.mapping_level, MappingLevel.INTERMEDIATE.value)
def post(self, project_id, task_id): """ Unlocks the task after mapping completed --- tags: - mapping produces: - application/json parameters: - in: header name: Authorization description: Base64 encoded session token required: true type: string default: Token sessionTokenHere== - name: project_id in: path description: The ID of the project the task is associated with required: true type: integer default: 1 - name: task_id in: path description: The unique task ID required: true type: integer default: 1 - in: body name: body required: true description: JSON object for unlocking a task schema: id: TaskUpdateUnlock required: - status properties: status: type: string description: The new status for the task default: MAPPED comment: type: string description: Optional user comment about the task default: Comment about the mapping responses: 200: description: Task unlocked 400: description: Client Error 401: description: Unauthorized - Invalid credentials 403: description: Forbidden 404: description: Task not found 500: description: Internal Server Error """ try: mapped_task = MappedTaskDTO(request.get_json()) mapped_task.user_id = tm.authenticated_user_id mapped_task.task_id = task_id mapped_task.project_id = project_id mapped_task.validate() except DataError as e: current_app.logger.error(f'Error validating request: {str(e)}') return str(e), 400 try: task = MappingService.unlock_task_after_mapping(mapped_task) return task.to_primitive(), 200 except NotFound: return {"Error": "Task Not Found"}, 404 except MappingServiceError as e: return {"Error": str(e)}, 403 except Exception as e: error_msg = f'Task Lock API - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"Error": error_msg}, 500 finally: # Refresh mapper level after mapping UserService.check_and_update_mapper_level(tm.authenticated_user_id)