fastfood/tests/repository.py

197 lines
6.6 KiB
Python
Raw Permalink Normal View History

from httpx import AsyncClient, Response
from .urls import reverse
2024-02-04 21:40:58 +03:00
class Repository:
class Menu:
@staticmethod
async def read_all(ac: AsyncClient) -> tuple[int, dict]:
"""чтение всех меню"""
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"""
2024-02-04 21:40:58 +03:00
response: Response = await ac.get(
reverse('get_menu', menu_id=data.get('id'))
2024-02-04 21:40:58 +03:00
)
return response.status_code, response.json()
@staticmethod
async def write(ac: AsyncClient, data: dict) -> tuple[int, dict]:
"""создания меню"""
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('update_menu', menu_id=data.get('id')),
json=data,
)
return response.status_code, response.json()
@staticmethod
async def delete(ac: AsyncClient, data: dict) -> int:
"""Удаление меню по id"""
2024-02-04 21:40:58 +03:00
response: Response = await ac.delete(
reverse('delete_menu', menu_id=data.get('id')),
2024-02-04 21:40:58 +03:00
)
return response.status_code
class Submenu:
@staticmethod
async def read_all(ac: AsyncClient, menu: dict) -> tuple[int, dict]:
"""чтение всех меню"""
2024-02-04 21:40:58 +03:00
response: Response = await ac.get(
reverse('get_submenus', menu_id=menu.get('id')),
2024-02-04 21:40:58 +03:00
)
return response.status_code, response.json()
@staticmethod
async def get(
ac: AsyncClient,
menu: dict,
submenu: dict,
) -> tuple[int, dict]:
"""Получение меню по id"""
response: Response = await ac.get(
reverse(
'get_submenu',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
),
)
return response.status_code, response.json()
@staticmethod
async def write(
ac: AsyncClient,
menu: dict,
submenu: dict,
) -> tuple[int, dict]:
"""создания меню"""
response: Response = await ac.post(
reverse('create_submenu_item', menu_id=menu.get('id')),
json=submenu,
)
return response.status_code, response.json()
@staticmethod
async def update(
ac: AsyncClient, menu: dict, submenu: dict
) -> tuple[int, dict]:
"""Обновление меню по id"""
response: Response = await ac.patch(
reverse(
'update_submenu',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
),
json=submenu,
)
return response.status_code, response.json()
@staticmethod
async def delete(ac: AsyncClient, menu: dict, submenu: dict) -> int:
"""Удаление меню по id"""
response: Response = await ac.delete(
reverse(
'delete_submenu',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
),
)
return response.status_code
class Dish:
@staticmethod
async def read_all(
ac: AsyncClient, menu: dict, submenu: dict
) -> tuple[int, dict]:
"""чтение всех блюд"""
response: Response = await ac.get(
reverse(
'get_dishes',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
),
)
return response.status_code, response.json()
@staticmethod
async def get(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> tuple[int, dict]:
"""Получение блюда по id"""
response: Response = await ac.get(
reverse(
'get_dish',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
dish_id=dish.get('id'),
),
)
return response.status_code, response.json()
@staticmethod
async def write(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> tuple[int, dict]:
"""создания блюда"""
response: Response = await ac.post(
reverse(
'create_dish',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
),
json=dish,
)
return response.status_code, response.json()
@staticmethod
async def update(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> tuple[int, dict]:
"""Обновление блюда по id"""
response: Response = await ac.patch(
reverse(
'update_dish',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
dish_id=dish.get('id'),
),
json=dish,
)
return response.status_code, response.json()
@staticmethod
async def delete(
ac: AsyncClient,
menu: dict,
submenu: dict,
dish: dict,
) -> int:
"""Удаление блюда по id"""
response: Response = await ac.delete(
reverse(
'delete_dish',
2024-02-04 21:40:58 +03:00
menu_id=menu.get('id'),
submenu_id=submenu.get('id'),
dish_id=dish.get('id'),
),
)
return response.status_code
class Summary:
@staticmethod
async def read_summary(ac: AsyncClient) -> tuple[int, dict]:
"""чтение summary"""
response: Response = await ac.get(reverse('get_summary'))
return response.status_code, response.json()