Ejemplo n.º 1
0
    def test_mapped_task_with_validated_status_is_invalid(self):

        mapped_task = MappedTaskDTO()
        mapped_task.task_id = 1
        mapped_task.project_id = 1
        mapped_task.status = TaskStatus.VALIDATED.name

        # Act / Assert
        with self.assertRaises(DataError):
            mapped_task.validate()
Ejemplo n.º 2
0
    def test_mapped_task_with_unknown_status_raises_error(self):
        # Arrange
        mapped_task = MappedTaskDTO()
        mapped_task.task_id = 1
        mapped_task.project_id = 1
        mapped_task.status = "IAIN"

        # Act / Assert
        with self.assertRaises(DataError):
            mapped_task.validate()
    def setUp(self):
        super().setUp()

        test_user = User()
        test_user.id = 123456
        test_user.username = "******"

        self.task_stub = Task()
        self.task_stub.id = 1
        self.task_stub.project_id = 1
        self.task_stub.task_status = 0
        self.task_stub.locked_by = 123456
        self.task_stub.lock_holder = test_user

        self.lock_task_dto = LockTaskDTO()
        self.lock_task_dto.user_id = 123456

        self.mapped_task_dto = MappedTaskDTO()
        self.mapped_task_dto.status = TaskStatus.MAPPED.name
        self.mapped_task_dto.user_id = 123456
Ejemplo n.º 4
0
    def setUp(self):
        self.app = create_app()
        self.ctx = self.app.app_context()
        self.ctx.push()

        test_user = User()
        test_user.id = 123456
        test_user.username = "******"

        self.task_stub = Task()
        self.task_stub.id = 1
        self.task_stub.project_id = 1
        self.task_stub.task_status = 0
        self.task_stub.locked_by = 123456
        self.task_stub.lock_holder = test_user

        self.lock_task_dto = LockTaskDTO()
        self.lock_task_dto.user_id = 123456

        self.mapped_task_dto = MappedTaskDTO()
        self.mapped_task_dto.status = TaskStatus.MAPPED.name
        self.mapped_task_dto.user_id = 123456
Ejemplo n.º 5
0
    def post(self, project_id, task_id):
        """
        Set a task as mapped
        ---
        tags:
            - tasks
        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: 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
            - 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:
            authenticated_user_id = token_auth.current_user()
            mapped_task = MappedTaskDTO(request.get_json())
            mapped_task.user_id = 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 {"Error": "Task unlock failed"}, 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:
            return {"Error": "Task unlock failed"}, 403
        except Exception as e:
            error_msg = f"Task Lock API - unhandled error: {str(e)}"
            current_app.logger.critical(error_msg)
            return {"Error": "Task unlock failed"}, 500
        finally:
            # Refresh mapper level after mapping
            UserService.check_and_update_mapper_level(authenticated_user_id)