fastfood/tests/test_summary.py

114 lines
3.2 KiB
Python
Raw Normal View History

import pytest
from httpx import AsyncClient
from .repository import Repository as Repo
@pytest.mark.asyncio
async def test_summary_with_menu(client: AsyncClient) -> None:
# Проверяем пустое summary
code, rspn = await Repo.Summary.read_summary(client)
assert code == 200
assert rspn == []
# Создаем меню и проверяем ответ
2024-02-12 02:42:46 +03:00
menu = {'title': 'Menu', 'description': 'main menu', 'submenus': []}
code, rspn = await Repo.Menu.write(client, menu)
menu.update(rspn)
# Удалим ненужные ключи, тк в модели они не используются
del menu['submenus_count']
del menu['dishes_count']
# Проверяем summary c меню
code, rspn = await Repo.Summary.read_summary(client)
assert code == 200
assert rspn == [menu]
# удаляем сопутствующее
await Repo.Menu.delete(client, menu)
@pytest.mark.asyncio
async def test_summary_with_submenus(client: AsyncClient) -> None:
# Создаем меню и проверяем ответ
2024-02-12 02:42:46 +03:00
menu: dict[str, str | list | float] = {
'title': 'Menu',
'description': 'main menu',
2024-02-12 02:42:46 +03:00
'submenus': [],
}
code, rspn = await Repo.Menu.write(client, menu)
menu.update(rspn)
del menu['submenus_count']
del menu['dishes_count']
# Создаем и проверяем подменю
2024-02-12 02:42:46 +03:00
submenu: dict[str, str | list | float] = {
'title': 'Submenu',
'description': 'submenu',
'parent_menu': menu['id'],
2024-02-12 02:42:46 +03:00
'dishes': list(),
}
code, rspn = await Repo.Submenu.write(client, menu, submenu)
submenu.update(rspn)
del submenu['dishes_count']
del submenu['parent_menu']
2024-02-12 02:42:46 +03:00
menu['submenus'] = [submenu]
# Получаем блюдо
code, rspn = await Repo.Summary.read_summary(client)
assert code == 200
assert rspn == [menu]
await Repo.Menu.delete(client, menu)
@pytest.mark.asyncio
async def test_summary_with_dishes(client: AsyncClient) -> None:
# Создаем меню и проверяем ответ
2024-02-12 02:42:46 +03:00
menu: dict[str, str | list | float] = {
'title': 'Menu',
'description': 'main menu',
2024-02-12 02:42:46 +03:00
'submenus': [],
}
code, rspn = await Repo.Menu.write(client, menu)
menu.update(rspn)
del menu['submenus_count']
del menu['dishes_count']
# Создаем и проверяем подменю
2024-02-12 02:42:46 +03:00
submenu: dict[str, str | list | float] = {
'title': 'Submenu',
'description': 'submenu',
'parent_menu': menu['id'],
2024-02-12 02:42:46 +03:00
'dishes': [],
}
code, rspn = await Repo.Submenu.write(client, menu, submenu)
submenu.update(rspn)
del submenu['dishes_count']
del submenu['parent_menu']
# Добавляем блюдо
dish = {
'title': 'dish',
'description': 'some dish',
'price': '12.5',
'parent_submenu': submenu['id'],
}
code, rspn = await Repo.Dish.write(client, menu, submenu, dish)
dish.update(rspn)
del dish['parent_submenu']
del dish['id']
2024-02-12 02:42:46 +03:00
submenu['dishes'] = [dish]
menu['submenus'] = [submenu]
code, rspn = await Repo.Summary.read_summary(client)
assert code == 200
assert rspn == [menu]
await Repo.Menu.delete(client, menu)