Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixes wrong signature and adds tests #2812

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
from typing import Any, AnyStr, Dict, List, Match, Optional, Set, Tuple, Union
from uuid import UUID, uuid1, uuid5

from models_library.projects_nodes_io import BaseFileLink, DownloadLink, PortLink
from servicelib.decorators import safe_return
from yarl import URL

from .project_models import ProjectDict

log = logging.getLogger(__name__)
variable_pattern = re.compile(r"^{{\W*(\w+)\W*}}$")

VARIABLE_PATTERN = re.compile(r"^{{\W*(\w+)\W*}}$")

# NOTE: InputTypes/OutputTypes that are NOT links
NOT_IO_LINK_TYPES_TUPLE = (str, int, float, bool)


def clone_project_document(
Expand Down Expand Up @@ -111,7 +114,7 @@ def _get_param_input_match(name, value, access) -> Optional[Match[AnyStr]]:
isinstance(value, str)
and access.get(name, "ReadAndWrite") == "ReadAndWrite"
):
match = variable_pattern.match(value)
match = VARIABLE_PATTERN.match(value)
return match
return None

Expand Down Expand Up @@ -270,10 +273,12 @@ def any_node_inputs_changed(
# for new nodes, detect only added link
for input_name, input_value in updated_node.get("inputs", {}).items():
# TODO: how to ensure this list of "links types" is up-to-date!??
# These types represent links that node-ports need to handle
if isinstance(input_value, PortLink, DownloadLink, BaseFileLink):
# Anything outside of the PRIMITIVE_TYPES_TUPLE, is interpreted as links
# that node-ports need to handle. This is a simpler check with ProjectDict
# since otherwise test will require constructing BaseModels on input_values
if not isinstance(input_value, NOT_IO_LINK_TYPES_TUPLE):
log.debug(
"Change detected in projects[%s].workbench[%s].inputs[%s]=%s",
"Change detected in projects[%s].workbench[%s].inputs[%s]=%s. Link was added.",
f"{project_uuid=}",
f"{node_id=}",
f"{input_name}",
Expand Down
44 changes: 43 additions & 1 deletion services/web/server/tests/unit/isolated/test_projects_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import pytest
from jsonschema import ValidationError
from simcore_service_webserver._resources import resources
from simcore_service_webserver.projects.project_models import ProjectDict
from simcore_service_webserver.projects.projects_utils import (
any_node_inputs_changed,
clone_project_document,
project_get_depending_nodes,
)
Expand Down Expand Up @@ -75,9 +77,49 @@ def test_clone_project_document(
],
)
async def test_project_get_depending_nodes(
fake_project_data: Dict[str, Any], node_uuid: str, expected_dependencies: Set[str]
fake_project_data: ProjectDict, node_uuid: str, expected_dependencies: Set[str]
):
set_of_depending_nodes = await project_get_depending_nodes(
fake_project_data, node_uuid
)
assert set_of_depending_nodes == expected_dependencies


def test_any_node_inputs_changed(fake_project_data: ProjectDict):

current_project = deepcopy(fake_project_data)
updated_project = deepcopy(fake_project_data)

assert not any_node_inputs_changed(updated_project, current_project)

assert (
fake_project_data == current_project
), "any_node_inputs_changed MUST NOT modify data "
assert (
fake_project_data == updated_project
), "any_node_inputs_changed MUST NOT modify data"

# add new node w/ a link
fake_node = deepcopy(
fake_project_data["workbench"]["5739e377-17f7-4f09-a6ad-62659fb7fdec"]
)
assert fake_node["inputs"] == {
"Na": 0,
"Kr": 0,
"BCL": 200,
"NBeats": 5,
"Ligand": 0,
"cAMKII": "WT",
"initfile": {
"nodeUuid": "b4b20476-e7c0-47c2-8cc4-f66ac21a13bf",
"output": "outFile",
},
}

updated_project["workbench"]["15d79982-9273-435b-bab6-e5366ba19165"] = fake_node

assert any_node_inputs_changed(updated_project, current_project)

# add new node w/o a link
fake_node["inputs"].pop("initfile")
assert not any_node_inputs_changed(updated_project, current_project)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from jsonschema import SchemaError
from servicelib.aiohttp.jsonschema_specs import create_jsonschema_specs
from simcore_service_webserver.projects.projects_utils import (
VARIABLE_PATTERN,
substitute_parameterized_inputs,
variable_pattern,
)
from yarl import URL

Expand All @@ -35,8 +35,8 @@ def mock_parametrized_project(fake_data_dir):

# check parameterized
inputs = prj["workbench"]["de2578c5-431e-409d-998c-c1f04de67f8b"]["inputs"]
assert variable_pattern.match(inputs["Na"])
assert variable_pattern.match(inputs["BCL"])
assert VARIABLE_PATTERN.match(inputs["Na"])
assert VARIABLE_PATTERN.match(inputs["BCL"])
return prj


Expand Down