feat: add support for definition in query param
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from typing import Optional, List
|
||||
from pydantic import Field
|
||||
from aiohttp import web
|
||||
@@ -54,6 +55,20 @@ class ArticleViewWithPaginationGroup(PydanticView):
|
||||
)
|
||||
|
||||
|
||||
class Lang(str, Enum):
|
||||
EN = 'en'
|
||||
FR = 'fr'
|
||||
|
||||
|
||||
class ArticleViewWithEnumInQuery(PydanticView):
|
||||
async def get(self, lang: Lang):
|
||||
return web.json_response(
|
||||
{
|
||||
"lang": lang
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def test_get_article_without_required_qs_should_return_an_error_message(
|
||||
aiohttp_client, event_loop
|
||||
):
|
||||
@@ -236,6 +251,20 @@ async def test_get_article_with_page_and_page_size(aiohttp_client, event_loop):
|
||||
assert resp.content_type == "application/json"
|
||||
|
||||
|
||||
async def test_get_article_with_enum_in_query(aiohttp_client, event_loop):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleViewWithEnumInQuery)
|
||||
|
||||
client = await aiohttp_client(app)
|
||||
|
||||
resp = await client.get(
|
||||
"/article", params={"lang": Lang.EN.value}
|
||||
)
|
||||
assert await resp.json() == {'lang': Lang.EN}
|
||||
assert resp.status == 200
|
||||
assert resp.content_type == "application/json"
|
||||
|
||||
|
||||
async def test_get_article_with_page_and_wrong_page_size(aiohttp_client, event_loop):
|
||||
app = web.Application()
|
||||
app.router.add_view("/article", ArticleViewWithPaginationGroup)
|
||||
|
||||
Reference in New Issue
Block a user