Skip to content

Commit 05ed52e

Browse files
author
Andrei Neagu
committed
added tests
1 parent 0085f4b commit 05ed52e

File tree

1 file changed

+50
-8
lines changed

1 file changed

+50
-8
lines changed

packages/simcore-sdk/tests/integration/test_node_ports_v2_nodeports2.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@
2929
SimcoreS3FileID,
3030
)
3131
from models_library.services_types import ServicePortKey
32+
from pytest_mock import MockerFixture
3233
from servicelib.progress_bar import ProgressBarData
3334
from settings_library.r_clone import RCloneSettings
3435
from simcore_sdk import node_ports_v2
3536
from simcore_sdk.node_ports_common.exceptions import UnboundPortError
3637
from simcore_sdk.node_ports_v2 import exceptions
3738
from simcore_sdk.node_ports_v2.links import ItemConcreteValue, PortLink
38-
from simcore_sdk.node_ports_v2.nodeports_v2 import Nodeports
39+
from simcore_sdk.node_ports_v2.nodeports_v2 import Nodeports, OutputsCallbacks
3940
from simcore_sdk.node_ports_v2.port import Port
4041
from utils_port_v2 import CONSTANT_UUID
4142

@@ -750,6 +751,34 @@ async def _upload_create_task(item_key: str) -> None:
750751
)
751752

752753

754+
class _Callbacks(OutputsCallbacks):
755+
async def aborted(self, key: ServicePortKey) -> None:
756+
pass
757+
758+
async def finished_succesfully(self, key: ServicePortKey) -> None:
759+
pass
760+
761+
async def finished_with_error(self, key: ServicePortKey) -> None:
762+
pass
763+
764+
765+
@pytest.fixture
766+
async def output_callbacks() -> _Callbacks:
767+
return _Callbacks()
768+
769+
770+
@pytest.fixture
771+
async def spy_outputs_callbaks(
772+
mocker: MockerFixture, output_callbacks: _Callbacks
773+
) -> dict[str, AsyncMock]:
774+
775+
return {
776+
"aborted": mocker.spy(output_callbacks, "aborted"),
777+
"finished_succesfully": mocker.spy(output_callbacks, "finished_succesfully"),
778+
"finished_with_error": mocker.spy(output_callbacks, "finished_with_error"),
779+
}
780+
781+
753782
async def test_batch_update_inputs_outputs(
754783
user_id: int,
755784
project_id: str,
@@ -758,6 +787,8 @@ async def test_batch_update_inputs_outputs(
758787
port_count: int,
759788
option_r_clone_settings: RCloneSettings | None,
760789
faker: Faker,
790+
output_callbacks: _Callbacks,
791+
spy_outputs_callbaks: dict[str, AsyncMock],
761792
) -> None:
762793
outputs = [(f"value_out_{i}", "integer", None) for i in range(port_count)]
763794
inputs = [(f"value_in_{i}", "integer", None) for i in range(port_count)]
@@ -772,13 +803,14 @@ async def test_batch_update_inputs_outputs(
772803
await check_config_valid(PORTS, config_dict)
773804

774805
async with ProgressBarData(num_steps=2, description=faker.pystr()) as progress_bar:
806+
port_values = (await PORTS.outputs).values()
775807
await PORTS.set_multiple(
776-
{
777-
ServicePortKey(port.key): (k, None)
778-
for k, port in enumerate((await PORTS.outputs).values())
779-
},
808+
{ServicePortKey(port.key): (k, None) for k, port in enumerate(port_values)},
780809
progress_bar=progress_bar,
781-
outputs_callbacks=AsyncMock(),
810+
outputs_callbacks=output_callbacks,
811+
)
812+
assert len(spy_outputs_callbaks["finished_succesfully"].call_args_list) == len(
813+
port_values
782814
)
783815
# pylint: disable=protected-access
784816
assert progress_bar._current_steps == pytest.approx(1) # noqa: SLF001
@@ -788,7 +820,11 @@ async def test_batch_update_inputs_outputs(
788820
for k, port in enumerate((await PORTS.inputs).values(), start=1000)
789821
},
790822
progress_bar=progress_bar,
791-
outputs_callbacks=AsyncMock(),
823+
outputs_callbacks=output_callbacks,
824+
)
825+
# inputs do not trigger callbacks
826+
assert len(spy_outputs_callbaks["finished_succesfully"].call_args_list) == len(
827+
port_values
792828
)
793829
assert progress_bar._current_steps == pytest.approx(2) # noqa: SLF001
794830

@@ -810,5 +846,11 @@ async def test_batch_update_inputs_outputs(
810846
await PORTS.set_multiple(
811847
{ServicePortKey("missing_key_in_both"): (123132, None)},
812848
progress_bar=progress_bar,
813-
outputs_callbacks=AsyncMock(),
849+
outputs_callbacks=output_callbacks,
814850
)
851+
852+
assert len(spy_outputs_callbaks["finished_succesfully"].call_args_list) == len(
853+
port_values
854+
)
855+
assert len(spy_outputs_callbaks["aborted"].call_args_list) == 0
856+
assert len(spy_outputs_callbaks["finished_with_error"].call_args_list) == 0

0 commit comments

Comments
 (0)