58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import datetime
|
|
|
|
import pytest
|
|
import pytest_asyncio
|
|
|
|
from fooder.controller.diary import DiaryController
|
|
from fooder.controller.meal import MealController
|
|
from fooder.controller.entry import EntryController
|
|
from fooder.model.meal import MealCreateModel
|
|
from fooder.model.entry import EntryCreateModel
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def diary(auth_ctx, user_settings):
|
|
async with auth_ctx.repo.transaction():
|
|
ctrl = await DiaryController.create(
|
|
auth_ctx,
|
|
date=datetime.date.today(),
|
|
settings=user_settings,
|
|
)
|
|
await MealController.create(
|
|
auth_ctx,
|
|
diary_id=ctrl.obj.id,
|
|
data=MealCreateModel(name="Breakfast"),
|
|
)
|
|
return ctrl.obj
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def meal(auth_ctx, diary):
|
|
async with auth_ctx.repo.transaction():
|
|
ctrl = await MealController.create(
|
|
auth_ctx,
|
|
diary_id=diary.id,
|
|
data=MealCreateModel(name="Lunch"),
|
|
)
|
|
return ctrl.obj
|
|
|
|
|
|
@pytest_asyncio.fixture
|
|
async def entry(auth_ctx, meal, product):
|
|
async with auth_ctx.repo.transaction():
|
|
ctrl = await EntryController.create(
|
|
auth_ctx,
|
|
meal_id=meal.id,
|
|
data=EntryCreateModel(grams=100.0, product_id=product.id),
|
|
)
|
|
return ctrl.obj
|
|
|
|
|
|
@pytest.fixture
|
|
def meal_payload():
|
|
return {"name": "Dinner"}
|
|
|
|
|
|
@pytest.fixture
|
|
def entry_payload(product):
|
|
return {"grams": 150.0, "product_id": product.id}
|