mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
fix duplicate slugs when testing
This commit is contained in:
parent
90f8eeb38a
commit
1a69e03ee3
12 changed files with 27 additions and 57 deletions
|
@ -42,7 +42,6 @@ def update_generics(func):
|
||||||
|
|
||||||
elif attribute:
|
elif attribute:
|
||||||
setattr(class_object, key, value)
|
setattr(class_object, key, value)
|
||||||
print("Complex", complex_attributed)
|
|
||||||
func(class_object, complex_attributed)
|
func(class_object, complex_attributed)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
|
@ -23,7 +23,6 @@ async def get_current_user(token: str = Depends(oauth2_scheme), session=Depends(
|
||||||
if username is None:
|
if username is None:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
token_data = TokenData(username=username)
|
token_data = TokenData(username=username)
|
||||||
print("Login Payload", token_data)
|
|
||||||
except JWTError:
|
except JWTError:
|
||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
user = db.users.get(session, token_data.username, "email")
|
user = db.users.get(session, token_data.username, "email")
|
||||||
|
|
|
@ -77,6 +77,5 @@ def get_today(
|
||||||
|
|
||||||
group_in_db: GroupInDB = db.groups.get(session, current_user.group, "name")
|
group_in_db: GroupInDB = db.groups.get(session, current_user.group, "name")
|
||||||
recipe = get_todays_meal(session, group_in_db)
|
recipe = get_todays_meal(session, group_in_db)
|
||||||
print(datetime.date.today())
|
|
||||||
|
|
||||||
return recipe.slug
|
return recipe.slug
|
||||||
|
|
|
@ -68,14 +68,11 @@ async def update_user(
|
||||||
|
|
||||||
token = None
|
token = None
|
||||||
if current_user.id == id or current_user.admin:
|
if current_user.id == id or current_user.admin:
|
||||||
print("Current User")
|
|
||||||
db.users.update(session, id, new_data.dict())
|
db.users.update(session, id, new_data.dict())
|
||||||
if current_user.id == id:
|
if current_user.id == id:
|
||||||
print(new_data.email)
|
access_token = security.create_access_token(data=dict(sub=new_data.email), expires_delta=timedelta(hours=2))
|
||||||
access_token = security.create_access_token(data=dict(sub=new_data.email), expires_delta=timedelta(hours=2))
|
token = {"access_token": access_token, "token_type": "bearer"}
|
||||||
token = {"access_token": access_token, "token_type": "bearer"}
|
|
||||||
|
|
||||||
print(SnackResponse.success("User Updated", token))
|
|
||||||
return SnackResponse.success("User Updated", token)
|
return SnackResponse.success("User Updated", token)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -89,13 +89,16 @@ class ImportDatabase:
|
||||||
# Migration from list to Object Type Data
|
# Migration from list to Object Type Data
|
||||||
try:
|
try:
|
||||||
if "" in recipe_dict["tags"]:
|
if "" in recipe_dict["tags"]:
|
||||||
recipe_dict["tags"] = [tag for tag in recipe_dict["tags"] if not tag == ""]
|
recipe_dict["tags"] = [tag for tag in recipe_dict["tags"] if tag != ""]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if "" in recipe_dict["categories"]:
|
if "" in recipe_dict["categories"]:
|
||||||
recipe_dict["categories"] = [cat for cat in recipe_dict["categories"] if not cat == ""]
|
recipe_dict["categories"] = [
|
||||||
|
cat for cat in recipe_dict["categories"] if cat != ""
|
||||||
|
]
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -239,16 +242,15 @@ class ImportDatabase:
|
||||||
|
|
||||||
item = db_table.get(self.session, search_value, search_key)
|
item = db_table.get(self.session, search_value, search_key)
|
||||||
if item:
|
if item:
|
||||||
if self.force_imports:
|
if not self.force_imports:
|
||||||
primary_key = getattr(item, db_table.primary_key)
|
|
||||||
db_table.delete(self.session, primary_key)
|
|
||||||
else:
|
|
||||||
return return_model(
|
return return_model(
|
||||||
name=model_name,
|
name=model_name,
|
||||||
status=False,
|
status=False,
|
||||||
exception=f"Table entry with matching '{search_key}': '{search_value}' exists",
|
exception=f"Table entry with matching '{search_key}': '{search_value}' exists",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
primary_key = getattr(item, db_table.primary_key)
|
||||||
|
db_table.delete(self.session, primary_key)
|
||||||
try:
|
try:
|
||||||
db_table.create(self.session, model.dict())
|
db_table.create(self.session, model.dict())
|
||||||
import_status = return_model(name=model_name, status=True)
|
import_status = return_model(name=model_name, status=True)
|
||||||
|
@ -301,12 +303,10 @@ def import_database(
|
||||||
|
|
||||||
import_session.clean_up()
|
import_session.clean_up()
|
||||||
|
|
||||||
data = {
|
return {
|
||||||
"recipeImports": recipe_report,
|
"recipeImports": recipe_report,
|
||||||
"settingsImports": settings_report,
|
"settingsImports": settings_report,
|
||||||
"themeImports": theme_report,
|
"themeImports": theme_report,
|
||||||
"groupImports": group_report,
|
"groupImports": group_report,
|
||||||
"userImports": user_report,
|
"userImports": user_report,
|
||||||
}
|
}
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
|
@ -4,26 +4,16 @@ from typing import Union
|
||||||
import pytz
|
import pytz
|
||||||
from mealie.db.database import db
|
from mealie.db.database import db
|
||||||
from mealie.db.db_setup import create_session
|
from mealie.db.db_setup import create_session
|
||||||
from pydantic.tools import T
|
from mealie.schema.meal import MealIn, MealOut, MealPlanIn, MealPlanInDB, MealPlanProcessed
|
||||||
from mealie.schema.meal import (
|
|
||||||
MealIn,
|
|
||||||
MealOut,
|
|
||||||
MealPlanIn,
|
|
||||||
MealPlanInDB,
|
|
||||||
MealPlanProcessed,
|
|
||||||
)
|
|
||||||
from mealie.schema.recipe import Recipe
|
from mealie.schema.recipe import Recipe
|
||||||
from mealie.schema.user import GroupInDB
|
from mealie.schema.user import GroupInDB
|
||||||
|
from pydantic.tools import T
|
||||||
from sqlalchemy.orm.session import Session
|
from sqlalchemy.orm.session import Session
|
||||||
|
|
||||||
|
|
||||||
def process_meals(session: Session, meal_plan_base: MealPlanIn) -> MealPlanProcessed:
|
def process_meals(session: Session, meal_plan_base: MealPlanIn) -> MealPlanProcessed:
|
||||||
meals = []
|
meals = []
|
||||||
for x, meal in enumerate(meal_plan_base.meals):
|
for x, meal in enumerate(meal_plan_base.meals):
|
||||||
# europe = pytz.timezone("America/Anchorage")
|
|
||||||
# d = europe.localize(meal_plan_base.startDate)
|
|
||||||
# print(d)
|
|
||||||
|
|
||||||
meal: MealIn
|
meal: MealIn
|
||||||
try:
|
try:
|
||||||
recipe: Recipe = db.recipes.get(session, meal.slug)
|
recipe: Recipe = db.recipes.get(session, meal.slug)
|
||||||
|
|
|
@ -2,11 +2,12 @@ import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from fastapi.logger import logger
|
||||||
from mealie.core.config import IMG_DIR, TEMP_DIR
|
from mealie.core.config import IMG_DIR, TEMP_DIR
|
||||||
from mealie.db.database import db
|
from mealie.db.database import db
|
||||||
from mealie.schema.recipe import Recipe
|
from mealie.schema.recipe import Recipe
|
||||||
from sqlalchemy.orm.session import Session
|
|
||||||
from mealie.utils.unzip import unpack_zip
|
from mealie.utils.unzip import unpack_zip
|
||||||
|
from sqlalchemy.orm.session import Session
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from yaml import CLoader as Loader
|
from yaml import CLoader as Loader
|
||||||
|
@ -50,11 +51,8 @@ def read_chowdown_file(recipe_file: Path) -> Recipe:
|
||||||
"tags": recipe_data.get("tags").split(","),
|
"tags": recipe_data.get("tags").split(","),
|
||||||
}
|
}
|
||||||
|
|
||||||
print(reformat_data)
|
reformated_list = [{"text": instruction} for instruction in reformat_data["recipeInstructions"]]
|
||||||
|
|
||||||
reformated_list = []
|
|
||||||
for instruction in reformat_data["recipeInstructions"]:
|
|
||||||
reformated_list.append({"text": instruction})
|
|
||||||
reformat_data["recipeInstructions"] = reformated_list
|
reformat_data["recipeInstructions"] = reformated_list
|
||||||
|
|
||||||
return Recipe(**reformat_data)
|
return Recipe(**reformat_data)
|
||||||
|
@ -63,21 +61,12 @@ def read_chowdown_file(recipe_file: Path) -> Recipe:
|
||||||
def chowdown_migrate(session: Session, zip_file: Path):
|
def chowdown_migrate(session: Session, zip_file: Path):
|
||||||
|
|
||||||
temp_dir = unpack_zip(zip_file)
|
temp_dir = unpack_zip(zip_file)
|
||||||
print(temp_dir.name)
|
|
||||||
|
|
||||||
path = Path(temp_dir.name)
|
|
||||||
for p in path.iterdir():
|
|
||||||
print("ItterDir", p)
|
|
||||||
for p in p.iterdir():
|
|
||||||
print("Sub Itter", p)
|
|
||||||
with temp_dir as dir:
|
with temp_dir as dir:
|
||||||
chow_dir = next(Path(dir).iterdir())
|
chow_dir = next(Path(dir).iterdir())
|
||||||
image_dir = TEMP_DIR.joinpath(chow_dir, "images")
|
image_dir = TEMP_DIR.joinpath(chow_dir, "images")
|
||||||
recipe_dir = TEMP_DIR.joinpath(chow_dir, "_recipes")
|
recipe_dir = TEMP_DIR.joinpath(chow_dir, "_recipes")
|
||||||
|
|
||||||
print(image_dir.exists())
|
|
||||||
print(recipe_dir.exists())
|
|
||||||
|
|
||||||
failed_recipes = []
|
failed_recipes = []
|
||||||
successful_recipes = []
|
successful_recipes = []
|
||||||
for recipe in recipe_dir.glob("*.md"):
|
for recipe in recipe_dir.glob("*.md"):
|
||||||
|
@ -86,17 +75,18 @@ def chowdown_migrate(session: Session, zip_file: Path):
|
||||||
db.recipes.create(session, new_recipe.dict())
|
db.recipes.create(session, new_recipe.dict())
|
||||||
successful_recipes.append(new_recipe.name)
|
successful_recipes.append(new_recipe.name)
|
||||||
except Exception as inst:
|
except Exception as inst:
|
||||||
|
session.rollback()
|
||||||
|
logger.error(inst)
|
||||||
failed_recipes.append(recipe.stem)
|
failed_recipes.append(recipe.stem)
|
||||||
|
|
||||||
failed_images = []
|
failed_images = []
|
||||||
for image in image_dir.iterdir():
|
for image in image_dir.iterdir():
|
||||||
try:
|
try:
|
||||||
if not image.stem in failed_recipes:
|
if image.stem not in failed_recipes:
|
||||||
shutil.copy(image, IMG_DIR.joinpath(image.name))
|
shutil.copy(image, IMG_DIR.joinpath(image.name))
|
||||||
except Exception as inst:
|
except Exception as inst:
|
||||||
print(inst)
|
logger.error(inst)
|
||||||
failed_images.append(image.name)
|
failed_images.append(image.name)
|
||||||
|
|
||||||
report = {"successful": successful_recipes, "failed": failed_recipes}
|
report = {"successful": successful_recipes, "failed": failed_recipes}
|
||||||
|
|
||||||
return report
|
return report
|
||||||
|
|
|
@ -52,8 +52,7 @@ class Cleaner:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def html(raw_html):
|
def html(raw_html):
|
||||||
cleanr = re.compile("<.*?>")
|
cleanr = re.compile("<.*?>")
|
||||||
cleantext = re.sub(cleanr, "", raw_html)
|
return re.sub(cleanr, "", raw_html)
|
||||||
return cleantext
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def image(image=None) -> str:
|
def image(image=None) -> str:
|
||||||
|
@ -142,12 +141,11 @@ class Cleaner:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def time(time_entry):
|
def time(time_entry):
|
||||||
print(time_entry, type(time_entry))
|
if time_entry is None:
|
||||||
if time_entry == None:
|
|
||||||
return None
|
return None
|
||||||
elif type(time_entry) == datetime:
|
elif type(time_entry) == datetime:
|
||||||
print(time_entry)
|
print(time_entry)
|
||||||
elif type(time_entry) != str:
|
elif type(time_entry) != str:
|
||||||
return str(time_entry)
|
return str(time_entry)
|
||||||
elif time_entry != None:
|
else:
|
||||||
return time_entry
|
return time_entry
|
||||||
|
|
|
@ -25,13 +25,10 @@ def create_from_url(url: str) -> Recipe:
|
||||||
"""
|
"""
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
new_recipe = extract_recipe_from_html(r.text, url)
|
new_recipe = extract_recipe_from_html(r.text, url)
|
||||||
print(new_recipe)
|
|
||||||
new_recipe = Cleaner.clean(new_recipe, url)
|
new_recipe = Cleaner.clean(new_recipe, url)
|
||||||
new_recipe = download_image_for_recipe(new_recipe)
|
new_recipe = download_image_for_recipe(new_recipe)
|
||||||
|
|
||||||
recipe = Recipe(**new_recipe)
|
return Recipe(**new_recipe)
|
||||||
|
|
||||||
return recipe
|
|
||||||
|
|
||||||
|
|
||||||
def extract_recipe_from_html(html: str, url: str) -> dict:
|
def extract_recipe_from_html(html: str, url: str) -> dict:
|
||||||
|
|
|
@ -34,6 +34,7 @@ def test_upload_chowdown_zip(api_client, chowdown_zip):
|
||||||
|
|
||||||
|
|
||||||
def test_import_chowdown_directory(api_client, chowdown_zip):
|
def test_import_chowdown_directory(api_client, chowdown_zip):
|
||||||
|
api_client.delete(f"{RECIPES_PREFIX}/roasted-okra") # TODO: Manage Test Data better
|
||||||
selection = chowdown_zip.name
|
selection = chowdown_zip.name
|
||||||
response = api_client.post(f"{MIGRATIONS_PREFIX}/chowdown/{selection}/import")
|
response = api_client.post(f"{MIGRATIONS_PREFIX}/chowdown/{selection}/import")
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ def test_create_by_url(api_client, recipe_data: RecipeTestData):
|
||||||
|
|
||||||
|
|
||||||
def test_create_by_json(api_client):
|
def test_create_by_json(api_client):
|
||||||
|
api_client.delete(f"{RECIPES_PREFIX}/banana-bread")
|
||||||
response = api_client.post(RECIPES_CREATE, json=raw_recipe)
|
response = api_client.post(RECIPES_CREATE, json=raw_recipe)
|
||||||
|
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
|
|
|
@ -66,7 +66,6 @@ def test_update_user(api_client: requests, token):
|
||||||
response = api_client.put(f"{BASE}/1", headers=token, json=update_data)
|
response = api_client.put(f"{BASE}/1", headers=token, json=update_data)
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
print(response.text)
|
|
||||||
assert json.loads(response.text).get("access_token")
|
assert json.loads(response.text).get("access_token")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue