Merge branch 'develop' of https://git.pi3c.ru/pi3c/fastfood into develop

Объединение изменений с разных устройств
develop
Сергей Ванюшкин 2024-01-30 13:09:54 +03:00
commit f61cb3a2ee
1 changed files with 49 additions and 33 deletions

View File

@ -1,110 +1,126 @@
from typing import Tuple
import pytest import pytest
from httpx import AsyncClient, Response
class TestBaseCrud: class TestBaseCrud:
class Menu: class Menu:
@staticmethod @staticmethod
async def read_all(ac): async def read_all(ac: AsyncClient) -> Tuple[int, dict]:
"""чтение всех меню""" """чтение всех меню"""
response = await ac.get("/") response: Response = await ac.get("/")
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def get(ac, data): async def get(ac: AsyncClient, data: dict) -> Tuple[int, dict]:
"""Получение меню по id""" """Получение меню по id"""
response = await ac.get(f"/{data.get('id')}") response: Response = await ac.get(f"/{data.get('id')}")
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def write(ac, data): async def write(ac: AsyncClient, data: dict) -> Tuple[int, dict]:
"""создания меню""" """создания меню"""
response = await ac.post("/", json=data) response: Response = await ac.post("/", json=data)
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def update(ac, data): async def update(ac: AsyncClient, data: dict) -> Tuple[int, dict]:
"""Обновление меню по id""" """Обновление меню по id"""
response = await ac.patch(f"/{data.get('id')}", json=data) response: Response = await ac.patch(
f"/{data.get('id')}",
json=data,
)
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def delete(ac, data): async def delete(ac: AsyncClient, data: dict) -> int:
"""Удаление меню по id""" """Удаление меню по id"""
response = await ac.delete(f"/{data.get('id')}") response: Response = await ac.delete(f"/{data.get('id')}")
return response.status_code return response.status_code
class Submenu: class Submenu:
@staticmethod @staticmethod
async def read_all(ac, menu): async def read_all(ac: AsyncClient, menu: dict) -> Tuple[int, dict]:
"""чтение всех меню""" """чтение всех меню"""
response = await ac.get(f"/{menu.get('id')}/submenus/") response: Response = await ac.get(f"/{menu.get('id')}/submenus/")
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def get(ac, menu, submenu): async def get(ac: AsyncClient, menu: dict, submenu: dict) -> Tuple[int, dict]:
"""Получение меню по id""" """Получение меню по id"""
response = await ac.get( response: Response = await ac.get(
f"/{menu.get('id')}/submenus/{submenu.get('id')}", f"/{menu.get('id')}/submenus/{submenu.get('id')}",
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def write(ac, menu, submenu): async def write(ac: AsyncClient, menu: dict, submenu: dict) -> Tuple[int, dict]:
"""создания меню""" """создания меню"""
response = await ac.post( response: Response = await ac.post(
f"/{menu.get('id')}/submenus/", f"/{menu.get('id')}/submenus/",
json=submenu, json=submenu,
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def update(ac, menu, submenu): async def update(
ac: AsyncClient, menu: dict, submenu: dict
) -> Tuple[int, dict]:
"""Обновление меню по id""" """Обновление меню по id"""
response = await ac.patch( response: Response = await ac.patch(
f"/{menu.get('id')}/submenus/{submenu.get('id')}", f"/{menu.get('id')}/submenus/{submenu.get('id')}",
json=submenu, json=submenu,
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def delete(ac, menu, submenu): async def delete(ac: AsyncClient, menu: dict, submenu: dict) -> int:
"""Удаление меню по id""" """Удаление меню по id"""
response = await ac.delete( response: Response = await ac.delete(
f"/{menu.get('id')}/submenus/{submenu.get('id')}" f"/{menu.get('id')}/submenus/{submenu.get('id')}"
) )
return response.status_code return response.status_code
class Dish: class Dish:
@staticmethod @staticmethod
async def read_all(ac, menu, submenu): async def read_all(
ac: AsyncClient, menu: dict, submenu: dict
) -> Tuple[int, dict]:
"""чтение всех блюд""" """чтение всех блюд"""
response = await ac.get( response: Response = await ac.get(
f"/{menu.get('id')}/submenus/{submenu.get('id')}/dishes/", f"/{menu.get('id')}/submenus/{submenu.get('id')}/dishes/",
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def get(ac, menu, submenu, dish): async def get(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> Tuple[int, dict]:
"""Получение блюда по id""" """Получение блюда по id"""
response = await ac.get( response: Response = await ac.get(
f"/{menu.get('id')}/submenus/{submenu.get('id')}" f"/{menu.get('id')}/submenus/{submenu.get('id')}"
f"/dishes/{dish.get('id')}", f"/dishes/{dish.get('id')}",
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def write(ac, menu, submenu, dish): async def write(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> Tuple[int, dict]:
"""создания блюда""" """создания блюда"""
response = await ac.post( response: Response = await ac.post(
f"/{menu.get('id')}/submenus/{submenu.get('id')}/dishes/", f"/{menu.get('id')}/submenus/{submenu.get('id')}/dishes/",
json=dish, json=dish,
) )
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def update(ac, menu, submenu, dish): async def update(
ac: AsyncClient, menu: dict, submenu: dict, dish: dict
) -> Tuple[int, dict]:
"""Обновление блюда по id""" """Обновление блюда по id"""
response = await ac.patch( response: Response = await ac.patch(
f"/{menu.get('id')}/submenus/{submenu.get('id')}" f"/{menu.get('id')}/submenus/{submenu.get('id')}"
f"/dishes/{dish.get('id')}", f"/dishes/{dish.get('id')}",
json=dish, json=dish,
@ -112,16 +128,16 @@ class TestBaseCrud:
return response.status_code, response.json() return response.status_code, response.json()
@staticmethod @staticmethod
async def delete(ac, menu, submenu, dish): async def delete(ac: AsyncClient, menu: dict, submenu: dict, dish: dict) -> int:
"""Удаление блюда по id""" """Удаление блюда по id"""
response = await ac.delete( response: Response = await ac.delete(
f"/{menu.get('id')}/submenus/{submenu.get('id')}" f"/{menu.get('id')}/submenus/{submenu.get('id')}"
f"/dishes/{dish.get('id')}" f"/dishes/{dish.get('id')}"
) )
return response.status_code return response.status_code
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_menu_crud(self, client): async def test_menu_crud(self, client: AsyncClient) -> None:
"""Тестирование функций меню""" """Тестирование функций меню"""
code, rspn = await self.Menu.read_all(client) code, rspn = await self.Menu.read_all(client)
assert code == 200 assert code == 200
@ -152,7 +168,7 @@ class TestBaseCrud:
assert code == 404 assert code == 404
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_submenus(self, client): async def test_submenus(self, client) -> None:
# Создаем меню и проверяем ответ # Создаем меню и проверяем ответ
menu = {"title": "Menu", "description": "main menu"} menu = {"title": "Menu", "description": "main menu"}
code, rspn = await self.Menu.write(client, menu) code, rspn = await self.Menu.write(client, menu)
@ -203,7 +219,7 @@ class TestBaseCrud:
await self.Menu.delete(client, menu) await self.Menu.delete(client, menu)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_dishes(self, client): async def test_dishes(self, client: AsyncClient) -> None:
# Создаем меню и проверяем ответ # Создаем меню и проверяем ответ
menu = { menu = {
"title": "Menu", "title": "Menu",