Skip to content

Commit

Permalink
finish unit tests for getting price unit endpint
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Oct 12, 2023
1 parent 5312462 commit e13a7aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
)

Expand Down Expand Up @@ -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)
Expand Down
23 changes: 14 additions & 9 deletions services/api-server/tests/unit/test_api_solver_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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

Expand All @@ -124,19 +125,23 @@ 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],
)

response = await client.get(
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()

0 comments on commit e13a7aa

Please sign in to comment.