Skip to content

Commit c78aca4

Browse files
committed
renames
1 parent 5f60df5 commit c78aca4

File tree

2 files changed

+20
-127
lines changed

2 files changed

+20
-127
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
from urllib.parse import parse_qs
1010

1111
import pytest
12+
import simcore_service_webserver.studies_dispatcher
1213
from aiohttp.test_utils import make_mocked_request
1314
from models_library.utils.pydantic_tools_extension import parse_obj_or_none
14-
from pydantic import ByteSize, TypeAdapter
15+
from pydantic import BaseModel, ByteSize, TypeAdapter
16+
from pytest_simcore.pydantic_models import (
17+
assert_validation_model,
18+
walk_model_examples_in_package,
19+
)
1520
from servicelib.aiohttp.requests_validation import parse_request_query_parameters_as
1621
from simcore_service_webserver.studies_dispatcher._controller.rest.redirects_schemas import (
1722
FileQueryParams,
@@ -23,6 +28,19 @@
2328
)
2429
from yarl import URL
2530

31+
32+
@pytest.mark.parametrize(
33+
"model_cls, example_name, example_data",
34+
walk_model_examples_in_package(simcore_service_webserver.studies_dispatcher),
35+
)
36+
def test_model_examples(
37+
model_cls: type[BaseModel], example_name: str, example_data: Any
38+
):
39+
assert_validation_model(
40+
model_cls, example_name=example_name, example_data=example_data
41+
)
42+
43+
2644
_SIZEBYTES = TypeAdapter(ByteSize).validate_python("3MiB")
2745

2846
# SEE https://github.com/ITISFoundation/osparc-simcore/issues/3951#issuecomment-1489992645
Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from unittest import mock
1212

1313
import pytest
14-
import simcore_service_webserver.studies_dispatcher
1514
import sqlalchemy as sa
1615
from aiohttp import ClientResponse, ClientSession
1716
from aiohttp.test_utils import TestClient, TestServer
@@ -20,23 +19,16 @@
2019
from common_library.serialization import model_dump_with_secrets
2120
from common_library.users_enums import UserRole
2221
from models_library.projects_state import ProjectShareState, ProjectStatus
23-
from pydantic import BaseModel, ByteSize, TypeAdapter
22+
from pydantic import ByteSize, TypeAdapter
2423
from pytest_mock import MockerFixture
2524
from pytest_simcore.helpers.assert_checks import assert_status
2625
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
2726
from pytest_simcore.helpers.typing_env import EnvVarsDict
2827
from pytest_simcore.helpers.webserver_users import UserInfoDict
29-
from pytest_simcore.pydantic_models import (
30-
assert_validation_model,
31-
walk_model_examples_in_package,
32-
)
3328
from servicelib.aiohttp import status
3429
from settings_library.rabbit import RabbitSettings
3530
from settings_library.redis import RedisSettings
3631
from settings_library.utils_session import DEFAULT_SESSION_COOKIE_NAME
37-
from simcore_service_webserver.studies_dispatcher._controller.rest.nih_schemas import (
38-
ServiceGet,
39-
)
4032
from simcore_service_webserver.studies_dispatcher._models import ViewerInfo
4133
from sqlalchemy.sql import text
4234
from yarl import URL
@@ -183,123 +175,6 @@ async def director_v2_automock(
183175
]
184176

185177

