From f72c6fe4d7af794b95b1899a21e6b6af904ffc9b Mon Sep 17 00:00:00 2001 From: pi3c Date: Tue, 6 Feb 2024 15:12:32 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20reverse()=20=D0=BF=D0=BE=D0=BB=D1=83?= =?UTF-8?q?=D1=87=D0=B0=D0=B5=D1=82=20=D1=83=D1=80=D0=BB=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B5=D0=BD=D0=B4=D0=BF=D0=BE?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastfood/repository/redis.py | 2 +- tests/conftest.py | 2 +- tests/repository.py | 48 ++++++++++++++++++------------------ tests/urls.py | 26 ++++--------------- 4 files changed, 31 insertions(+), 47 deletions(-) diff --git a/fastfood/repository/redis.py b/fastfood/repository/redis.py index a560efd..f3732cd 100644 --- a/fastfood/repository/redis.py +++ b/fastfood/repository/redis.py @@ -31,7 +31,7 @@ class RedisRepository: pool: redis.Redis = Depends(get_redis_pool), ) -> None: self.pool = pool - self.ttl = 1800 + self.ttl = 2 async def get(self, key: str) -> Any | None: data = await self.pool.get(key) diff --git a/tests/conftest.py b/tests/conftest.py index e64f40a..c36a411 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -52,6 +52,6 @@ async def client(event_loop) -> AsyncGenerator[AsyncClient, None]: async with AsyncClient( app=app, - base_url='http://localhost:8000/api/v1/menus', + base_url='http://localhost:8000', ) as async_client: yield async_client diff --git a/tests/repository.py b/tests/repository.py index f4aca24..e563f2a 100644 --- a/tests/repository.py +++ b/tests/repository.py @@ -1,6 +1,6 @@ from httpx import AsyncClient, Response -from .urls import reverse_url +from .urls import reverse class Repository: @@ -9,28 +9,28 @@ class Repository: async def read_all(ac: AsyncClient) -> tuple[int, dict]: """чтение всех меню""" - response: Response = await ac.get(reverse_url('menus')) + response: Response = await ac.get(reverse('get_menus')) return response.status_code, response.json() @staticmethod async def get(ac: AsyncClient, data: dict) -> tuple[int, dict]: """Получение меню по id""" response: Response = await ac.get( - reverse_url('menu', menu_id=data.get('id')) + reverse('get_menu', menu_id=data.get('id')) ) return response.status_code, response.json() @staticmethod async def write(ac: AsyncClient, data: dict) -> tuple[int, dict]: """создания меню""" - response: Response = await ac.post(reverse_url('menus'), json=data) + response: Response = await ac.post(reverse('add_menu'), json=data) return response.status_code, response.json() @staticmethod async def update(ac: AsyncClient, data: dict) -> tuple[int, dict]: """Обновление меню по id""" response: Response = await ac.patch( - reverse_url('menu', menu_id=data.get('id')), + reverse('update_menu', menu_id=data.get('id')), json=data, ) return response.status_code, response.json() @@ -39,7 +39,7 @@ class Repository: async def delete(ac: AsyncClient, data: dict) -> int: """Удаление меню по id""" response: Response = await ac.delete( - reverse_url('menu', menu_id=data.get('id')), + reverse('delete_menu', menu_id=data.get('id')), ) return response.status_code @@ -48,7 +48,7 @@ class Repository: async def read_all(ac: AsyncClient, menu: dict) -> tuple[int, dict]: """чтение всех меню""" response: Response = await ac.get( - reverse_url('submenus', menu_id=menu.get('id')), + reverse('get_submenus', menu_id=menu.get('id')), ) return response.status_code, response.json() @@ -60,8 +60,8 @@ class Repository: ) -> tuple[int, dict]: """Получение меню по id""" response: Response = await ac.get( - reverse_url( - 'submenu', + reverse( + 'get_submenu', menu_id=menu.get('id'), submenu_id=submenu.get('id'), ), @@ -76,7 +76,7 @@ class Repository: ) -> tuple[int, dict]: """создания меню""" response: Response = await ac.post( - reverse_url('submenu', menu_id=menu.get('id')), + reverse('create_submenu_item', menu_id=menu.get('id')), json=submenu, ) return response.status_code, response.json() @@ -87,8 +87,8 @@ class Repository: ) -> tuple[int, dict]: """Обновление меню по id""" response: Response = await ac.patch( - reverse_url( - 'submenu', + reverse( + 'update_submenu', menu_id=menu.get('id'), submenu_id=submenu.get('id'), ), @@ -100,8 +100,8 @@ class Repository: async def delete(ac: AsyncClient, menu: dict, submenu: dict) -> int: """Удаление меню по id""" response: Response = await ac.delete( - reverse_url( - 'submenu', + reverse( + 'delete_submenu', menu_id=menu.get('id'), submenu_id=submenu.get('id'), ), @@ -115,8 +115,8 @@ class Repository: ) -> tuple[int, dict]: """чтение всех блюд""" response: Response = await ac.get( - reverse_url( - 'dishes', + reverse( + 'get_dishes', menu_id=menu.get('id'), submenu_id=submenu.get('id'), ), @@ -129,8 +129,8 @@ class Repository: ) -> tuple[int, dict]: """Получение блюда по id""" response: Response = await ac.get( - reverse_url( - 'dish', + reverse( + 'get_dish', menu_id=menu.get('id'), submenu_id=submenu.get('id'), dish_id=dish.get('id'), @@ -144,8 +144,8 @@ class Repository: ) -> tuple[int, dict]: """создания блюда""" response: Response = await ac.post( - reverse_url( - 'dishes', + reverse( + 'create_dish', menu_id=menu.get('id'), submenu_id=submenu.get('id'), ), @@ -159,8 +159,8 @@ class Repository: ) -> tuple[int, dict]: """Обновление блюда по id""" response: Response = await ac.patch( - reverse_url( - 'dish', + reverse( + 'update_dish', menu_id=menu.get('id'), submenu_id=submenu.get('id'), dish_id=dish.get('id'), @@ -178,8 +178,8 @@ class Repository: ) -> int: """Удаление блюда по id""" response: Response = await ac.delete( - reverse_url( - 'dish', + reverse( + 'delete_dish', menu_id=menu.get('id'), submenu_id=submenu.get('id'), dish_id=dish.get('id'), diff --git a/tests/urls.py b/tests/urls.py index 169912f..0d6caed 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,25 +1,9 @@ -def reverse_url(loc: str, **kwargs) -> str: - menu_pref = '/' - submenu_pref = menu_pref + str(kwargs.get('menu_id', '')) + '/submenus/' - dish_pref = submenu_pref + str(kwargs.get('submenu_id', '')) + '/dishes/' +from fastfood.app import create_app - match loc: - case 'menus': - return menu_pref +app = create_app() - case 'menu': - return menu_pref + str(kwargs.get('menu_id', '')) - case 'submenus': - return submenu_pref +def reverse(loc: str, **kwargs) -> str: - case 'submenu': - return submenu_pref + str(kwargs.get('submenu_id', '')) - - case 'dishes': - return dish_pref - - case 'dish': - return dish_pref + str(kwargs.get('dish_id', '')) - - return menu_pref + url = app.url_path_for(loc, **kwargs) + return url