MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / _valid

Function _valid

sdks/python/tests/test_v1_client.py:81–98  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

79
80
81def _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)

Calls 2

_dummyFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected