Construct a REAL model (valid by construction) and dump it to wire JSON — the Go server always returns full objects, so fixtures should too. Recurses into nested model fields (e.g. DomainView.dns_records) so deep views work.
(model_cls, **overrides)
| 79 | |
| 80 | |
| 81 | def _valid(model_cls, **overrides): |
| 82 | """Construct a REAL model (valid by construction) and dump it to wire JSON — |
| 83 | the Go server always returns full objects, so fixtures should too. Recurses |
| 84 | into nested model fields (e.g. DomainView.dns_records) so deep views work.""" |
| 85 | from pydantic import BaseModel as _BaseModel |
| 86 | |
| 87 | kwargs = {} |
| 88 | for name, field in model_cls.model_fields.items(): |
| 89 | if name in overrides: |
| 90 | kwargs[name] = overrides[name] |
| 91 | elif field.is_required(): |
| 92 | ann = field.annotation |
| 93 | if isinstance(ann, type) and issubclass(ann, _BaseModel): |
| 94 | kwargs[name] = _valid(ann) |
| 95 | else: |
| 96 | kwargs[name] = _REQUIRED_DEFAULTS.get(name, _dummy(field.annotation)) |
| 97 | inst = model_cls(**kwargs) |
| 98 | return inst.model_dump(by_alias=True, mode="json") |
| 99 | |
| 100 | |
| 101 | @pytest.fixture(autouse=True) |
no test coverage detected