mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-03 04:25:24 +02:00
feature: proper multi-tenant-support (#969)(WIP)
* update naming * refactor tests to use shared structure * shorten names * add tools test case * refactor to support multi-tenant * set group_id on creation * initial refactor for multitenant tags/cats * spelling * additional test case for same valued resources * fix recipe update tests * apply indexes to foreign keys * fix performance regressions * handle unknown exception * utility decorator for function debugging * migrate recipe_id to UUID * GUID for recipes * remove unused import * move image functions into package * move utilities to packages dir * update import * linter * image image and asset routes * update assets and images to use UUIDs * fix migration base * image asset test coverage * use ids for categories and tag crud functions * refactor recipe organizer test suite to reduce duplication * add uuid serlization utility * organizer base router * slug routes testing and fixes * fix postgres error * adopt UUIDs * move tags, categories, and tools under "organizers" umbrella * update composite label * generate ts types * fix import error * update frontend types * fix type errors * fix postgres errors * fix #978 * add null check for title validation * add note in docs on multi-tenancy
This commit is contained in:
parent
9a82a172cb
commit
c617251f4c
157 changed files with 1866 additions and 1578 deletions
|
@ -48,6 +48,7 @@ def test_create_mealplan_with_recipe(api_client: TestClient, unique_user: TestUs
|
|||
|
||||
new_plan = CreatePlanEntry(date=date.today(), entry_type="dinner", recipe_id=recipe_id).dict(by_alias=True)
|
||||
new_plan["date"] = date.today().strftime("%Y-%m-%d")
|
||||
new_plan["recipeId"] = str(recipe_id)
|
||||
|
||||
response = api_client.post(Routes.base, json=new_plan, headers=unique_user.token)
|
||||
response_json = response.json()
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
from fastapi.testclient import TestClient
|
||||
|
||||
from mealie.repos.all_repositories import AllRepositories
|
||||
from tests.utils.assertion_helpers import assert_ignore_keys
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
||||
class Routes:
|
||||
base = "/api/groups/categories"
|
||||
|
||||
@staticmethod
|
||||
def item(item_id: int | str) -> str:
|
||||
return f"{Routes.base}/{item_id}"
|
||||
|
||||
|
||||
def test_group_mealplan_set_preferences(api_client: TestClient, unique_user: TestUser, database: AllRepositories):
|
||||
# Create Categories
|
||||
categories = [{"name": x} for x in ["Breakfast", "Lunch", "Dinner"]]
|
||||
|
||||
created = []
|
||||
for category in categories:
|
||||
create = database.categories.create(category)
|
||||
created.append(create.dict())
|
||||
|
||||
# Set Category Preferences
|
||||
response = api_client.put(Routes.base, json=created, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
# Get Category Preferences
|
||||
response = api_client.get(Routes.base, headers=unique_user.token)
|
||||
assert response.status_code == 200
|
||||
|
||||
as_dict = response.json()
|
||||
|
||||
assert len(as_dict) == len(categories)
|
||||
|
||||
for api_data, expected in zip(as_dict, created):
|
||||
assert_ignore_keys(api_data, expected, ["id", "recipes"])
|
|
@ -7,6 +7,7 @@ from pydantic import UUID4
|
|||
from mealie.repos.all_repositories import AllRepositories
|
||||
from mealie.schema.meal_plan.plan_rules import PlanRulesOut, PlanRulesSave
|
||||
from mealie.schema.recipe.recipe import RecipeCategory
|
||||
from mealie.schema.recipe.recipe_category import CategorySave
|
||||
from tests import utils
|
||||
from tests.utils.fixture_schemas import TestUser
|
||||
|
||||
|
@ -20,9 +21,12 @@ class Routes:
|
|||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def category(database: AllRepositories):
|
||||
def category(
|
||||
database: AllRepositories,
|
||||
unique_user: TestUser,
|
||||
):
|
||||
slug = utils.random_string(length=10)
|
||||
model = database.categories.create(RecipeCategory(slug=slug, name=slug))
|
||||
model = database.categories.create(CategorySave(group_id=unique_user.group_id, slug=slug, name=slug))
|
||||
|
||||
yield model
|
||||
|
||||
|
@ -61,7 +65,7 @@ def test_group_mealplan_rules_create(
|
|||
"categories": [category.dict()],
|
||||
}
|
||||
|
||||
response = api_client.post(Routes.base, json=payload, headers=unique_user.token)
|
||||
response = api_client.post(Routes.base, json=utils.jsonify(payload), headers=unique_user.token)
|
||||
assert response.status_code == 201
|
||||
|
||||
# Validate the response data
|
||||
|
|
|
@ -121,7 +121,7 @@ def test_shopping_lists_add_recipe(
|
|||
|
||||
assert len(refs) == 1
|
||||
|
||||
assert refs[0]["recipeId"] == recipe.id
|
||||
assert refs[0]["recipeId"] == str(recipe.id)
|
||||
|
||||
|
||||
def test_shopping_lists_remove_recipe(
|
||||
|
@ -198,4 +198,4 @@ def test_shopping_lists_remove_recipe_multiple_quantity(
|
|||
|
||||
refs = as_json["recipeReferences"]
|
||||
assert len(refs) == 1
|
||||
assert refs[0]["recipeId"] == recipe.id
|
||||
assert refs[0]["recipeId"] == str(recipe.id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue