33# pylint: disable=unused-argument
44# pylint: disable=unused-variable
55
6+ from collections .abc import Callable
67from pathlib import Path
7- from typing import NamedTuple
88
9- import openapi_core
109import pytest
1110import simcore_service_storage .application
1211from aiohttp import web
1312from faker import Faker
14- from openapi_core import Spec as OpenApiSpecs
1513from pytest_simcore .helpers .monkeypatch_envs import setenvs_from_dict
1614from pytest_simcore .helpers .typing_env import EnvVarsDict
15+ from pytest_simcore .openapi_specs import Entrypoint
1716from simcore_service_storage ._meta import API_VTAG
1817from simcore_service_storage .resources import storage_resources
1918from 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
4444def 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
10163def 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)
0 commit comments