Skip to content

Commit 752cc1f

Browse files
committed
further simplified tests in web
1 parent 48d1f9c commit 752cc1f

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
from copy import deepcopy
77
from functools import lru_cache
88
from pathlib import Path
9-
from typing import Any, NamedTuple
9+
from typing import Any, Callable, NamedTuple
1010

1111
import jsonref
1212
import pytest
1313
import yaml
1414

15+
try:
16+
from aiohttp import web
17+
18+
has_aiohttp = True
19+
except ImportError:
20+
has_aiohttp = False
21+
1522

1623
class 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 _

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# pylint: disable=unused-variable
55

66

7+
from collections.abc import Callable
8+
79
import pytest
810
from aiohttp import web
911
from 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-
8158
def 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

0 commit comments

Comments
 (0)