def test_split_geom_raise_grid_service_error_when_task_not_usable(self): if self.skip_tests: return with self.assertRaises(SplitServiceError): task_stub = Task() task_stub.is_square = True SplitService._create_split_tasks("foo", "bar", "dum", task_stub)
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.splittable = True task_stub.x = 1010 task_stub.y = 1399 task_stub.zoom = 11 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))
def test_split_geom_returns_split_geometries(self): if self.skip_tests: return # arrange x = 1010 y = 1399 zoom = 11 expected = geojson.loads(json.dumps(get_canned_json('split_task.json'))) # act result = SplitService._create_split_tasks(x, y, zoom) # assert self.assertEqual(str(expected), str(result))
def test_split_non_square_task(self, mock_task): if self.skip_tests: return # Lock task for mapping task = Task.get(2, self.test_project.id) task.lock_task_for_mapping(self.test_user.id) splitTaskDTO = SplitTaskDTO() splitTaskDTO.user_id = self.test_user.id splitTaskDTO.project_id = self.test_project.id splitTaskDTO.task_id = 2 # Split tasks expected = geojson.loads(json.dumps(get_canned_json('non_square_split_results.json'))) result = SplitService._create_split_tasks(task.x, task.y, task.zoom, task) self.assertEqual(str(expected), str(result))
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))
def test_split_geom_raise_grid_service_error_when_task_not_usable(self): if self.skip_tests: return with self.assertRaises(SplitServiceError): SplitService._create_split_tasks("foo", "bar", "dum")
def post(self, project_id, task_id): """ Split a task --- tags: - grid 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: 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 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 = tm.authenticated_user_id 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 str(e), 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 Exception as e: error_msg = f'Task Split API - unhandled error: {str(e)}' current_app.logger.critical(error_msg) return {"Error": error_msg}, 500