diff --git a/tests/conftest.py b/tests/conftest.py index 34740dd..acc9cf3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ import copy import json import pytest +import typing DATA_PATH = Path(__file__).parent / "data" @@ -46,7 +47,9 @@ def mock_request_response(mock_session): Prepares a mock response and status code for a given url and method. """ - def _load_mock_request_response(name: str, url: str, method: str, code=200): + def _load_mock_request_response( + name: str, url: str, method: str, code=200 + ) -> dict[str, typing.Any]: data = {} for postfix in {"REQUEST", "RESPONSE"}: with open(DATA_PATH / f"{name}.REQUEST.json") as f: @@ -54,6 +57,6 @@ def _load_mock_request_response(name: str, url: str, method: str, code=200): mock_session.register_uri( method, url, json=data["response"]["body"], status_code=code ) - return data["request"] + return data yield _load_mock_request_response diff --git a/tests/test_api_create.py b/tests/test_api_create.py index 4685b44..c8a0e95 100644 --- a/tests/test_api_create.py +++ b/tests/test_api_create.py @@ -1,16 +1,33 @@ -def test_api_create(mock_request_response): +from edutap.wallet_google.models.primitives.enums import State + +import pytest + + +testdata = [ + ( + "Create", + "GenericObject", + { + "id": "3388000000022141777.obj53.test.ycc.edutap", + "classId": "3388000000022141777.test.ycc.edutap", + "state": State.ACTIVE, + }, + ), +] + + +@pytest.mark.parametrize("prefix,name,checkdata", testdata) +def test_api_create(mock_request_response, prefix, name, checkdata): from edutap.wallet_google.api import create - from edutap.wallet_google.models.primitives.enums import State from edutap.wallet_google.registry import lookup_model from edutap.wallet_google.session import session_manager request_data = mock_request_response( - "CreateGenericObject", session_manager.url("GenericObject"), "POST" + f"{prefix}{name}", session_manager.url(name), "POST" ) - result = create("GenericObject", request_data["body"]) + result = create(name, request_data["request"]["body"]) - GenericObject = lookup_model("GenericObject") - assert isinstance(result, GenericObject) - assert result.id == "3388000000022141777.obj53.test.ycc.edutap" - assert result.classId == "3388000000022141777.test.ycc.edutap" - assert result.state == State.ACTIVE + model = lookup_model(name) + assert isinstance(result, model) + for key, value in checkdata.items(): + assert getattr(result, key) == value