Skip to content

Commit 3a640c7

Browse files
author
Andrei Neagu
committed
Merge branch 'extending-nodeports' of github.com:GitHK/osparc-simcore-forked into extending-nodeports
2 parents a68be95 + b4384a3 commit 3a640c7

File tree

3 files changed

+67
-10
lines changed

3 files changed

+67
-10
lines changed

packages/simcore-sdk/src/simcore_sdk/node_data/data_manager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ async def is_file_present_in_storage(file_path: Path) -> bool:
7878
return await filemanager.entry_exists(
7979
store_id=0, # this is for simcore.s3
8080
s3_object=_create_s3_object(file_path),
81-
)
81+
)

services/web/server/src/simcore_service_webserver/groups_classifiers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@
3131

3232
class ClassifierItem(BaseModel):
3333
classifier: str = Field(
34-
..., description="Unique identifier used to tag studies or services", example=""
34+
..., description="Unique identifier used to tag studies or services"
3535
)
3636
display_name: str
37-
short_description: Optional[str] # TODO: truncate
37+
short_description: Optional[str]
3838
url: Optional[HttpUrl] = Field(
3939
None,
4040
description="Link to more information",
@@ -44,7 +44,7 @@ class ClassifierItem(BaseModel):
4444
@validator("short_description", pre=True)
4545
@classmethod
4646
def truncate_to_short(cls, v):
47-
if len(v) >= MAX_SIZE_SHORT_MSG:
47+
if v and len(v) >= MAX_SIZE_SHORT_MSG:
4848
return v[:MAX_SIZE_SHORT_MSG] + "…"
4949
return v
5050

@@ -70,21 +70,21 @@ class GroupClassifierRepository:
7070
def __init__(self, app: web.Application):
7171
self.engine = app[APP_DB_ENGINE_KEY]
7272

73-
async def get_bundle(self, gid: int) -> Dict[str, Any]:
73+
async def _get_bundle(self, gid: int) -> Optional[RowProxy]:
7474
async with self.engine.acquire() as conn:
75-
bundle = await conn.scalar(
75+
bundle: Optional[RowProxy] = await conn.scalar(
7676
sa.select([group_classifiers.c.bundle]).where(
7777
group_classifiers.c.gid == gid
7878
)
7979
)
80-
return bundle or {}
80+
return bundle
8181

8282
async def get_classifiers_from_bundle(self, gid: int) -> Dict[str, Any]:
83-
bundle = await self.get_bundle(gid)
83+
bundle = await self._get_bundle(gid)
8484
if bundle:
8585
try:
8686
# truncate bundle to what is needed and drop the rest
87-
bundle = Classifiers(**bundle).dict(exclude_unset=True)
87+
return Classifiers(**bundle).dict(exclude_unset=True, exclude_none=True)
8888
except ValidationError as err:
8989
logger.error(
9090
"DB corrupt data in 'groups_classifiers' table. "
@@ -93,7 +93,7 @@ async def get_classifiers_from_bundle(self, gid: int) -> Dict[str, Any]:
9393
gid,
9494
err,
9595
)
96-
return bundle
96+
return {}
9797

9898
async def group_uses_scicrunch(self, gid: int) -> bool:
9999
async with self.engine.acquire() as conn:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# pylint:disable=unused-argument
2+
# pylint:disable=redefined-outer-name
3+
# pylint:disable=no-name-in-module
4+
5+
from typing import Dict
6+
7+
import pytest
8+
import sqlalchemy as sa
9+
from servicelib.aiopg_utils import DataSourceName, create_pg_engine
10+
from simcore_service_webserver.constants import APP_DB_ENGINE_KEY
11+
from simcore_service_webserver.groups_classifiers import GroupClassifierRepository
12+
from sqlalchemy.sql import text
13+
14+
15+
@pytest.fixture
16+
def inject_tables(postgres_db: sa.engine.Engine):
17+
18+
stmt = text(
19+
"""\
20+
INSERT INTO "group_classifiers" ("id", "bundle", "created", "modified", "gid", "uses_scicrunch") VALUES
21+
(2, '{"vcs_ref": "asdfasdf", "vcs_url": "https://foo.classifiers.git", "build_date": "2021-01-20T15:19:30Z", "classifiers": {"project::dak": {"url": null, "logo": null, "aliases": [], "related": [], "markdown": "", "released": null, "classifier": "project::dak", "created_by": "Nicolas Chavannes", "github_url": null, "display_name": "DAK", "wikipedia_url": null, "short_description": null}, "organization::zmt": {"url": "https://zmt.swiss/", "logo": null, "aliases": ["Zurich MedTech AG"], "related": [], "markdown": "Zurich MedTech AG (ZMT) offers tools and best practices for targeted life sciences applications to simulate, analyze, and predict complex and dynamic biological processes and interactions. ZMT is a member of Zurich43", "released": null, "classifier": "organization::zmt", "created_by": "crespo", "github_url": null, "display_name": "ZMT", "wikipedia_url": null, "short_description": "ZMT is a member of Zurich43"}}, "collections": {"jupyterlab-math": {"items": ["crespo/osparc-demo"], "markdown": "Curated collection of repositories with examples of notebooks to run in jupyter-python-octave-math service", "created_by": "crespo", "display_name": "jupyterlab-math"}}}', '2021-03-04 23:17:43.373258', '2021-03-04 23:17:43.373258', 1, '0');
22+
"""
23+
)
24+
with postgres_db.connect() as conn:
25+
conn.execute(stmt)
26+
27+
28+
@pytest.fixture
29+
async def app(loop, postgres_dsn: Dict, inject_tables):
30+
31+
dsn = DataSourceName(
32+
user=postgres_dsn["user"],
33+
password=postgres_dsn["password"],
34+
database=postgres_dsn["database"],
35+
host=postgres_dsn["host"],
36+
port=postgres_dsn["port"],
37+
)
38+
39+
async with create_pg_engine(dsn) as engine:
40+
fake_app = {APP_DB_ENGINE_KEY: engine}
41+
yield fake_app
42+
43+
44+
async def test_classfiers_from_bundle(app):
45+
46+
repo = GroupClassifierRepository(app)
47+
48+
assert not await repo.group_uses_scicrunch(gid=1)
49+
50+
bundle = await repo.get_classifiers_from_bundle(gid=1)
51+
assert bundle
52+
53+
# Prunes extras and excludes unset and nones
54+
assert bundle["classifiers"]["project::dak"] == {
55+
"classifier": "project::dak",
56+
"display_name": "DAK",
57+
}

0 commit comments

Comments
 (0)