Skip to content

Commit 56512a2

Browse files
committed
both tests run
1 parent 752cc1f commit 56512a2

File tree

7 files changed

+41
-69
lines changed

7 files changed

+41
-69
lines changed

packages/pytest-simcore/src/pytest_simcore/openapi_specs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
# pylint: disable=unused-variable
44
# pylint: disable=too-many-arguments
55

6+
from collections.abc import Callable
67
from copy import deepcopy
78
from functools import lru_cache
89
from pathlib import Path
9-
from typing import Any, Callable, NamedTuple
10+
from typing import Any, NamedTuple
1011

1112
import jsonref
1213
import pytest

services/storage/requirements/_test.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ coverage
1111
docker
1212
faker
1313
fakeredis[lua]
14+
jsonref
1415
moto[server]
1516
pandas
1617
pytest

services/storage/requirements/_test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ jsonpath-ng==1.6.1
125125
# via moto
126126
jsonpointer==3.0.0
127127
# via jsonpatch
128+
jsonref==1.1.0
129+
# via -r requirements/_test.in
128130
jsonschema==4.21.1
129131
# via
130132
# -c requirements/_base.txt

services/storage/tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"pytest_simcore.file_extra",
7676
"pytest_simcore.httpbin_service",
7777
"pytest_simcore.minio_service",
78+
"pytest_simcore.openapi_specs",
7879
"pytest_simcore.postgres_service",
7980
"pytest_simcore.pytest_global_environs",
8081
"pytest_simcore.repository_paths",

services/storage/tests/unit/test__openapi_specs.py

Lines changed: 17 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
# pylint: disable=unused-argument
44
# pylint: disable=unused-variable
55

6+
from collections.abc import Callable
67
from pathlib import Path
7-
from typing import NamedTuple
88

9-
import openapi_core
109
import pytest
1110
import simcore_service_storage.application
1211
from aiohttp import web
1312
from faker import Faker
14-
from openapi_core import Spec as OpenApiSpecs
1513
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1614
from pytest_simcore.helpers.typing_env import EnvVarsDict
15+
from pytest_simcore.openapi_specs import Entrypoint
1716
from simcore_service_storage._meta import API_VTAG
1817
from simcore_service_storage.resources import storage_resources
1918
from simcore_service_storage.settings import Settings
2019

2120

22-
class Entrypoint(NamedTuple):
23-
name: str
24-
method: str
25-
path: str
21+
@pytest.fixture
22+
def openapi_specs_path() -> Path:
23+
# overrides pytest_simcore.openapi_specs.app_openapi_specs_path fixture
24+
spec_path: Path = storage_resources.get_path(f"api/{API_VTAG}/openapi.yaml")
25+
return spec_path
2626

2727

