Browse Source

tests: add empty - string ('?q=') case --> 422 for regex validated query param

pull/14104/head
Enam Singh 10 months ago
parent
commit
9057eed3ec
  1. 33
      tests/test_regex_deprecated_params.py

33
tests/test_regex_deprecated_params.py

@ -70,7 +70,38 @@ def test_query_params_str_validations_item_query_nonregexquery():
] ]
} }
) )
@needs_py310
def test_query_params_str_validations_item_query_empty():
client = get_client()
response = client.get("/items/", params = {"q": ""})
assert response.status_code == 422
assert response.json() == IsDict(
{
"detail": [
{
"type": "string_pattern_mismatch",
"loc": ["query", "q"],
"msg": "String should match pattern '^fixedquery$'",
"input": "",
"ctx": {"pattern": "^fixedquery$"},
}
]
}
) | IsDict(
# TODO: remove when deprecating Pydantic v1
{
"detail": [
{
"ctx": {"pattern": "^fixedquery$"},
"loc": ["query", "q"],
"msg": 'string does not match regex "^fixedquery$"',
"type": "value_error.str.regex",
}
]
}
)
@needs_py310 @needs_py310
def test_openapi_schema(): def test_openapi_schema():

Loading…
Cancel
Save