Skip to content

Commit 59dbea6

Browse files
committed
WIP: tests scicrunch
1 parent fc39c9f commit 59dbea6

File tree

2 files changed

+73
-13
lines changed

2 files changed

+73
-13
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
####################################################################################################################
77
# NOTES
88

9+
910
#
1011
# To check times pytest --pdb -vv --durations=0 tests/unit/isolated/test_classifiers.py
1112
#
@@ -52,13 +53,32 @@
5253
import re
5354
from collections import defaultdict
5455
from copy import deepcopy
55-
from typing import List
56+
from typing import DefaultDict, List, Set
5657

5758
from pydantic import BaseModel, Field
5859

5960
# TODO: emulate server for testing
6061
# TODO:
6162

63+
GROUP_CLASSIFIER_SAMPLE = {
64+
"build_date": "2020-12-14T18:10:00Z",
65+
"classifiers": {
66+
"Programming Language::Python": {
67+
"classifier": "RRID:SCR_008394",
68+
"display_name": "Python",
69+
"short_description": "Python Programming Language",
70+
},
71+
"Programming Language::Octave": {
72+
"classifier": "RRID:SCR_014398",
73+
"display_name": "GNU Octave",
74+
},
75+
"Jupyter Notebook": {
76+
"classifier": "RRID:SCR_018315",
77+
"display_name": "Jupyter Notebook",
78+
},
79+
},
80+
}
81+
6282

6383
SPLIT_STRIP_PATTERN = r"[^:\s][^:]*[^:\s]*"
6484

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

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
import pytest
1010
from aiohttp import ClientSession
1111
from servicelib.client_session import get_client_session
12-
from simcore_service_webserver.scicrunch import (
13-
SciCrunchAPI,
14-
SciCrunchSettings,
15-
ValidationResult,
16-
)
12+
from simcore_service_webserver.scicrunch import SciCrunchAPI, SciCrunchSettings
13+
from simcore_service_webserver.scicrunch_api import ValidationResult
14+
from simcore_service_webserver.scicrunch_models import ListOfResourceHits
1715

1816
# TODO: emulate server for testing
1917
RRID_PORTAL_API_KEY = os.environ.get("RRID_PORTAL_API_KEY")
@@ -29,19 +27,32 @@ async def fake_app(monkeypatch, loop):
2927

3028

3129
@pytest.fixture
32-
async def scicrunch(fake_app):
33-
scicrunch_api = SciCrunchAPI.create_instance(
30+
async def scicrunch(fake_app) -> SciCrunchAPI:
31+
scicrunch_api = SciCrunchAPI.acquire_instance(
3432
app=fake_app, settings=SciCrunchSettings(api_key=RRID_PORTAL_API_KEY)
3533
)
3634
assert scicrunch_api is SciCrunchAPI.get_instance(fake_app)
3735
return scicrunch_api
3836

3937

38+
# From https://scicrunch.org/resources
39+
VALID_RRID_SAMPLES = [
40+
("Antibody", "RRID:AB_90755"),
41+
("Plasmid", "RRID:Addgene_44362"),
42+
("Organism", "RRID:MMRRC_026409-UCD"),
43+
("Cell Line", "RRID:CVCL_0033"),
44+
("Tool", "RRID:SCR_007358"),
45+
]
46+
47+
48+
## TESTS -------------------------------------------------------
49+
50+
4051
@pytest.mark.skipif(
4152
RRID_PORTAL_API_KEY is None,
4253
reason="Testing agains actual service is intended for manual exploratory testing",
4354
)
44-
async def test_scicrunch_api_specs(loop):
55+
async def test_scicrunch_service_api_specs(loop):
4556
async with ClientSession() as client:
4657
resp = await client.get("https://scicrunch.org/swagger-docs/swagger.json")
4758
openapi_specs = await resp.json()
@@ -63,9 +74,10 @@ async def test_scicrunch_api_specs(loop):
6374
("Octave", "RRID:SCR_014398"), # TODO: should be valid!
6475
(None, "SCR_INVALID_XXXXX"),
6576
(None, "ANOTHER_INVALID_RRID"),
66-
],
77+
]
78+
+ VALID_RRID_SAMPLES,
6779
)
68-
async def test_rrid_validation(name, rrid, scicrunch):
80+
async def test_scicrunch_service_rrid_validation(name, rrid, scicrunch):
6981

7082
validation_result = await scicrunch.validate_rrid(rrid)
7183

@@ -85,8 +97,36 @@ async def test_rrid_validation(name, rrid, scicrunch):
8597
("Language::Python", "SCR_008394"),
8698
("Language::Octave", "SCR_014398"),
8799
("osparc", "SCR_018997"), # proper citation: (o²S²PARC, RRID:SCR_018997)
88-
],
100+
]
101+
+ VALID_RRID_SAMPLES,
89102
)
90-
async def test_get_rrid_fields(name, rrid, scicrunch):
103+
async def test_scicrunch_service_get_rrid_fields(name, rrid, scicrunch):
104+
assert name is not None
91105
resource = await scicrunch.get_resource_fields(rrid)
92106
assert resource.scicrunch_id == rrid
107+
108+
109+
@pytest.mark.skipif(
110+
RRID_PORTAL_API_KEY is None,
111+
reason="Testing agains actual service is intended for manual exploratory testing",
112+
)
113+
async def test_scicrunch_service_autocomplete(scicrunch):
114+
115+
expected = ListOfResourceHits(
116+
__root__=[
117+
{
118+
"rid": "SCR_000860",
119+
"original_id": "nlx_155680",
120+
"name": "cbiNifti: Matlab/Octave Nifti library",
121+
},
122+
{
123+
"rid": "SCR_009637",
124+
"original_id": "nlx_155924",
125+
"name": "Pipeline System for Octave and Matlab",
126+
},
127+
{"rid": "SCR_014398", "original_id": "SCR_014398", "name": "GNU Octave"},
128+
]
129+
)
130+
131+
hits = await scicrunch.search_resource("octave")
132+
assert expected == hits

0 commit comments

Comments
 (0)