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

🐛 Sync nodes when patching #6973

Original file line number Diff line number Diff line change
Expand Up @@ -1047,13 +1047,17 @@ async def patch_project_node(
if _node_patch_exclude_unset.get("label"):
await dynamic_scheduler_api.update_projects_networks(app, project_id=project_id)

# 5. Updates project states for user, if inputs have been changed
if "inputs" in _node_patch_exclude_unset:
# 5. Updates project states for user, if inputs/outputs have been changed
if {"inputs", "outputs"} & _node_patch_exclude_unset.keys():
giancarloromeo marked this conversation as resolved.
Show resolved Hide resolved
giancarloromeo marked this conversation as resolved.
Show resolved Hide resolved
updated_project = await add_project_states_for_user(
user_id=user_id, project=updated_project, is_template=False, app=app
)
for node_uuid in updated_project["workbench"]:
await notify_project_node_update(
app, updated_project, node_uuid, errors=None
)
return

# 6. Notify project node update
await notify_project_node_update(app, updated_project, node_id, errors=None)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ def mock_catalog_rpc_check_for_service(mocker: MockerFixture):
)


@pytest.fixture
def mocked_notify_project_node_update(mocker: MockerFixture):
return mocker.patch(
"simcore_service_webserver.projects.projects_api.notify_project_node_update",
)


@pytest.mark.parametrize(
"user_role,expected",
[
Expand Down Expand Up @@ -195,7 +202,7 @@ async def test_patch_project_node(
_tested_node = data["workbench"][node_id]

assert _tested_node["label"] == "testing-string"
assert _tested_node["progress"] == None
assert _tested_node["progress"] is None
assert _tested_node["key"] == _patch_key["key"]
assert _tested_node["version"] == _patch_version["version"]
assert _tested_node["inputs"] == _patch_inputs["inputs"]
Expand All @@ -205,6 +212,83 @@ async def test_patch_project_node(
assert _tested_node["outputs"] == _patch_outputs["outputs"]


@pytest.mark.parametrize(
"user_role,expected", [(UserRole.USER, status.HTTP_204_NO_CONTENT)]
)
async def test_patch_project_node_notifies(
mocker: MockerFixture,
client: TestClient,
logged_user: UserInfoDict,
user_project: ProjectDict,
expected: HTTPStatus,
mock_catalog_api_get_services_for_user_in_product,
mock_project_uses_available_services,
mock_catalog_rpc_check_for_service,
mocked_notify_project_node_update,
):

node_id = next(iter(user_project["workbench"]))
assert client.app
base_url = client.app.router["patch_project_node"].url_for(
project_id=user_project["uuid"], node_id=node_id
)

# inputs
_patch_inputs = {
"key": "simcore/services/dynamic/patch-service-key",
}
resp = await client.patch(
f"{base_url}",
data=json.dumps(_patch_inputs),
)
await assert_status(resp, expected)
assert mocked_notify_project_node_update.call_count == 1
args = mocked_notify_project_node_update.await_args_list
assert args[0][0][1]["workbench"][node_id]["key"] == _patch_inputs["key"]
assert f"{args[0][0][2]}" == node_id


@pytest.mark.parametrize(
"user_role,expected", [(UserRole.USER, status.HTTP_204_NO_CONTENT)]
)
async def test_patch_project_node_inputs_notifies(
mocker: MockerFixture,
client: TestClient,
logged_user: UserInfoDict,
user_project: ProjectDict,
expected: HTTPStatus,
mock_catalog_api_get_services_for_user_in_product,
mock_project_uses_available_services,
mocked_notify_project_node_update,
):
node_id = next(iter(user_project["workbench"]))
assert client.app
base_url = client.app.router["patch_project_node"].url_for(
project_id=user_project["uuid"], node_id=node_id
)

# inputs
_patch_inputs = {
"inputs": {
"input_1": {
"nodeUuid": "c374e5ba-fc42-5c40-ae74-df7ef337f597",
"output": "out_1",
},
}
}
resp = await client.patch(
f"{base_url}",
data=json.dumps(_patch_inputs),
)
await assert_status(resp, expected)
assert mocked_notify_project_node_update.call_count > 1
# 1 message per node updated
assert [
call_args[0][2]
for call_args in mocked_notify_project_node_update.await_args_list
] == list(user_project["workbench"].keys())


@pytest.mark.parametrize(
"user_role,expected", [(UserRole.USER, status.HTTP_204_NO_CONTENT)]
)
Expand Down
Loading