mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-06-23 15:31:37 -04:00
* upgrade sqlalchemy to 2.0 * rewrite all db models to sqla 2.0 mapping api * fix some importing and typing weirdness * fix types of a lot of nullable columns * remove get_ref methods * fix issues found by tests * rewrite all queries in repository_recipe to 2.0 style * rewrite all repository queries to 2.0 api * rewrite all remaining queries to 2.0 api * remove now-unneeded __allow_unmapped__ flag * remove and fix some unneeded cases of "# type: ignore" * fix formatting * bump black version * run black * can this please be the last one. okay. just. okay. * fix repository errors * remove return * drop open API validator --------- Co-authored-by: Sören Busch <fleshgolem@gmx.net>
82 lines
2.2 KiB
Python
82 lines
2.2 KiB
Python
import pytest
|
|
import sqlalchemy
|
|
from pydantic import UUID4
|
|
|
|
from mealie.repos.repository_factory import AllRepositories
|
|
from mealie.schema.group.group_shopping_list import ShoppingListItemCreate, ShoppingListOut, ShoppingListSave
|
|
from tests.utils.factories import random_string
|
|
from tests.utils.fixture_schemas import TestUser
|
|
|
|
|
|
def create_item(list_id: UUID4) -> dict:
|
|
return {
|
|
"shopping_list_id": str(list_id),
|
|
"checked": False,
|
|
"position": 0,
|
|
"is_food": False,
|
|
"note": random_string(10),
|
|
"quantity": 1,
|
|
"unit_id": None,
|
|
"food_id": None,
|
|
"recipe_id": None,
|
|
"label_id": None,
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def shopping_lists(database: AllRepositories, unique_user: TestUser):
|
|
models: list[ShoppingListOut] = []
|
|
|
|
for _ in range(3):
|
|
model = database.group_shopping_lists.create(
|
|
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
|
)
|
|
|
|
models.append(model)
|
|
|
|
yield models
|
|
|
|
for model in models:
|
|
try:
|
|
database.group_shopping_lists.delete(model.id)
|
|
except Exception: # Entry Deleted in Test
|
|
pass
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def shopping_list(database: AllRepositories, unique_user: TestUser):
|
|
model = database.group_shopping_lists.create(
|
|
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
|
)
|
|
|
|
yield model
|
|
|
|
try:
|
|
database.group_shopping_lists.delete(model.id)
|
|
except Exception: # Entry Deleted in Test
|
|
pass
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def list_with_items(database: AllRepositories, unique_user: TestUser):
|
|
list_model = database.group_shopping_lists.create(
|
|
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
|
)
|
|
|
|
for _ in range(10):
|
|
database.group_shopping_list_item.create(
|
|
ShoppingListItemCreate(
|
|
**create_item(list_model.id),
|
|
)
|
|
)
|
|
|
|
# refresh model
|
|
list_model = database.group_shopping_lists.get_one(list_model.id) # type: ignore
|
|
|
|
yield list_model
|
|
|
|
try:
|
|
database.group_shopping_lists.delete(list_model.id)
|
|
except sqlalchemy.exc.NoResultFound: # Entry Deleted in Test
|
|
pass
|