|
| 1 | +# pylint: disable=redefined-outer-name |
| 2 | +# pylint: disable=unused-argument |
| 3 | + |
| 4 | +from inspect import signature |
| 5 | + |
| 6 | +import pytest |
| 7 | +from simcore_service_dynamic_sidecar.core.validation import ( |
| 8 | + _DEFAULT_BACKEND_NETWORK_NAME, |
| 9 | + _inject_backend_networking, |
| 10 | + parse_compose_spec, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +def incoming_iseg_compose_file_content() -> str: |
| 16 | + return """ |
| 17 | +networks: |
| 18 | + dy-sidecar_6f54ecb4-cac2-424a-8b72-ee9366026ff8: |
| 19 | + driver: overlay |
| 20 | + external: |
| 21 | + name: dy-sidecar_6f54ecb4-cac2-424a-8b72-ee9366026ff8 |
| 22 | +services: |
| 23 | + iseg-app: |
| 24 | + image: registry.osparc.org/simcore/services/dynamic/iseg-app:1.0.7 |
| 25 | + iseg-web: |
| 26 | + image: registry.osparc.org/simcore/services/dynamic/iseg-web:1.0.7 |
| 27 | + networks: |
| 28 | + dy-sidecar_6f54ecb4-cac2-424a-8b72-ee9366026ff8: |
| 29 | +version: \'3.7\' |
| 30 | + """ |
| 31 | + |
| 32 | + |
| 33 | +@pytest.fixture |
| 34 | +def incoming_iseg_compose_file_content_missing_network() -> str: |
| 35 | + return """ |
| 36 | +networks: |
| 37 | +services: |
| 38 | + iseg-app: |
| 39 | + image: registry.osparc.org/simcore/services/dynamic/iseg-app:1.0.7 |
| 40 | + iseg-web: |
| 41 | + image: registry.osparc.org/simcore/services/dynamic/iseg-web:1.0.7 |
| 42 | + networks: |
| 43 | + dy-sidecar_6f54ecb4-cac2-424a-8b72-ee9366026ff8: |
| 44 | +version: \'3.7\' |
| 45 | + """ |
| 46 | + |
| 47 | + |
| 48 | +@pytest.fixture |
| 49 | +def incoming_iseg_compose_file_content_missing_network_list() -> str: |
| 50 | + return """ |
| 51 | +networks: |
| 52 | +services: |
| 53 | + iseg-app: |
| 54 | + image: registry.osparc.org/simcore/services/dynamic/iseg-app:1.0.7 |
| 55 | + iseg-web: |
| 56 | + image: registry.osparc.org/simcore/services/dynamic/iseg-web:1.0.7 |
| 57 | + networks: |
| 58 | + - dy-sidecar_6f54ecb4-cac2-424a-8b72-ee9366026ff8 |
| 59 | +version: \'3.7\' |
| 60 | + """ |
| 61 | + |
| 62 | + |
| 63 | +@pytest.fixture |
| 64 | +def incoming_iseg_compose_file_content_no_networks() -> str: |
| 65 | + return """ |
| 66 | +services: |
| 67 | + iseg-app: |
| 68 | + image: registry.osparc.org/simcore/services/dynamic/iseg-app:1.0.7 |
| 69 | + iseg-web: |
| 70 | + image: registry.osparc.org/simcore/services/dynamic/iseg-web:1.0.7 |
| 71 | +version: \'3.7\' |
| 72 | + """ |
| 73 | + |
| 74 | + |
| 75 | +@pytest.fixture( |
| 76 | + params=[ |
| 77 | + "incoming_iseg_compose_file_content", |
| 78 | + "incoming_iseg_compose_file_content_missing_network", |
| 79 | + "incoming_iseg_compose_file_content_missing_network_list", |
| 80 | + "incoming_iseg_compose_file_content_no_networks", |
| 81 | + ] |
| 82 | +) |
| 83 | +def incoming_compose_file( |
| 84 | + request, |
| 85 | + incoming_iseg_compose_file_content: str, |
| 86 | + incoming_iseg_compose_file_content_missing_network: str, |
| 87 | + incoming_iseg_compose_file_content_missing_network_list: str, |
| 88 | + incoming_iseg_compose_file_content_no_networks: str, |
| 89 | +) -> str: |
| 90 | + # check that fixture_name is present in this function's parameters |
| 91 | + fixture_name = request.param |
| 92 | + sig = signature(incoming_compose_file) |
| 93 | + assert fixture_name in sig.parameters, ( |
| 94 | + f"Provided fixture name {fixture_name} was not found " |
| 95 | + f"as a parameter in the signature {sig}" |
| 96 | + ) |
| 97 | + |
| 98 | + # returns the parameter by name from the ones declared in the signature |
| 99 | + result: str = locals()[fixture_name] |
| 100 | + return result |
| 101 | + |
| 102 | + |
| 103 | +def test_inject_backend_networking(incoming_compose_file: str): |
| 104 | + """ |
| 105 | + NOTE: this goes with issue [https://github.com/ITISFoundation/osparc-simcore/issues/3261] |
| 106 | + """ |
| 107 | + parsed_compose_spec = parse_compose_spec(incoming_compose_file) |
| 108 | + _inject_backend_networking(parsed_compose_spec) |
| 109 | + assert _DEFAULT_BACKEND_NETWORK_NAME in parsed_compose_spec["networks"] |
| 110 | + assert ( |
| 111 | + _DEFAULT_BACKEND_NETWORK_NAME |
| 112 | + in parsed_compose_spec["services"]["iseg-app"]["networks"] |
| 113 | + ) |
| 114 | + assert ( |
| 115 | + _DEFAULT_BACKEND_NETWORK_NAME |
| 116 | + in parsed_compose_spec["services"]["iseg-web"]["networks"] |
| 117 | + ) |
0 commit comments