Skip to content

Commit 03a8b7f

Browse files
authored
♻️ maintenance: fixes scicrunch tests and set as integration tests (ITISFoundation#3018)
* split scicrunch into unit and integration tests * doc * adapts tests to pass
1 parent 81e4847 commit 03a8b7f

File tree

8 files changed

+165
-12
lines changed

8 files changed

+165
-12
lines changed

packages/dask-task-models-library/src/dask_task_models_library/container_tasks/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Config:
1313
{
1414
"server_address": "docker.io",
1515
"username": "admin",
16-
"password": "sfjlskdjoiw",
16+
"password": "123456",
1717
}
1818
]
1919
}

packages/pytest-simcore/src/pytest_simcore/helpers/utils_scrunch_citations.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,19 @@ def _split(citation: str) -> Tuple[str, str]:
2828
# https://www.addgene.org/44362/
2929
PLAMID_CITATIONS = split_citations(["(RRID:Addgene_44362)"])
3030

31-
# MMRRC, catalog https://www.mmrrc.org/catalog/cellLineSDS.php?mmrrc_id=26409
32-
ORGANISM_CITATIONS = split_citations(["(MMRRC Cat# 026409-UCD, RRID:MMRRC_026409-UCD)"])
31+
# MMRRC,
32+
# catalog https://www.mmrrc.org/catalog/cellLineSDS.php?mmrrc_id=26409
33+
# https://scicrunch.org/resolver/RRID:MMRRC_026409-UCD.json
34+
#
35+
# As of May 2022, changed proper_citation change from
36+
# '(MMRRC Cat# 026409-UCD, RRID:MMRRC_026409-UCD)' to
37+
# 'RRID:MMRRC_026409-UCD'
38+
#
39+
ORGANISM_CITATIONS = split_citations(["(RRID:MMRRC_026409-UCD)"])
3340

3441
# https://web.expasy.org/cellosaurus/CVCL_0033
35-
CELL_LINE_CITATIONS = split_citations(["(ATCC Cat# HTB-30, RRID:CVCL_0033)"])
42+
# As of May 2022, name changed from 'ATCC Cat# HTB-30' to 'AddexBio Cat# C0006007/65'
43+
CELL_LINE_CITATIONS = split_citations(["(AddexBio Cat# C0006007/65, RRID:CVCL_0033)"])
3644

3745
#
3846
# WARNING: Since Sep.2021, the order of the resolved hits list returned by
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
5+
6+
import pytest
7+
from simcore_service_webserver.scicrunch.settings import SciCrunchSettings
8+
9+
10+
@pytest.fixture
11+
async def settings() -> SciCrunchSettings:
12+
return SciCrunchSettings(SCICRUNCH_API_KEY="fake-secret-key")

