Browse Source

Update tests to reflect correct behavior for form/header default values

The previous test expectations were based on buggy behavior where default
values were incorrectly included in validation error input messages. After
fixing issue #13399 to preserve model_fields_set correctly, validation
errors now correctly show only the actual input received, not pre-filled
defaults.

Changes:
- test_forms_single_model.py: Updated test_no_data to expect empty input dict
- test_tutorial001.py: Removed x_tag default from validation error input
- test_tutorial002.py: Removed x_tag default from validation error input
- test_tutorial003.py: Removed x_tag default from both invalid tests

These changes ensure tests validate the correct behavior where defaults
are not pre-filled in the input dict passed to Pydantic, which allows
model_fields_set to accurately track which fields were explicitly provided.
pull/14870/head
Varun Chawla 5 months ago
parent
commit
877fdca4d4
  1. 4
      tests/test_forms_single_model.py
  2. 1
      tests/test_tutorial/test_header_param_models/test_tutorial001.py
  3. 2
      tests/test_tutorial/test_header_param_models/test_tutorial002.py
  4. 2
      tests/test_tutorial/test_header_param_models/test_tutorial003.py

4
tests/test_forms_single_model.py

@ -99,13 +99,13 @@ def test_no_data():
"type": "missing",
"loc": ["body", "username"],
"msg": "Field required",
"input": {"tags": ["foo", "bar"], "with": "nothing"},
"input": {},
},
{
"type": "missing",
"loc": ["body", "lastname"],
"msg": "Field required",
"input": {"tags": ["foo", "bar"], "with": "nothing"},
"input": {},
},
]
}

1
tests/test_tutorial/test_header_param_models/test_tutorial001.py

@ -67,7 +67,6 @@ def test_header_param_model_invalid(client: TestClient):
"loc": ["header", "save_data"],
"msg": "Field required",
"input": {
"x_tag": [],
"host": "testserver",
"accept": "*/*",
"accept-encoding": "gzip, deflate",

2
tests/test_tutorial/test_header_param_models/test_tutorial002.py

@ -67,7 +67,7 @@ def test_header_param_model_invalid(client: TestClient):
"type": "missing",
"loc": ["header", "save_data"],
"msg": "Field required",
"input": {"x_tag": [], "host": "testserver"},
"input": {"host": "testserver"},
}
]
}

2
tests/test_tutorial/test_header_param_models/test_tutorial003.py

@ -66,7 +66,6 @@ def test_header_param_model_no_underscore(client: TestClient):
"input": {
"host": "testserver",
"traceparent": "123",
"x_tag": [],
"accept": "*/*",
"accept-encoding": "gzip, deflate",
"connection": "keep-alive",
@ -104,7 +103,6 @@ def test_header_param_model_invalid(client: TestClient):
"loc": ["header", "save_data"],
"msg": "Field required",
"input": {
"x_tag": [],
"host": "testserver",
"accept": "*/*",
"accept-encoding": "gzip, deflate",

Loading…
Cancel
Save