feat: update pydantic
This commit is contained in:
@@ -50,9 +50,9 @@ class Signature(Group):
|
||||
|
||||
class ArticleViewWithSignatureGroup(PydanticView):
|
||||
async def get(
|
||||
self,
|
||||
*,
|
||||
signature: Signature,
|
||||
self,
|
||||
*,
|
||||
signature: Signature,
|
||||
):
|
||||
return web.json_response(
|
||||
{"expired": signature.expired, "scope": signature.scope},
|
||||
@@ -61,7 +61,7 @@ class ArticleViewWithSignatureGroup(PydanticView):
|
||||
|
||||
|
||||
async def test_get_article_without_required_header_should_return_an_error_message(
|
||||
aiohttp_client, event_loop
|
||||
aiohttp_client, event_loop
|
||||
):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleView)
|
||||
@@ -70,18 +70,24 @@ async def test_get_article_without_required_header_should_return_an_error_messag
|
||||
resp = await client.get("/article", headers={})
|
||||
assert resp.status == 400
|
||||
assert resp.content_type == "application/json"
|
||||
assert await resp.json() == [
|
||||
|
||||
result = await resp.json()
|
||||
assert len(result) == 1
|
||||
result[0].pop('input')
|
||||
|
||||
assert result == [
|
||||
{
|
||||
"in": "headers",
|
||||
"loc": ["signature_expired"],
|
||||
"msg": "field required",
|
||||
"type": "value_error.missing",
|
||||
'type': 'missing',
|
||||
'loc': ['signature_expired'],
|
||||
'msg': 'Field required',
|
||||
'url': 'https://errors.pydantic.dev/2.1.2/v/missing',
|
||||
'loc_in': 'headers'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
async def test_get_article_with_wrong_header_type_should_return_an_error_message(
|
||||
aiohttp_client, event_loop
|
||||
aiohttp_client, event_loop
|
||||
):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleView)
|
||||
@@ -90,18 +96,22 @@ async def test_get_article_with_wrong_header_type_should_return_an_error_message
|
||||
resp = await client.get("/article", headers={"signature_expired": "foo"})
|
||||
assert resp.status == 400
|
||||
assert resp.content_type == "application/json"
|
||||
|
||||
assert await resp.json() == [
|
||||
{
|
||||
"in": "headers",
|
||||
"loc": ["signature_expired"],
|
||||
"msg": "invalid datetime format",
|
||||
"type": "value_error.datetime",
|
||||
'type': 'datetime_parsing',
|
||||
'loc': ['signature_expired'],
|
||||
'msg': 'Input should be a valid datetime, input is too short',
|
||||
'input': 'foo',
|
||||
'ctx': {'error': 'input is too short'},
|
||||
'url': 'https://errors.pydantic.dev/2.1.2/v/datetime_parsing',
|
||||
'loc_in': 'headers'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
async def test_get_article_with_valid_header_should_return_the_parsed_type(
|
||||
aiohttp_client, event_loop
|
||||
aiohttp_client, event_loop
|
||||
):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleView)
|
||||
@@ -116,7 +126,7 @@ async def test_get_article_with_valid_header_should_return_the_parsed_type(
|
||||
|
||||
|
||||
async def test_get_article_with_valid_header_containing_hyphen_should_be_returned(
|
||||
aiohttp_client, event_loop
|
||||
aiohttp_client, event_loop
|
||||
):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleView)
|
||||
@@ -136,18 +146,20 @@ async def test_wrong_value_to_header_defined_with_str_enum(aiohttp_client, event
|
||||
|
||||
client = await aiohttp_client(app)
|
||||
resp = await client.get("/coord", headers={"format": "WGS84"})
|
||||
|
||||
assert (
|
||||
await resp.json()
|
||||
== [
|
||||
{
|
||||
"ctx": {"enum_values": ["UMT", "MGRS"]},
|
||||
"in": "headers",
|
||||
"loc": ["format"],
|
||||
"msg": "value is not a valid enumeration member; permitted: 'UMT', 'MGRS'",
|
||||
"type": "type_error.enum",
|
||||
}
|
||||
]
|
||||
!= {"signature": "2020-10-04T18:01:00"}
|
||||
await resp.json()
|
||||
== [
|
||||
{
|
||||
'ctx': {'expected': "'UMT' or 'MGRS'"},
|
||||
'input': 'WGS84',
|
||||
'loc': ['format'],
|
||||
'loc_in': 'headers',
|
||||
'msg': "Input should be 'UMT' or 'MGRS'",
|
||||
'type': 'enum'
|
||||
}
|
||||
]
|
||||
!= {"signature": "2020-10-04T18:01:00"}
|
||||
)
|
||||
assert resp.status == 400
|
||||
assert resp.content_type == "application/json"
|
||||
|
||||
Reference in New Issue
Block a user