2024-01-29 02:19:02 +03:00
|
|
|
from uuid import UUID
|
|
|
|
|
2024-01-29 12:34:11 +03:00
|
|
|
import pytest
|
2024-01-29 02:19:02 +03:00
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
2024-01-29 12:34:11 +03:00
|
|
|
|
2024-01-29 02:19:02 +03:00
|
|
|
from fastfood.cruds.menu import MenuCrud
|
2024-01-29 12:34:11 +03:00
|
|
|
from fastfood.cruds.submenu import SubMenuCrud
|
|
|
|
from fastfood.models import Dish, Menu, SubMenu
|
2024-01-29 02:19:02 +03:00
|
|
|
from fastfood.schemas import Menu as menuschema
|
|
|
|
from fastfood.schemas import MenuBase as menubaseschema
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_menu(asession: AsyncSession) -> None:
|
|
|
|
async with asession:
|
|
|
|
menu: Menu = Menu(title="SomeMenu", description="SomeDescription")
|
|
|
|
|
2024-01-29 20:11:39 +03:00
|
|
|
menu: Menu = await MenuCrud.create_menu_item(
|
|
|
|
menubaseschema.model_validate(menu),
|
|
|
|
asession,
|
|
|
|
)
|
|
|
|
|
2024-01-29 02:19:02 +03:00
|
|
|
menu_id: UUID = menu.id
|
|
|
|
|
|
|
|
req_menu: Menu | None = await MenuCrud.get_menu_item(menu_id, asession)
|
|
|
|
assert menu == req_menu
|
|
|
|
|
|
|
|
req_menus = await MenuCrud.get_menus(asession)
|
2024-01-29 20:11:39 +03:00
|
|
|
assert menu == req_menus.scalars().all()[0]
|
2024-01-29 02:19:02 +03:00
|
|
|
|
|
|
|
menu.title = "updatedMenu"
|
|
|
|
await MenuCrud.update_menu_item(
|
|
|
|
menu.id, menuschema.model_validate(menu), asession
|
|
|
|
)
|
|
|
|
req_menu = await MenuCrud.get_menu_item(menu_id, asession)
|
|
|
|
assert menu == req_menu
|
|
|
|
|
|
|
|
await MenuCrud.delete_menu_item(menu_id, asession)
|
|
|
|
req_menus = await MenuCrud.get_menus(asession)
|
|
|
|
assert req_menus.all() == []
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_submenu(asession: AsyncSession) -> None:
|
|
|
|
async with asession:
|
2024-01-29 20:11:39 +03:00
|
|
|
# Создаем меню напрямую
|
2024-01-29 02:19:02 +03:00
|
|
|
menu: Menu = Menu(title="SomeMenu", description="SomeDescription")
|
|
|
|
asession.add(menu)
|
|
|
|
await asession.commit()
|
|
|
|
await asession.refresh(menu)
|
|
|
|
menu_id: UUID = menu.id
|
2024-01-29 20:11:39 +03:00
|
|
|
|
|
|
|
# Создаем подменю через ручку
|
2024-01-29 02:19:02 +03:00
|
|
|
submenu: SubMenu = SubMenu(
|
2024-01-29 12:34:11 +03:00
|
|
|
title="submenu",
|
|
|
|
description="",
|
|
|
|
parent_menu=menu_id,
|
2024-01-29 02:19:02 +03:00
|
|
|
)
|
|
|
|
submenu = await SubMenuCrud.create_submenu_item(
|
2024-01-29 12:34:11 +03:00
|
|
|
menu_id,
|
|
|
|
menubaseschema.model_validate(submenu),
|
|
|
|
asession,
|
2024-01-29 02:19:02 +03:00
|
|
|
)
|
2024-01-29 20:11:39 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_dish(asession: AsyncSession):
|
|
|
|
async with asession:
|
|
|
|
pass
|