Skip to content

Commit

Permalink
Add model_no_ref_schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brynpickering committed Dec 18, 2024
1 parent 0308a8b commit bf6cc0a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,42 @@ def test_logging(self, caplog, config_model_double_nested, to_update, expected):
model.update(to_update)

assert all(log_text in caplog.text for log_text in expected)


class TestNoRefSchema:
@pytest.fixture(scope="module")
def config_model(self):
sub_model = pydantic.create_model(
"SubModel",
__base__=config.ConfigBaseModel,
model_config={"title": "TITLE"},
foo=(str, "bar"),
foobar=(int, 1),
)
model = pydantic.create_model(
"Model",
__base__=config.ConfigBaseModel,
model_config={"title": "TITLE 2"},
nested=(sub_model, sub_model()),
)
return model

def test_config_model_no_defs(self, config_model):
model = config_model()
json_schema = model.model_json_schema()
no_defs_json_schema = model.model_no_ref_schema()
assert "$defs" in json_schema
assert "$defs" not in no_defs_json_schema

def test_config_model_no_resolved_refs(self, config_model):
model = config_model()
json_schema = model.model_json_schema()
no_defs_json_schema = model.model_no_ref_schema()
assert json_schema["properties"]["nested"] == {
"$ref": "#/$defs/SubModel",
"default": {"foo": "bar", "foobar": 1},
}
assert (
no_defs_json_schema["properties"]["nested"]
== json_schema["$defs"]["SubModel"]
)

0 comments on commit bf6cc0a

Please sign in to comment.