diff --git a/examples/example_app/pages/handler_return_dict.py b/examples/example_app/pages/handler_return_dict.py new file mode 100644 index 000000000..6fbb50fc2 --- /dev/null +++ b/examples/example_app/pages/handler_return_dict.py @@ -0,0 +1,6 @@ +import frontik.handler + + +class Page(frontik.handler.PageHandler): + def get_page(self) -> dict: + return {'str_field': 'Привет'} diff --git a/examples/example_app/pages/handler_return_pydantic.py b/examples/example_app/pages/handler_return_pydantic.py new file mode 100644 index 000000000..f219ccaf7 --- /dev/null +++ b/examples/example_app/pages/handler_return_pydantic.py @@ -0,0 +1,12 @@ +from pydantic import BaseModel + +import frontik.handler + + +class ResponseModel(BaseModel): + str_field: str + + +class Page(frontik.handler.PageHandler): + def get_page(self) -> ResponseModel: + return ResponseModel(str_field='Привет') diff --git a/examples/frontik.cfg b/examples/frontik.cfg index 6d125a05d..98d7126be 100644 --- a/examples/frontik.cfg +++ b/examples/frontik.cfg @@ -11,3 +11,5 @@ stderr_log = True jinja_template_root = 'templates' consul_enabled=False + +debug=True diff --git a/tests/test_handler_returned_value_processing.py b/tests/test_handler_returned_value_processing.py index 92d29d2d2..96dc9a3e3 100644 --- a/tests/test_handler_returned_value_processing.py +++ b/tests/test_handler_returned_value_processing.py @@ -12,16 +12,17 @@ class _PydanticModel(BaseModel): int_field: int bool_field: bool + str_field: str class ReturnPydanticModelHandler(PageHandler): async def get_page(self) -> _PydanticModel: - return _PydanticModel(int_field=1, bool_field=True) + return _PydanticModel(int_field=1, bool_field=True, str_field='Ну привет') class ReturnDictHandler(PageHandler): async def get_page(self) -> dict: - return {'is_dict': True} + return {'is_dict': True, 'msg': 'Ну привет'} class TestApplication(FrontikApplication): @@ -40,8 +41,10 @@ def frontik_app(self) -> TestApplication: async def test_get_dict(self): resp = await self.fetch_json('/return_dict') assert resp['is_dict'] is True + assert resp['msg'] == 'Ну привет' async def test_get_pydantic_model(self): resp = await self.fetch_json('/return_pydantic') assert resp['int_field'] == 1 assert resp['bool_field'] is True + assert resp['str_field'] == 'Ну привет'