Skip to content

Commit

Permalink
unit tests for getting job wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Oct 11, 2023
1 parent 44a1285 commit fb14c68
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 36 deletions.
13 changes: 11 additions & 2 deletions services/api-server/tests/mocks/get_job_wallet_found.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@
"allOf": null,
"oneOf": null
},
"response_value": "87643648-3a38-44e2-9cfe-d86ab3d50629"
"response_value": "projects"
}
]
},
"query": null,
"request_payload": null,
"response_body": {
"data": null
"data": {
"walletId": 1,
"name": "my_wallet",
"description": "my awesome wallet",
"owner": 3,
"thumbnail": "string",
"status": "ACTIVE",
"created": "2023-10-10T13:58:20.381826+00:00",
"modified": "2023-10-10T13:58:20.381826+00:00"
}
},
"status_code": 200
}
Expand Down
34 changes: 0 additions & 34 deletions services/api-server/tests/mocks/get_job_wallet_not_found.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
[
{
"name": "GET /projects/87643648-3a38-44e2-9cfe-d86ab3d50629/wallet",
"description": "<Request('GET', 'http://webserver:8080/v0/projects/87643648-3a38-44e2-9cfe-d86ab3d50629/wallet')>",
"method": "GET",
"host": "webserver",
"path": {
"path": "/v0/projects/{project_id}/wallet",
"path_parameters": [
{
"in_": "path",
"name": "project_id",
"required": true,
"schema_": {
"title": "Project Id",
"type_": "str",
"pattern": null,
"format_": "uuid",
"exclusiveMinimum": null,
"minimum": null,
"anyOf": null,
"allOf": null,
"oneOf": null
},
"response_value": "87643648-3a38-44e2-9cfe-d86ab3d50629"
}
]
},
"query": null,
"request_payload": null,
"response_body": {
"data": null
},
"status_code": 200
},
{
"name": "GET /projects/87643648-3a38-44e2-9cfe-d86ac3d50629/wallet",
"description": "<Request('GET', 'http://webserver:8080/v0/projects/87643648-3a38-44e2-9cfe-d86ac3d50629/wallet')>",
Expand Down
68 changes: 68 additions & 0 deletions services/api-server/tests/unit/test_api_solver_jobs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from pathlib import Path
from typing import Any, Callable
from uuid import UUID

import httpx
import pytest
import respx
from httpx import AsyncClient
from simcore_service_api_server._meta import API_VTAG
from simcore_service_api_server.utils.http_calls_capture import HttpApiCallCaptureModel
from unit.conftest import SideEffectCallback


@pytest.mark.parametrize(
"capture", ["get_job_wallet_found.json", "get_job_wallet_not_found.json"]
)
async def test_get_solver_job_wallet(
client: AsyncClient,
mocked_webserver_service_api_base,
respx_mock_from_capture: Callable[
[respx.MockRouter, Path, list[SideEffectCallback] | None], respx.MockRouter
],
auth: httpx.BasicAuth,
project_tests_dir: Path,
capture: str,
):

_wallet_id: int = 1826

def _get_job_wallet_side_effect(
request: httpx.Request,
path_params: dict[str, Any],
capture: HttpApiCallCaptureModel,
) -> Any:
response = capture.response_body
assert isinstance(response, dict)
if data := response.get("data"):
assert isinstance(data, dict)
assert data.get("walletId")
response["data"]["walletId"] = _wallet_id
return response

respx_mock = respx_mock_from_capture(
mocked_webserver_service_api_base,
project_tests_dir / "mocks" / capture,
[_get_job_wallet_side_effect],
)

solver_key: str = "simcore/services/comp/my_super_hpc_solver"
solver_version: str = "3.14.0"
job_id: UUID = UUID("87643648-3a38-44e2-9cfe-d86ab3d50629")
response = await client.get(
f"{API_VTAG}/solvers/{solver_key}/releases/{solver_version}/jobs/{job_id}/wallet",
auth=auth,
)
if capture == "get_job_wallet_found.json":
assert response.status_code == 200
body = response.json()
assert isinstance(body, dict)
assert _wallet_id == body.get("walletId")
elif capture == "get_job_wallet_not_found.json":
assert response.status_code == 404
body = response.json()
assert isinstance(body, dict)
assert body.get("data") is None
assert body.get("errors") is not None
else:
pytest.fail()

0 comments on commit fb14c68

Please sign in to comment.