|
| 1 | +import types |
| 2 | +from unittest.mock import AsyncMock |
| 3 | + |
| 4 | +from simcore_sdk.node_ports_common import dbmanager |
| 5 | + |
| 6 | + |
| 7 | +async def test_update_comp_run_snapshot_tasks_if_computational(monkeypatch): |
| 8 | + engine = AsyncMock() |
| 9 | + connection = AsyncMock() |
| 10 | + project_id = "project-1" |
| 11 | + node_uuid = "node-1" |
| 12 | + node_configuration = { |
| 13 | + "schema": {"foo": "bar"}, |
| 14 | + "inputs": {"a": 1}, |
| 15 | + "outputs": {"b": 2}, |
| 16 | + "run_hash": "hash123", |
| 17 | + } |
| 18 | + node = types.SimpleNamespace(node_class="COMPUTATIONAL") |
| 19 | + |
| 20 | + get_node_mock = AsyncMock(return_value=node) |
| 21 | + get_latest_run_id_mock = AsyncMock(return_value="run-1") |
| 22 | + update_mock = AsyncMock() |
| 23 | + |
| 24 | + monkeypatch.setattr(dbmanager, "_get_node_from_db", get_node_mock) |
| 25 | + monkeypatch.setattr( |
| 26 | + dbmanager, "get_latest_run_id_for_project", get_latest_run_id_mock |
| 27 | + ) |
| 28 | + monkeypatch.setattr(dbmanager, "update_for_run_id_and_node_id", update_mock) |
| 29 | + |
| 30 | + await dbmanager._update_comp_run_snapshot_tasks_if_computational( |
| 31 | + engine, connection, project_id, node_uuid, node_configuration |
| 32 | + ) |
| 33 | + |
| 34 | + get_node_mock.assert_awaited_once_with(project_id, node_uuid, connection) |
| 35 | + get_latest_run_id_mock.assert_awaited_once_with( |
| 36 | + engine, connection, project_id=project_id |
| 37 | + ) |
| 38 | + update_mock.assert_awaited_once() |
| 39 | + _, kwargs = update_mock.call_args |
| 40 | + assert kwargs["run_id"] == "run-1" |
| 41 | + assert kwargs["node_id"] == node_uuid |
| 42 | + assert kwargs["data"]["schema"] == node_configuration["schema"] |
| 43 | + |
| 44 | + |
| 45 | +async def test_update_comp_run_snapshot_tasks_if_not_computational(monkeypatch): |
| 46 | + engine = AsyncMock() |
| 47 | + connection = AsyncMock() |
| 48 | + project_id = "project-2" |
| 49 | + node_uuid = "node-2" |
| 50 | + node_configuration = { |
| 51 | + "schema": {}, |
| 52 | + "inputs": {}, |
| 53 | + "outputs": {}, |
| 54 | + } |
| 55 | + node = types.SimpleNamespace(node_class="ITERATIVE") |
| 56 | + |
| 57 | + get_node_mock = AsyncMock(return_value=node) |
| 58 | + get_latest_run_id_mock = AsyncMock() |
| 59 | + update_mock = AsyncMock() |
| 60 | + |
| 61 | + monkeypatch.setattr(dbmanager, "_get_node_from_db", get_node_mock) |
| 62 | + monkeypatch.setattr( |
| 63 | + dbmanager, "get_latest_run_id_for_project", get_latest_run_id_mock |
| 64 | + ) |
| 65 | + monkeypatch.setattr(dbmanager, "update_for_run_id_and_node_id", update_mock) |
| 66 | + |
| 67 | + await dbmanager._update_comp_run_snapshot_tasks_if_computational( |
| 68 | + engine, connection, project_id, node_uuid, node_configuration |
| 69 | + ) |
| 70 | + |
| 71 | + get_node_mock.assert_awaited_once_with(project_id, node_uuid, connection) |
| 72 | + get_latest_run_id_mock.assert_not_awaited() |
| 73 | + update_mock.assert_not_awaited() |
0 commit comments