services/web/server/tests/unit/isolated/scicrunch/test_scicrunch__resolver.py renamed to services/web/server/tests/integration/02/scicrunch/test_scicrunch__resolver.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# FIXME: PC check the CELL_LINE_CITATIONS test please
1111
from pytest_simcore.helpers.utils_scrunch_citations import ( # CELL_LINE_CITATIONS,
1212
ANTIBODY_CITATIONS,
13+
CELL_LINE_CITATIONS,
1314
ORGANISM_CITATIONS,
1415
PLAMID_CITATIONS,
1516
TOOL_CITATIONS,
@@ -20,18 +21,27 @@
2021

2122
@pytest.mark.parametrize(
2223
"name,rrid",
23-
TOOL_CITATIONS + ANTIBODY_CITATIONS + PLAMID_CITATIONS + ORGANISM_CITATIONS,
24+
TOOL_CITATIONS
25+
+ ANTIBODY_CITATIONS
26+
+ PLAMID_CITATIONS
27+
+ ORGANISM_CITATIONS
28+
+ CELL_LINE_CITATIONS,
2429
)
2530
async def test_scicrunch_resolves_all_valid_rrids(
2631
name: str, rrid: str, settings: SciCrunchSettings
2732
):
33+
# NOTE: this test run against https://scicrunch.org/resolver/{SCR_018997}.json
34+
# which is an open API (no auth required). Any change in the responses of that
35+
# service might cause a failure on this test
36+
# This tests checks some of the structure "deduced" from the responses so far.
37+
2838
async with ClientSession(timeout=ClientTimeout(total=30)) as client:
29-
resolved = await resolve_rrid(rrid, client, settings)
39+
resolved = await resolve_rrid(identifier=rrid, client=client, settings=settings)
3040

3141
assert resolved
3242
assert isinstance(resolved, ResolvedItem)
3343

34-
if resolved.is_unique:
44+
if resolved.is_unique and name:
3545
assert name in resolved.proper_citation
3646

3747
assert rrid in resolved.proper_citation
@@ -42,7 +52,7 @@ async def test_scicrunch_resolves_all_valid_rrids(
4252
# only rrid with a prefix
4353
assert resolved.proper_citation == f"RRID:{rrid}"
4454
else:
45-
# includes name and rrid
55+
# proper_citation includes both 'name' and 'rrid' but in different formats!
4656

4757
#
4858
# NOTE: why CELL_LINE_CITATIONS are removed from test parametrization ?
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# pylint:disable=unused-variable
2+
# pylint:disable=unused-argument
3+
# pylint:disable=redefined-outer-name
4+
5+
"""
6+
Use this test to emulate situations with scicrunch service API
7+
8+
"""
9+
import json
10+
import os
11+
from pathlib import Path
12+
13+
import pytest
14+
from aioresponses.core import aioresponses
15+
from servicelib.aiohttp.application import create_safe_application
16+
from servicelib.aiohttp.client_session import get_client_session
17+
from simcore_service_webserver.application_settings import setup_settings
18+
from simcore_service_webserver.scicrunch.plugin import setup_scicrunch
19+
from simcore_service_webserver.scicrunch.service_client import (
20+
ResearchResource,
21+
SciCrunch,
22+
)
23+
24+
25+
@pytest.fixture
26+
async def mock_scicrunch_service_api(fake_data_dir: Path, mock_env_devel_environment):
27+
assert mock_env_devel_environment["SCICRUNCH_API_KEY"] == os.environ.get(
28+
"SCICRUNCH_API_KEY"
29+
)
30+
31+
API_KEY = os.environ.get("SCICRUNCH_API_KEY")
32+
assert os.environ.get("SCICRUNCH_API_BASE_URL") == "https://scicrunch.org/api/1"
33+
34+
with aioresponses() as mock:
35+
# curl -X GET "https://scicrunch.org/api/1/resource/fields/autocomplete?field=Resource%20Name&value=octave" -H "accept: application/json
36+
mock.get(
37+
f"https://scicrunch.org/api/1/resource/fields/autocomplete?field=Resource%20Name&value=octave&key={API_KEY}",
38+
status=200,
39+
payload={
40+
"data": [
41+
{
42+
"rid": "SCR_000860",
43+
"original_id": "nlx_155680",
44+
"name": "cbiNifti: Matlab/Octave Nifti library",
45+
},
46+
{
47+
"rid": "SCR_009637",
48+
"original_id": "nlx_155924",
49+
"name": "Pipeline System for Octave and Matlab",
50+
},
51+
{
52+
"rid": "SCR_014398",
53+
"original_id": "SCR_014398",
54+
"name": "GNU Octave",
55+
},
56+
],
57+
"success": "true",
58+
},
59+
)
60+
# curl -X GET "https://scicrunch.org/api/1/resource/fields/view/SCR_018997" -H "accept: application/json"
61+
mock.get(
62+
f"https://scicrunch.org/api/1/resource/fields/view/SCR_018997?key={API_KEY}",
63+
status=200,
64+
payload=json.loads(
65+
(fake_data_dir / "get_osparc_resource_payload.json").read_text()
66+
),
67+
)
68+
# curl -X GET "https://scicrunch.org/api/1/resource/versions/all/SCR_018997" -H "accept: application/json"
69+
mock.get(
70+
f"https://scicrunch.org/api/1/resource/versions/all/SCR_018997?key={API_KEY}",
71+
status=200,
72+
payload=json.loads(
73+
'{"data":[{"version":2,"status":"Curated","time":1598984801,"uid":34739,"username":"Edyta Vieth","cid":null},{"version":1,"status":"Pending","time":1598898249,"uid":43,"username":"Anita Bandrowski","cid":30}],"success":true}'
74+
),
75+
)
76+
77+
yield mock
78+
79+
80+
@pytest.fixture
81+
async def mock_scicrunch_service_resolver(
82+
fake_data_dir: Path, mock_env_devel_environment, aioresponses_mocker
83+
):
84+
aioresponses_mocker.get(
85+
"https://scicrunch.org/resolver/SCR_018997.json",
86+
status=200,
87+
payload=json.loads(
88+
(fake_data_dir / "get_scicrunch_resolver_response.json").read_text()
89+
),
90+
)
91+
92+
93+
@pytest.fixture
94+
async def fake_app(mock_env_devel_environment):
95+
# By using .env-devel we ensure all needed variables are at
96+
# least defined there
97+
print("app's environment variables", format(mock_env_devel_environment))
98+
99+
app = create_safe_application()
100+
101+
setup_settings(app)
102+
setup_scicrunch(app)
103+
104+
yield app
105+
106+
client = get_client_session(app)
107+
await client.close()
108+
109+
110+
## TESTS -------------------------------------------------------
111+
112+
113+
def test_setup_scicrunch_submodule(fake_app):
114+
# scicruch should be init
115+
scicrunch = SciCrunch.get_instance(fake_app)
116+
assert scicrunch
117+
assert scicrunch.client == get_client_session(fake_app)
118+
119+
120+
async def test_get_research_resource(fake_app, mock_scicrunch_service_resolver):
121+
# mock_scicrunch_service_api):
122+
scicrunch = SciCrunch.get_instance(fake_app)
123+
resource: ResearchResource = await scicrunch.get_resource_fields(rrid="SCR_018997")
124+
125+
assert resource.rrid == "RRID:SCR_018997"
126+
assert resource.name == "o²S²PARC"
127+
assert "Simulation platform" in resource.description

services/web/server/tests/unit/isolated/scicrunch/__init__.py

Whitespace-only changes.

services/web/server/tests/unit/isolated/scicrunch/test_scicrunch_models.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,3 @@ def test_research_resource_model(name, rrid_tag):
6464
)
6565

6666
assert re.match(STRICT_RRID_PATTERN, resource.rrid)
67-
68-
69-
def test_models_conversion():
70-
assert True

0 commit comments

Comments
 (0)