Skip to content

Commit 32330bf

Browse files
committed
ports
1 parent 5bb8a50 commit 32330bf

File tree

9 files changed

+71
-84
lines changed

9 files changed

+71
-84
lines changed

services/web/server/tests/unit/isolated/test__redirections.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
import asyncio
77
import textwrap
8+
from collections.abc import Callable
89
from pathlib import Path
10+
from typing import Awaitable
911

1012
import pytest
1113
from aiohttp import web
14+
from aiohttp.test_utils import TestClient
1215

1316

1417
@pytest.fixture
@@ -34,7 +37,11 @@ def index_static_path(tmpdir):
3437

3538

3639
@pytest.fixture
37-
def client(event_loop: asyncio.AbstractEventLoop, aiohttp_client, index_static_path):
40+
def client(
41+
event_loop: asyncio.AbstractEventLoop,
42+
aiohttp_client: Callable[..., Awaitable[TestClient]],
43+
index_static_path,
44+
):
3845

3946
routes = web.RouteTableDef()
4047

services/web/server/tests/unit/isolated/test_activity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import asyncio
66
import os
7-
from collections.abc import Callable
7+
from collections.abc import Awaitable, Callable
88
from typing import Any
99
from unittest.mock import MagicMock
1010

@@ -101,7 +101,7 @@ def app_environment(
101101
@pytest.fixture
102102
def client(
103103
event_loop: asyncio.AbstractEventLoop,
104-
aiohttp_client: Callable,
104+
aiohttp_client: Callable[..., Awaitable[TestClient]],
105105
mock_orphaned_services: MagicMock,
106106
app_environment: EnvVarsDict,
107107
):

services/web/server/tests/unit/isolated/test_diagnostics_healthcheck.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import asyncio
88
import json
99
import logging
10-
from collections.abc import Callable, Coroutine
1110
import time
11+
from collections.abc import Awaitable, Callable, Coroutine
1212

1313
import pytest
1414
import simcore_service_webserver
@@ -89,12 +89,14 @@ def mock_environment(
8989
{
9090
**mock_env_devel_environment,
9191
"AIODEBUG_SLOW_DURATION_SECS": f"{SLOW_HANDLER_DELAY_SECS / 10}",
92-
"WEBSERVER_DIAGNOSTICS": json.dumps({
93-
"DIAGNOSTICS_MAX_AVG_LATENCY": "2.0",
94-
"DIAGNOSTICS_MAX_TASK_DELAY": f"{SLOW_HANDLER_DELAY_SECS}",
95-
"DIAGNOSTICS_START_SENSING_DELAY": f"{0}",
96-
"DIAGNOSTICS_HEALTHCHECK_ENABLED": "1",
97-
}),
92+
"WEBSERVER_DIAGNOSTICS": json.dumps(
93+
{
94+
"DIAGNOSTICS_MAX_AVG_LATENCY": "2.0",
95+
"DIAGNOSTICS_MAX_TASK_DELAY": f"{SLOW_HANDLER_DELAY_SECS}",
96+
"DIAGNOSTICS_START_SENSING_DELAY": f"{0}",
97+
"DIAGNOSTICS_HEALTHCHECK_ENABLED": "1",
98+
}
99+
),
98100
"SC_HEALTHCHECK_TIMEOUT": "2m",
99101
},
100102
)
@@ -104,7 +106,7 @@ def mock_environment(
104106
def client(
105107
event_loop: asyncio.AbstractEventLoop,
106108
unused_tcp_port_factory: Callable,
107-
aiohttp_client: Callable,
109+
aiohttp_client: Callable[..., Awaitable[TestClient]],
108110
api_version_prefix: str,
109111
mock_environment: EnvVarsDict,
110112
) -> TestClient:

services/web/server/tests/unit/isolated/test_rest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# pylint:disable=no-name-in-module
44

55
import asyncio
6-
from collections.abc import Callable
6+
from collections.abc import Awaitable, Callable
77
from http import HTTPStatus
88
from unittest.mock import MagicMock
99

@@ -24,7 +24,7 @@
2424
def client(
2525
event_loop: asyncio.AbstractEventLoop,
2626
unused_tcp_port_factory: Callable,
27-
aiohttp_client: Callable,
27+
aiohttp_client: Callable[..., Awaitable[TestClient]],
2828
api_version_prefix: str,
2929
mock_env_devel_environment: EnvVarsDict,
3030
mock_env_deployer_pipeline: EnvVarsDict,

services/web/server/tests/unit/isolated/test_security_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import asyncio
77
import statistics
88
from collections import OrderedDict
9-
from collections.abc import Callable
9+
from collections.abc import Awaitable, Callable
1010
from typing import Any
1111
from unittest.mock import MagicMock
1212

@@ -205,7 +205,7 @@ async def _logout(request: web.Request):
205205
@pytest.fixture
206206
def client(
207207
event_loop: asyncio.AbstractEventLoop,
208-
aiohttp_client: Callable,
208+
aiohttp_client: Callable[..., Awaitable[TestClient]],
209209
mocker: MockerFixture,
210210
app_products: OrderedDict[str, Product],
211211
set_products_in_app_state: Callable[

services/web/server/tests/unit/isolated/test_utils_rate_limiting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import asyncio
66
import time
7+
from collections.abc import Awaitable
78
from typing import Callable
89

910
import pytest
@@ -28,7 +29,10 @@ async def get_ok_handler(_request: web.Request):
2829

2930

3031
@pytest.fixture
31-
def client(event_loop, aiohttp_client: Callable) -> TestClient:
32+
def client(
33+
event_loop,
34+
aiohttp_client: Callable[..., Awaitable[TestClient]],
35+
) -> TestClient:
3236
app = web.Application()
3337
app.router.add_get("/", get_ok_handler)
3438

services/web/server/tests/unit/with_dbs/01/test_guests_management.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

services/web/server/tests/unit/with_dbs/01/test_storage.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# pylint:disable=unused-import
2-
# pylint:disable=unused-argument
3-
# pylint:disable=redefined-outer-name
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
45

56
import asyncio
7+
from collections.abc import Awaitable, Callable
68
from urllib.parse import quote
79

810
import pytest
911
from aiohttp import web
10-
from aiohttp.test_utils import TestServer
12+
from aiohttp.test_utils import TestClient, TestServer
1113
from faker import Faker
1214
from pytest_simcore.helpers.assert_checks import assert_status
1315
from pytest_simcore.helpers.typing_env import EnvVarsDict
@@ -22,9 +24,10 @@
2224
@pytest.fixture()
2325
def storage_server(
2426
event_loop: asyncio.AbstractEventLoop,
25-
aiohttp_server: TestServer,
27+
aiohttp_server: Callable[..., Awaitable[TestServer]],
2628
app_environment: EnvVarsDict,
27-
):
29+
storage_test_server_port: int,
30+
) -> TestServer:
2831
async def _get_locs(request: web.Request):
2932
assert not request.can_read_body
3033

@@ -125,6 +128,7 @@ async def _get_datasets_meta(request: web.Request):
125128

126129
storage_api_version = app_environment["STORAGE_VTAG"]
127130
storage_port = int(app_environment["STORAGE_PORT"])
131+
assert storage_port == storage_test_server_port
128132

129133
assert (
130134
storage_api_version != API_VERSION
@@ -164,7 +168,9 @@ async def _get_datasets_meta(request: web.Request):
164168
(UserRole.TESTER, status.HTTP_200_OK),
165169
],
166170
)
167-
async def test_get_storage_locations(client, storage_server, logged_user, expected):
171+
async def test_get_storage_locations(
172+
client: TestClient, storage_server: TestServer, logged_user, expected
173+
):
168174
url = "/v0/storage/locations"
169175
assert url.startswith(PREFIX)
170176

@@ -186,7 +192,9 @@ async def test_get_storage_locations(client, storage_server, logged_user, expect
186192
(UserRole.ADMIN, status.HTTP_200_OK),
187193
],
188194
)
189-
async def test_sync_file_meta_table(client, storage_server, logged_user, expected):
195+
async def test_sync_file_meta_table(
196+
client: TestClient, storage_server: TestServer, logged_user, expected
197+
):
190198
url = "/v0/storage/locations/0:sync"
191199
assert url.startswith(PREFIX)
192200

@@ -208,7 +216,9 @@ async def test_sync_file_meta_table(client, storage_server, logged_user, expecte
208216
(UserRole.TESTER, status.HTTP_200_OK),
209217
],
210218
)
211-
async def test_get_datasets_metadata(client, storage_server, logged_user, expected):
219+
async def test_get_datasets_metadata(
220+
client: TestClient, storage_server: TestServer, logged_user, expected
221+
):
212222
url = "/v0/storage/locations/0/datasets"
213223
assert url.startswith(PREFIX)
214224

@@ -234,7 +244,7 @@ async def test_get_datasets_metadata(client, storage_server, logged_user, expect
234244
],
235245
)
236246
async def test_get_files_metadata_dataset(
237-
client, storage_server, logged_user, expected
247+
client: TestClient, storage_server: TestServer, logged_user, expected
238248
):
239249
url = "/v0/storage/locations/0/datasets/N:asdfsdf/metadata"
240250
assert url.startswith(PREFIX)
@@ -263,7 +273,7 @@ async def test_get_files_metadata_dataset(
263273
],
264274
)
265275
async def test_storage_file_meta(
266-
client, storage_server, logged_user, expected, faker: Faker
276+
client: TestClient, storage_server: TestServer, logged_user, expected, faker: Faker
267277
):
268278
# tests redirect of path with quotes in path
269279
file_id = f"{faker.uuid4()}/{faker.uuid4()}/a/b/c/d/e/dat"
@@ -289,7 +299,9 @@ async def test_storage_file_meta(
289299
(UserRole.TESTER, status.HTTP_200_OK),
290300
],
291301
)
292-
async def test_storage_list_filter(client, storage_server, logged_user, expected):
302+
async def test_storage_list_filter(
303+
client: TestClient, storage_server: TestServer, logged_user, expected
304+
):
293305
# tests composition of 2 queries
294306
file_id = "a/b/c/d/e/dat"
295307
url = "/v0/storage/locations/0/files/metadata?uuid_filter={}".format(

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,27 @@ def docker_compose_file(docker_compose_env: pytest.MonkeyPatch) -> str:
118118
# WEB SERVER/CLIENT FIXTURES ------------------------------------------------
119119

120120

121+
@pytest.fixture
122+
def web_test_server_port(unused_tcp_port_factory: Callable):
123+
return unused_tcp_port_factory()
124+
125+
126+
@pytest.fixture
127+
def storage_test_server_port(
128+
unused_tcp_port_factory: Callable, web_test_server_port: int
129+
):
130+
port = unused_tcp_port_factory()
131+
assert port != web_test_server_port
132+
return port
133+
134+
121135
@pytest.fixture
122136
def app_environment(
123137
monkeypatch: pytest.MonkeyPatch,
124138
default_app_cfg: AppConfigDict,
125139
unused_tcp_port_factory: Callable,
126140
mock_env_devel_environment: EnvVarsDict,
141+
storage_test_server_port: int,
127142
monkeypatch_setenv_from_app_config: Callable[[AppConfigDict], EnvVarsDict],
128143
) -> EnvVarsDict:
129144
# WARNING: this fixture is commonly overriden. Check before renaming.
@@ -138,7 +153,7 @@ def app_environment(app_environment: EnvVarsDict, monkeypatch: pytest.MonkeyPatc
138153
"""
139154
# NOTE: remains from from old cfg
140155
cfg = deepcopy(default_app_cfg)
141-
cfg["storage"]["port"] = unused_tcp_port_factory()
156+
cfg["storage"]["port"] = storage_test_server_port
142157
envs_app_cfg = monkeypatch_setenv_from_app_config(cfg)
143158

144159
return (
@@ -189,6 +204,7 @@ def web_server(
189204
unused_tcp_port_factory: Callable,
190205
app_environment: EnvVarsDict,
191206
postgres_db: sa.engine.Engine,
207+
web_test_server_port: int,
192208
# tools
193209
aiohttp_server: Callable,
194210
mocked_send_email: None,
@@ -201,7 +217,7 @@ def web_server(
201217
disable_static_webserver(app)
202218

203219
server = event_loop.run_until_complete(
204-
aiohttp_server(app, port=unused_tcp_port_factory())
220+
aiohttp_server(app, port=web_test_server_port)
205221
)
206222

207223
assert isinstance(postgres_db, sa.engine.Engine)

0 commit comments

Comments
 (0)