def test_split_task_helper(
        self,
        mock_task_get,
        mock_task_get_max_task_id_for_project,
        mock_task_create,
        mock_task_delete,
        mock_project_get,
        mock_project_save,
        mock_project_tasks,
        mock_instructions,
    ):
        if self.skip_tests:
            return

        # arrange
        task_stub = Task()
        task_stub.id = 1
        task_stub.project_id = 1
        task_stub.task_status = 1
        task_stub.locked_by = 1234
        task_stub.lock_holder = 1234
        task_stub.is_square = True
        task_stub.x = 16856
        task_stub.y = 17050
        task_stub.zoom = 15
        task_stub.geometry = shape.from_shape(
            Polygon(
                [
                    (5.1855468740711421, 7.2970875628719796),
                    (5.1855468740711421, 7.3079847788619219),
                    (5.1965332021941588, 7.3079847788619219),
                    (5.1965332021941588, 7.2970875628719796),
                    (5.1855468740711421, 7.2970875628719796),
                ]
            )
        )
        mock_task_get.return_value = task_stub
        mock_task_get_max_task_id_for_project.return_value = 1
        mock_project_get.return_value = Project()
        mock_project_tasks.return_value = [task_stub]
        splitTaskDTO = SplitTaskDTO()
        splitTaskDTO.user_id = 1234
        splitTaskDTO.project_id = 1
        splitTaskDTO.task_id = 1

        # act
        result = SplitService.split_task(splitTaskDTO)

        # assert
        self.assertEqual(4, len(result.tasks))
Esempio n. 2
0
 def post(self, project_id, task_id):
     """
     Split a task
     ---
     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 split OK
         400:
             description: Client Error
         401:
             description: Unauthorized - Invalid credentials
         403:
             description: Forbidden
         404:
             description: Task not found
         500:
             description: Internal Server Error
     """
     try:
         split_task_dto = SplitTaskDTO()
         split_task_dto.user_id = token_auth.current_user()
         split_task_dto.project_id = project_id
         split_task_dto.task_id = task_id
         split_task_dto.preferred_locale = request.environ.get(
             "HTTP_ACCEPT_LANGUAGE")
         split_task_dto.validate()
     except DataError as e:
         current_app.logger.error(f"Error validating request: {str(e)}")
         return {"Error": "Unable to split task"}, 400
     try:
         tasks = SplitService.split_task(split_task_dto)
         return tasks.to_primitive(), 200
     except NotFound:
         return {"Error": "Task Not Found"}, 404
     except SplitServiceError as e:
         return {"Error": str(e)}, 403
     except InvalidGeoJson as e:
         return {"Error": str(e)}, 500
     except Exception as e:
         error_msg = f"TasksActionsSplitAPI POST - unhandled error: {str(e)}"
         current_app.logger.critical(error_msg)
         return {"Error": "Unable to split task"}, 500