2828
@pytest.fixture
@@ -42,6 +42,7 @@ def app_environment(
4242

4343
@pytest.fixture
4444
def app(app_environment: EnvVarsDict) -> web.Application:
45+
assert app_environment
4546
# Expects that:
4647
# - routings happen during setup!
4748
# - all plugins are setup but app is NOT started (i.e events are not triggered)
@@ -50,61 +51,20 @@ def app(app_environment: EnvVarsDict) -> web.Application:
5051
return simcore_service_storage.application.create(settings)
5152

5253

53-
@pytest.fixture(scope="module")
54-
def openapi_specs() -> openapi_core.Spec:
55-
spec_path: Path = storage_resources.get_path(f"api/{API_VTAG}/openapi.yaml")
56-
return openapi_core.Spec.from_path(spec_path)
57-
58-
5954
@pytest.fixture
60-
def expected_openapi_entrypoints(openapi_specs: OpenApiSpecs) -> set[Entrypoint]:
61-
entrypoints: set[Entrypoint] = set()
62-
63-
# openapi-specifications, i.e. "contract"
64-
for path, path_obj in openapi_specs["paths"].items():
65-
for operation, operation_obj in path_obj.items():
66-
entrypoints.add(
67-
Entrypoint(
68-
method=operation.upper(),
69-
path=path,
70-
name=operation_obj["operationId"],
71-
)
72-
)
73-
return entrypoints
74-
75-
76-
@pytest.fixture
77-
def app_entrypoints(app: web.Application) -> set[Entrypoint]:
78-
entrypoints: set[Entrypoint] = set()
79-
80-
# app routes, i.e. "exposed"
81-
for resource_name, resource in app.router.named_resources().items():
82-
resource_path = resource.canonical
83-
for route in resource:
84-
assert route.name == resource_name
85-
assert route.resource
86-
assert route.name is not None
87-
88-
if route.method == "HEAD":
89-
continue
90-
91-
entrypoints.add(
92-
Entrypoint(
93-
method=route.method,
94-
path=resource_path,
95-
name=route.name,
96-
)
97-
)
98-
return entrypoints
55+
def app_rest_entrypoints(
56+
app: web.Application,
57+
create_aiohttp_app_rest_entrypoints: Callable[[web.Application], set[Entrypoint]],
58+
) -> set[Entrypoint]:
59+
# check whether exposed routes implements openapi.json contract
60+
return create_aiohttp_app_rest_entrypoints(app)
9961

10062

10163
def test_app_named_resources_against_openapi_specs(
102-
expected_openapi_entrypoints: set[Entrypoint],
103-
app_entrypoints: set[Entrypoint],
64+
openapi_specs_entrypoints: set[Entrypoint],
65+
app_rest_entrypoints: set[Entrypoint],
10466
):
105-
# check whether exposed routes implements openapi.json contract
106-
107-
assert app_entrypoints == expected_openapi_entrypoints
67+
assert app_rest_entrypoints == openapi_specs_entrypoints
10868

10969
# NOTE: missing here is:
11070
# - input schemas (path, query and body)

services/web/server/tests/unit/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import yaml
1717
from pytest_simcore.helpers.dict_tools import ConfigDict
1818
from pytest_simcore.helpers.webserver_projects import empty_project_data
19-
from simcore_service_webserver.rest._utils import get_openapi_specs_path
2019

2120
CURRENT_DIR = Path(sys.argv[0] if __name__ == "__main__" else __file__).resolve().parent
2221

@@ -77,9 +76,3 @@ def disable_gc_manual_guest_users(mocker):
7776
"simcore_service_webserver.garbage_collector._core.remove_users_manually_marked_as_guests",
7877
return_value=None,
7978
)
80-
81-
82-
@pytest.fixture
83-
def openapi_specs_path(api_version_prefix: str) -> Path:
84-
# overrides pytest_simcore.openapi_specs.app_openapi_specs_path fixture
85-
return get_openapi_specs_path(api_version_prefix)

services/web/server/tests/unit/with_dbs/03/test__openapi_specs.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
from collections.abc import Callable
8+
from pathlib import Path
89

910
import pytest
1011
from aiohttp import web
@@ -14,6 +15,13 @@
1415
from pytest_simcore.openapi_specs import Entrypoint
1516
from simcore_service_webserver.application import create_application
1617
from simcore_service_webserver.application_settings import get_application_settings
18+
from simcore_service_webserver.rest._utils import get_openapi_specs_path
19+
20+
21+
@pytest.fixture
22+
def openapi_specs_path(api_version_prefix: str) -> Path:
23+
# overrides pytest_simcore.openapi_specs.app_openapi_specs_path fixture
24+
return get_openapi_specs_path(api_version_prefix)
1725

1826

1927
@pytest.fixture
@@ -46,6 +54,7 @@ def app_environment(
4654

4755
@pytest.fixture
4856
def app(app_environment: EnvVarsDict) -> web.Application:
57+
assert app_environment
4958
# Expects that:
5059
# - routings happen during setup!
5160
# - all plugins are setup but app is NOT started (i.e events are not triggered)
@@ -55,14 +64,19 @@ def app(app_environment: EnvVarsDict) -> web.Application:
5564
return app_
5665

5766

58-
def test_app_named_resources_against_openapi_specs(
59-
openapi_specs_entrypoints: set[Entrypoint],
67+
@pytest.fixture
68+
def app_rest_entrypoints(
6069
app: web.Application,
6170
create_aiohttp_app_rest_entrypoints: Callable[[web.Application], set[Entrypoint]],
62-
):
71+
) -> set[Entrypoint]:
6372
# check whether exposed routes implements openapi.json contract
64-
app_rest_entrypoints: set[Entrypoint] = create_aiohttp_app_rest_entrypoints(app)
73+
return create_aiohttp_app_rest_entrypoints(app)
74+
6575

76+
def test_app_named_resources_against_openapi_specs(
77+
openapi_specs_entrypoints: set[Entrypoint],
78+
app_rest_entrypoints: set[Entrypoint],
79+
):
6680
assert app_rest_entrypoints == openapi_specs_entrypoints
6781

6882
# NOTE: missing here is:

0 commit comments

Comments
 (0)