Skip to content

Commit

Permalink
Allows matching from general to specific data
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Jun 16, 2021
1 parent cfdf4f8 commit 142276a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@ async def get_compatible_outputs_given_target_input_handler(request: Request):
#


def can_connect(from_output: ServiceOutput, to_input: ServiceInput) -> bool:
def can_connect(
from_output: ServiceOutput, to_input: ServiceInput, *, strict: bool = False
) -> bool:
# FIXME: can_connect is a very very draft version

# compatible units
Expand All @@ -303,9 +305,18 @@ def can_connect(from_output: ServiceOutput, to_input: ServiceInput) -> bool:
ok = from_output.property_type == to_input.property_type
if not ok:
ok = (
# data: -> data:*/*
to_input.property_type == "data:*/*"
and from_output.property_type.startswith("data:")
)

if not strict:
# NOTE: by default, this is allowed in the UI but not in a more strict plausibility check
# data:*/* -> data:
ok |= (
from_output.property_type == "data:*/*"
and to_input.property_type.startswith("data:")
)
return ok


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from models_library.services import ServiceInput, ServiceOutput
from simcore_service_webserver.catalog_api_handlers import can_connect


def test_can_connect():
# Reproduces https://github.com/ITISFoundation/osparc-issues/issues/442
file_picker_outfile = {
"displayOrder": 2,
"label": "File Picker",
"description": "Picker",
"type": "data:*/*",
}

input_sleeper_input_1 = {
"displayOrder": 1,
"label": "Sleeper",
"description": "sleeper input file",
"type": "data:text/plain",
}

# data:*/* -> data:text/plain
assert can_connect(
from_output=ServiceOutput.parse_obj(file_picker_outfile),
to_input=ServiceInput.parse_obj(input_sleeper_input_1),
)
assert not can_connect(
from_output=ServiceOutput.parse_obj(file_picker_outfile),
to_input=ServiceInput.parse_obj(input_sleeper_input_1),
strict=True,
)

# data:text/plain -> data:*/*
assert can_connect(
from_output=ServiceOutput.parse_obj(input_sleeper_input_1),
to_input=ServiceInput.parse_obj(file_picker_outfile),
)
assert can_connect(
from_output=ServiceOutput.parse_obj(input_sleeper_input_1),
to_input=ServiceInput.parse_obj(file_picker_outfile),
strict=True,
)

0 comments on commit 142276a

Please sign in to comment.