186-
# REST-API
187-
# Samples taken from trials on http://127.0.0.1:9081/dev/doc#/viewer/get_viewer_for_file
188-
#
189-
190-
191-
def _get_base_url(client: TestClient) -> str:
192-
s = client.server
193-
assert isinstance(s.scheme, str)
194-
url = URL.build(scheme=s.scheme, host=s.host, port=s.port)
195-
return f"{url}"
196-
197-
198-
async def test_api_get_viewer_for_file(client: TestClient):
199-
resp = await client.get("/v0/viewers/default?file_type=JPEG")
200-
data, _ = await assert_status(resp, status.HTTP_200_OK)
201-
202-
base_url = _get_base_url(client)
203-
assert data == [
204-
{
205-
"file_type": "JPEG",
206-
"title": "Bio-formats v1.0.1",
207-
"view_url": f"{base_url}/view?file_type=JPEG&viewer_key=simcore/services/dynamic/bio-formats-web&viewer_version=1.0.1",
208-
},
209-
]
210-
211-
212-
async def test_api_get_viewer_for_unsupported_type(client: TestClient):
213-
resp = await client.get("/v0/viewers/default?file_type=UNSUPPORTED_TYPE")
214-
data, error = await assert_status(resp, status.HTTP_200_OK)
215-
assert data == []
216-
assert error is None
217-
218-
219-
async def test_api_list_supported_filetypes(client: TestClient):
220-
resp = await client.get("/v0/viewers/default")
221-
data, _ = await assert_status(resp, status.HTTP_200_OK)
222-
223-
base_url = _get_base_url(client)
224-
assert data == [
225-
{
226-
"title": "Rawgraphs v2.11.1",
227-
"file_type": "CSV",
228-
"view_url": f"{base_url}/view?file_type=CSV&viewer_key=simcore/services/dynamic/raw-graphs&viewer_version=2.11.1",
229-
},
230-
{
231-
"title": "Jupyterlab math v1.6.9",
232-
"file_type": "IPYNB",
233-
"view_url": f"{base_url}/view?file_type=IPYNB&viewer_key=simcore/services/dynamic/jupyter-octave-python-math&viewer_version=1.6.9",
234-
},
235-
{
236-
"title": "Bio-formats v1.0.1",
237-
"file_type": "JPEG",
238-
"view_url": f"{base_url}/view?file_type=JPEG&viewer_key=simcore/services/dynamic/bio-formats-web&viewer_version=1.0.1",
239-
},
240-
{
241-
"title": "Rawgraphs v2.11.1",
242-
"file_type": "JSON",
243-
"view_url": f"{base_url}/view?file_type=JSON&viewer_key=simcore/services/dynamic/raw-graphs&viewer_version=2.11.1",
244-
},
245-
{
246-
"title": "Bio-formats v1.0.1",
247-
"file_type": "PNG",
248-
"view_url": f"{base_url}/view?file_type=PNG&viewer_key=simcore/services/dynamic/bio-formats-web&viewer_version=1.0.1",
249-
},
250-
{
251-
"title": "Jupyterlab math v1.6.9",
252-
"file_type": "PY",
253-
"view_url": f"{base_url}/view?file_type=PY&viewer_key=simcore/services/dynamic/jupyter-octave-python-math&viewer_version=1.6.9",
254-
},
255-
{
256-
"title": "Rawgraphs v2.11.1",
257-
"file_type": "TSV",
258-
"view_url": f"{base_url}/view?file_type=TSV&viewer_key=simcore/services/dynamic/raw-graphs&viewer_version=2.11.1",
259-
},
260-
{
261-
"title": "Rawgraphs v2.11.1",
262-
"file_type": "XLSX",
263-
"view_url": f"{base_url}/view?file_type=XLSX&viewer_key=simcore/services/dynamic/raw-graphs&viewer_version=2.11.1",
264-
},
265-
]
266-
267-
268-
@pytest.mark.parametrize(
269-
"model_cls, example_name, example_data",
270-
walk_model_examples_in_package(simcore_service_webserver.studies_dispatcher),
271-
)
272-
def test_model_examples(
273-
model_cls: type[BaseModel], example_name: str, example_data: Any
274-
):
275-
assert_validation_model(
276-
model_cls, example_name=example_name, example_data=example_data
277-
)
278-
279-
280-
async def test_api_list_services(client: TestClient):
281-
assert client.app
282-
283-
url = client.app.router["list_latest_services"].url_for()
284-
response = await client.get(f"{url}")
285-
286-
data, error = await assert_status(response, status.HTTP_200_OK)
287-
288-
services = TypeAdapter(list[ServiceGet]).validate_python(data)
289-
assert services
290-
291-
# latest versions of services with everyone + ospar-product (see stmt_create_services_access_rights)
292-
assert services[0].key == "simcore/services/dynamic/raw-graphs"
293-
assert services[0].file_extensions == ["CSV", "JSON", "TSV", "XLSX"]
294-
assert "2.11.1" in services[0].view_url.query
295-
296-
assert services[1].key == "simcore/services/dynamic/jupyter-octave-python-math"
297-
assert services[1].file_extensions == ["IPYNB", "PY"]
298-
assert "1.6.9" in services[1].view_url.query
299-
300-
assert error is None
301-
302-
303178
# REDIRECT ROUTES --------------------------------------------------------------------------------
304179

305180

0 commit comments

Comments
 (0)