|
5 | 5 |
|
6 | 6 | import json |
7 | 7 | from copy import deepcopy |
8 | | -from pprint import pformat |
9 | 8 | from typing import Any, Final, NamedTuple |
10 | 9 |
|
11 | 10 | import pytest |
|
33 | 32 | from models_library.services_resources import DEFAULT_SINGLE_SERVICE_NAME |
34 | 33 | from models_library.utils.string_substitution import TextTemplate |
35 | 34 | from pydantic import BaseModel, TypeAdapter, ValidationError |
| 35 | +from pytest_simcore.pydantic_models import ( |
| 36 | + assert_validation_model, |
| 37 | + iter_model_examples_in_class, |
| 38 | +) |
36 | 39 |
|
37 | 40 |
|
38 | 41 | class _Parametrization(NamedTuple): |
@@ -89,17 +92,23 @@ def test_service_settings(): |
89 | 92 | service_setting.set_destination_containers(["random_value1", "random_value2"]) |
90 | 93 |
|
91 | 94 |
|
92 | | -@pytest.mark.parametrize("model_cls", [SimcoreServiceLabels]) |
| 95 | +@pytest.mark.parametrize( |
| 96 | + "model_cls, example_name, example_data", |
| 97 | + iter_model_examples_in_class(SimcoreServiceLabels), |
| 98 | +) |
93 | 99 | def test_correctly_detect_dynamic_sidecar_boot( |
94 | | - model_cls: type[BaseModel], model_cls_examples: dict[str, dict[str, Any]] |
| 100 | + model_cls: type[BaseModel], example_name: str, example_data: Any |
95 | 101 | ): |
96 | | - for name, example in model_cls_examples.items(): |
97 | | - print(name, ":", pformat(example)) |
98 | | - model_instance = TypeAdapter(model_cls).validate_python(example) |
99 | | - assert model_instance.callbacks_mapping is not None |
100 | | - assert model_instance.needs_dynamic_sidecar == ( |
101 | | - "simcore.service.paths-mapping" in example |
102 | | - ) |
| 102 | + |
| 103 | + model_instance = assert_validation_model( |
| 104 | + model_cls, example_name=example_name, example_data=example_data |
| 105 | + ) |
| 106 | + |
| 107 | + assert isinstance(model_instance, SimcoreServiceLabels) |
| 108 | + assert model_instance.callbacks_mapping is not None |
| 109 | + assert model_instance.needs_dynamic_sidecar == ( |
| 110 | + "simcore.service.paths-mapping" in example_data |
| 111 | + ) |
103 | 112 |
|
104 | 113 |
|
105 | 114 | def test_raises_error_if_http_entrypoint_is_missing(): |
|
0 commit comments