From e13a7aaba5465b60a099983bf878111132fd5276 Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Thu, 12 Oct 2023 15:24:11 +0200 Subject: [PATCH] finish unit tests for getting price unit endpint --- .../api/routes/solvers_jobs.py | 4 ++-- .../tests/unit/test_api_solver_jobs.py | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py b/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py index dcd6b276011..bde7cd44d14 100644 --- a/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py +++ b/services/api-server/src/simcore_service_api_server/api/routes/solvers_jobs.py @@ -72,7 +72,7 @@ def _assert_project_associated_with_solver( ) if expected_job_name != project.name: raise HTTPException( - status.HTTP_404_NOT_FOUND, + status.HTTP_422_UNPROCESSABLE_ENTITY, detail=f"job {project.uuid} is not associated with solver {solver_key} and version {version}", ) @@ -588,7 +588,7 @@ async def get_job_pricing_unit( webserver_api: Annotated[AuthSession, Depends(get_webserver_session)], ): job_name = _compose_job_resource_name(solver_key, version, job_id) - _logger.debug("Getting wallet for job '%s'", job_name) + _logger.debug("Getting pricing unit for job '%s'", job_name) project: ProjectGet = await webserver_api.get_project(project_id=job_id) _assert_project_associated_with_solver(solver_key, version, project) diff --git a/services/api-server/tests/unit/test_api_solver_jobs.py b/services/api-server/tests/unit/test_api_solver_jobs.py index 5160dee9674..4147d7363a9 100644 --- a/services/api-server/tests/unit/test_api_solver_jobs.py +++ b/services/api-server/tests/unit/test_api_solver_jobs.py @@ -74,7 +74,7 @@ def _get_job_wallet_side_effect( @pytest.mark.parametrize( - "capture", + "capture_file", [ "get_job_pricing_unit_invalid_job.json", "get_job_pricing_unit_invalid_solver.json", @@ -89,7 +89,7 @@ async def test_get_solver_job_pricing_unit( ], auth: httpx.BasicAuth, project_tests_dir: Path, - capture: str, + capture_file: str, ): solver_key: str = "simcore/services/comp/my_super_hpc_solver" @@ -108,10 +108,11 @@ def _get_job_side_effect( assert data.get("uuid") data["uuid"] = path_params["project_id"] assert data.get("name") - data["name"] = Job.compose_resource_name( - parent_name=Solver.compose_resource_name(solver_key, solver_version), # type: ignore - job_id=job_id, - ) + if capture_file != "get_job_pricing_unit_invalid_solver.json": + data["name"] = Job.compose_resource_name( + parent_name=Solver.compose_resource_name(solver_key, solver_version), # type: ignore + job_id=job_id, + ) response["data"] = data return response @@ -124,9 +125,9 @@ def _get_pricing_unit_side_effect( respx_mock = respx_mock_from_capture( mocked_webserver_service_api_base, - project_tests_dir / "mocks" / capture, + project_tests_dir / "mocks" / capture_file, [_get_job_side_effect, _get_pricing_unit_side_effect] - if capture == "get_job_pricing_unit_success.json" + if capture_file == "get_job_pricing_unit_success.json" else [_get_job_side_effect], ) @@ -134,9 +135,13 @@ def _get_pricing_unit_side_effect( f"{API_VTAG}/solvers/{solver_key}/releases/{solver_version}/jobs/{job_id}/pricing_unit", auth=auth, ) - if capture == "get_job_pricing_unit_success.json": + if capture_file == "get_job_pricing_unit_success.json": assert response.status_code == 200 body = response.json() assert isinstance(body, dict) + elif capture_file == "get_job_pricing_unit_invalid_job.json": + assert response.status_code == 404 + elif capture_file == "get_job_pricing_unit_invalid_solver.json": + assert response.status_code == 422 else: pytest.fail()