File tree Expand file tree Collapse file tree 2 files changed +45
-27
lines changed
packages/pytest-simcore/src/pytest_simcore
services/web/server/tests/unit/with_dbs/03 Expand file tree Collapse file tree 2 files changed +45
-27
lines changed Original file line number Diff line number Diff line change 66from copy import deepcopy
77from functools import lru_cache
88from pathlib import Path
9- from typing import Any , NamedTuple
9+ from typing import Any , Callable , NamedTuple
1010
1111import jsonref
1212import pytest
1313import yaml
1414
15+ try :
16+ from aiohttp import web
17+
18+ has_aiohttp = True
19+ except ImportError :
20+ has_aiohttp = False
21+
1522
1623class Entrypoint (NamedTuple ):
1724 name : str
@@ -64,3 +71,35 @@ def openapi_specs_entrypoints(
6471 )
6572 )
6673 return entrypoints
74+
75+
76+ if has_aiohttp :
77+
78+ @pytest .fixture
79+ def create_aiohttp_app_rest_entrypoints () -> Callable [
80+ [web .Application ], set [Entrypoint ]
81+ ]:
82+ def _ (app : web .Application ):
83+ entrypoints : set [Entrypoint ] = set ()
84+
85+ # app routes, i.e. "exposed"
86+ for resource_name , resource in app .router .named_resources ().items ():
87+ resource_path = resource .canonical
88+ for route in resource :
89+ assert route .name == resource_name
90+ assert route .resource
91+ assert route .name is not None
92+
93+ if route .method == "HEAD" :
94+ continue
95+
96+ entrypoints .add (
97+ Entrypoint (
98+ method = route .method ,
99+ path = resource_path ,
100+ name = route .name ,
101+ )
102+ )
103+ return entrypoints
104+
105+ return _
Original file line number Diff line number Diff line change 44# pylint: disable=unused-variable
55
66
7+ from collections .abc import Callable
8+
79import pytest
810from aiohttp import web
911from faker import Faker
@@ -53,36 +55,13 @@ def app(app_environment: EnvVarsDict) -> web.Application:
5355 return app_
5456
5557
56- @pytest .fixture
57- def app_rest_entrypoints (app : web .Application ) -> set [Entrypoint ]:
58- entrypoints : set [Entrypoint ] = set ()
59-
60- # app routes, i.e. "exposed"
61- for resource_name , resource in app .router .named_resources ().items ():
62- resource_path = resource .canonical
63- for route in resource :
64- assert route .name == resource_name
65- assert route .resource
66- assert route .name is not None
67-
68- if route .method == "HEAD" :
69- continue
70-
71- entrypoints .add (
72- Entrypoint (
73- method = route .method ,
74- path = resource_path ,
75- name = route .name ,
76- )
77- )
78- return entrypoints
79-
80-
8158def test_app_named_resources_against_openapi_specs (
8259 openapi_specs_entrypoints : set [Entrypoint ],
83- app_rest_entrypoints : set [Entrypoint ],
60+ app : web .Application ,
61+ create_aiohttp_app_rest_entrypoints : Callable [[web .Application ], set [Entrypoint ]],
8462):
8563 # check whether exposed routes implements openapi.json contract
64+ app_rest_entrypoints : set [Entrypoint ] = create_aiohttp_app_rest_entrypoints (app )
8665
8766 assert app_rest_entrypoints == openapi_specs_entrypoints
8867
You can’t perform that action at this time.
0 commit comments