diff --git a/mealie/tests/test_routes/test_meal_routes.py b/mealie/tests/test_routes/test_meal_routes.py index 2df010e51..49c69b488 100644 --- a/mealie/tests/test_routes/test_meal_routes.py +++ b/mealie/tests/test_routes/test_meal_routes.py @@ -8,34 +8,53 @@ def cleanup(api_client): api_client.delete(f"/api/recipe/{recipe_test_data[1].expected_slug}/delete/") -meal_plan = { - "startDate": "2021-01-18", - "endDate": "2021-01-19", - "meals": [ - { - "slug": None, - "date": "2021-1-17", - "dateText": "Monday, January 18, 2021", - }, - { - "slug": None, - "date": "2021-1-18", - "dateText": "Tueday, January 19, 2021", - }, - ], -} +def get_meal_plan_template(first=None, second=None): + return { + "startDate": "2021-01-18", + "endDate": "2021-01-19", + "meals": [ + { + "slug": first, + "date": "2021-1-17", + "dateText": "Monday, January 18, 2021", + }, + { + "slug": second, + "date": "2021-1-18", + "dateText": "Tueday, January 19, 2021", + }, + ], + } + + +slug_1 = None +slug_2 = None + + +def get_slugs(api_client): + # Slug 1 + global slug_1 + global slug_2 + if slug_1 == None: + slug_1 = api_client.post( + "/api/recipe/create-url/", json={"url": recipe_test_data[0].url} + ) + slug_1 = json.loads(slug_1.content) + + # Slug 2 + slug_2 = api_client.post( + "/api/recipe/create-url/", json={"url": recipe_test_data[1].url} + ) + slug_2 = json.loads(slug_2.content) + + return slug_1, slug_2 def test_create_mealplan(api_client): - slug_1 = api_client.post( - "/api/recipe/create-url/", json={"url": recipe_test_data[0].url} - ) - slug_2 = api_client.post( - "/api/recipe/create-url/", json={"url": recipe_test_data[1].url} - ) - - meal_plan["meals"][0]["slug"] = json.loads(slug_1.content) - meal_plan["meals"][1]["slug"] = json.loads(slug_2.content) + slug_1, slug_2 = get_slugs(api_client) + meal_plan = get_meal_plan_template() + meal_plan["meals"][0]["slug"] = slug_1 + meal_plan["meals"][1]["slug"] = slug_2 response = api_client.post("/api/meal-plan/create/", json=meal_plan) assert response.status_code == 200 @@ -46,22 +65,18 @@ def test_read_mealplan(api_client): assert response.status_code == 200 + slug_1, slug_2 = get_slugs(api_client) + meal_plan = get_meal_plan_template(slug_1, slug_2) + new_meal_plan = json.loads(response.text) meals = new_meal_plan[0]["meals"] assert meals[0]["slug"] == meal_plan["meals"][0]["slug"] assert meals[1]["slug"] == meal_plan["meals"][1]["slug"] - cleanup(api_client) - def test_update_mealplan(api_client): - slug_1 = api_client.post( - "/api/recipe/create-url/", json={"url": recipe_test_data[0].url} - ) - slug_2 = api_client.post( - "/api/recipe/create-url/", json={"url": recipe_test_data[1].url} - ) + slug_1, slug_2 = get_slugs(api_client) response = api_client.get("/api/meal-plan/all/") @@ -70,8 +85,8 @@ def test_update_mealplan(api_client): ## Swap plan_uid = existing_mealplan.get("uid") - existing_mealplan["meals"][0]["slug"] = json.loads(slug_2.content) - existing_mealplan["meals"][1]["slug"] = json.loads(slug_1.content) + existing_mealplan["meals"][0]["slug"] = slug_2 + existing_mealplan["meals"][1]["slug"] = slug_1 response = api_client.post( f"/api/meal-plan/{plan_uid}/update/", json=existing_mealplan @@ -83,10 +98,8 @@ def test_update_mealplan(api_client): existing_mealplan = json.loads(response.text) existing_mealplan = existing_mealplan[0] - assert existing_mealplan["meals"][0]["slug"] == json.loads(slug_2.content) - assert existing_mealplan["meals"][1]["slug"] == json.loads(slug_1.content) - - cleanup(api_client) + assert existing_mealplan["meals"][0]["slug"] == slug_2 + assert existing_mealplan["meals"][1]["slug"] == slug_1 def test_delete_mealplan(api_client): diff --git a/mealie/tests/test_migrations/__init__.py b/mealie/tests/test_routes/utils/meal_utils.py similarity index 100% rename from mealie/tests/test_migrations/__init__.py rename to mealie/tests/test_routes/utils/meal_utils.py diff --git a/mealie/tests/test_recipes/__init__.py b/mealie/tests/test_services/test_migrations/__init__.py similarity index 100% rename from mealie/tests/test_recipes/__init__.py rename to mealie/tests/test_services/test_migrations/__init__.py diff --git a/mealie/tests/data/nextcloud_recipes/Air Fryer Shrimp/recipe.json b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Air Fryer Shrimp/recipe.json similarity index 100% rename from mealie/tests/data/nextcloud_recipes/Air Fryer Shrimp/recipe.json rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Air Fryer Shrimp/recipe.json diff --git a/mealie/tests/data/nextcloud_recipes/Air Fryer Shrimp/thumb.jpg b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Air Fryer Shrimp/thumb.jpg similarity index 100% rename from mealie/tests/data/nextcloud_recipes/Air Fryer Shrimp/thumb.jpg rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Air Fryer Shrimp/thumb.jpg diff --git a/mealie/tests/data/nextcloud_recipes/Chicken Parmigiana/recipe.json b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Chicken Parmigiana/recipe.json similarity index 100% rename from mealie/tests/data/nextcloud_recipes/Chicken Parmigiana/recipe.json rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Chicken Parmigiana/recipe.json diff --git a/mealie/tests/data/nextcloud_recipes/Chicken Parmigiana/thumb.jpg b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Chicken Parmigiana/thumb.jpg similarity index 100% rename from mealie/tests/data/nextcloud_recipes/Chicken Parmigiana/thumb.jpg rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Chicken Parmigiana/thumb.jpg diff --git a/mealie/tests/data/nextcloud_recipes/Skillet Shepherd's Pie/recipe.json b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Skillet Shepherd's Pie/recipe.json similarity index 100% rename from mealie/tests/data/nextcloud_recipes/Skillet Shepherd's Pie/recipe.json rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/Skillet Shepherd's Pie/recipe.json diff --git a/mealie/tests/data/nextcloud_recipes/nextcloud.zip b/mealie/tests/test_services/test_migrations/data/nextcloud_recipes/nextcloud.zip similarity index 100% rename from mealie/tests/data/nextcloud_recipes/nextcloud.zip rename to mealie/tests/test_services/test_migrations/data/nextcloud_recipes/nextcloud.zip diff --git a/mealie/tests/test_migrations/test_nextcloud.py b/mealie/tests/test_services/test_migrations/test_nextcloud.py similarity index 94% rename from mealie/tests/test_migrations/test_nextcloud.py rename to mealie/tests/test_services/test_migrations/test_nextcloud.py index 01fc7cfad..ec7ef2eea 100644 --- a/mealie/tests/test_migrations/test_nextcloud.py +++ b/mealie/tests/test_services/test_migrations/test_nextcloud.py @@ -11,7 +11,7 @@ from services.migrations.nextcloud import ( from services.recipe_services import Recipe CWD = Path(__file__).parent -NEXTCLOUD_DIR = CWD.parent.joinpath("data", "nextcloud_recipes") +NEXTCLOUD_DIR = CWD.joinpath("data", "nextcloud_recipes") TEMP_NEXTCLOUD = TEMP_DIR.joinpath("nextcloud") diff --git a/mealie/tests/test_services/test_scraper/__init__.py b/mealie/tests/test_services/test_scraper/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/mealie/tests/data/html-raw/carottes-rapps-with-rice-and-sunflower-seeds.html b/mealie/tests/test_services/test_scraper/data/html-raw/carottes-rapps-with-rice-and-sunflower-seeds.html similarity index 100% rename from mealie/tests/data/html-raw/carottes-rapps-with-rice-and-sunflower-seeds.html rename to mealie/tests/test_services/test_scraper/data/html-raw/carottes-rapps-with-rice-and-sunflower-seeds.html diff --git a/mealie/tests/data/html-raw/healthy_pasta_bake_60759.html b/mealie/tests/test_services/test_scraper/data/html-raw/healthy_pasta_bake_60759.html similarity index 100% rename from mealie/tests/data/html-raw/healthy_pasta_bake_60759.html rename to mealie/tests/test_services/test_scraper/data/html-raw/healthy_pasta_bake_60759.html diff --git a/mealie/tests/data/recipes-raw/Pizza-Knoblauch-Champignon-Paprika-vegan.html.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/Pizza-Knoblauch-Champignon-Paprika-vegan.html.json similarity index 100% rename from mealie/tests/data/recipes-raw/Pizza-Knoblauch-Champignon-Paprika-vegan.html.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/Pizza-Knoblauch-Champignon-Paprika-vegan.html.json diff --git a/mealie/tests/data/recipes-raw/best-homemade-salsa-recipe.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/best-homemade-salsa-recipe.json similarity index 100% rename from mealie/tests/data/recipes-raw/best-homemade-salsa-recipe.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/best-homemade-salsa-recipe.json diff --git a/mealie/tests/data/recipes-raw/blue-cheese-stuffed-turkey-meatballs-with-raspberry-balsamic-glaze-2.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/blue-cheese-stuffed-turkey-meatballs-with-raspberry-balsamic-glaze-2.json similarity index 100% rename from mealie/tests/data/recipes-raw/blue-cheese-stuffed-turkey-meatballs-with-raspberry-balsamic-glaze-2.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/blue-cheese-stuffed-turkey-meatballs-with-raspberry-balsamic-glaze-2.json diff --git a/mealie/tests/data/recipes-raw/bon_appetit.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/bon_appetit.json similarity index 100% rename from mealie/tests/data/recipes-raw/bon_appetit.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/bon_appetit.json diff --git a/mealie/tests/data/recipes-raw/chunky-apple-cake.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/chunky-apple-cake.json similarity index 100% rename from mealie/tests/data/recipes-raw/chunky-apple-cake.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/chunky-apple-cake.json diff --git a/mealie/tests/data/recipes-raw/dairy-free-impossible-pumpkin-pie.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/dairy-free-impossible-pumpkin-pie.json similarity index 100% rename from mealie/tests/data/recipes-raw/dairy-free-impossible-pumpkin-pie.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/dairy-free-impossible-pumpkin-pie.json diff --git a/mealie/tests/data/recipes-raw/how-to-make-instant-pot-spaghetti.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/how-to-make-instant-pot-spaghetti.json similarity index 100% rename from mealie/tests/data/recipes-raw/how-to-make-instant-pot-spaghetti.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/how-to-make-instant-pot-spaghetti.json diff --git a/mealie/tests/data/recipes-raw/instant-pot-chicken-and-potatoes.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/instant-pot-chicken-and-potatoes.json similarity index 100% rename from mealie/tests/data/recipes-raw/instant-pot-chicken-and-potatoes.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/instant-pot-chicken-and-potatoes.json diff --git a/mealie/tests/data/recipes-raw/instant-pot-kerala-vegetable-stew.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/instant-pot-kerala-vegetable-stew.json similarity index 100% rename from mealie/tests/data/recipes-raw/instant-pot-kerala-vegetable-stew.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/instant-pot-kerala-vegetable-stew.json diff --git a/mealie/tests/data/recipes-raw/jalapeno-popper-dip.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/jalapeno-popper-dip.json similarity index 100% rename from mealie/tests/data/recipes-raw/jalapeno-popper-dip.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/jalapeno-popper-dip.json diff --git a/mealie/tests/data/recipes-raw/microwave_sweet_potatoes_04783.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/microwave_sweet_potatoes_04783.json similarity index 100% rename from mealie/tests/data/recipes-raw/microwave_sweet_potatoes_04783.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/microwave_sweet_potatoes_04783.json diff --git a/mealie/tests/data/recipes-raw/moroccan-skirt-steak-with-roasted-pepper-couscous.json b/mealie/tests/test_services/test_scraper/data/recipes-raw/moroccan-skirt-steak-with-roasted-pepper-couscous.json similarity index 100% rename from mealie/tests/data/recipes-raw/moroccan-skirt-steak-with-roasted-pepper-couscous.json rename to mealie/tests/test_services/test_scraper/data/recipes-raw/moroccan-skirt-steak-with-roasted-pepper-couscous.json diff --git a/mealie/tests/test_recipes/test_scraper.py b/mealie/tests/test_services/test_scraper/test_scraper.py similarity index 96% rename from mealie/tests/test_recipes/test_scraper.py rename to mealie/tests/test_services/test_scraper/test_scraper.py index 2201007d8..ab635dc4d 100644 --- a/mealie/tests/test_recipes/test_scraper.py +++ b/mealie/tests/test_services/test_scraper/test_scraper.py @@ -10,8 +10,8 @@ from services.scrape_services import ( ) CWD = Path(__file__).parent -RAW_RECIPE_DIR = CWD.parent.joinpath("data", "recipes-raw") -RAW_HTML_DIR = CWD.parent.joinpath("data", "html-raw") +RAW_RECIPE_DIR = CWD.joinpath("data", "recipes-raw") +RAW_HTML_DIR = CWD.joinpath("data", "html-raw") # https://github.com/django/django/blob/stable/1.3.x/django/core/validators.py#L45 url_validation_regex = re.compile(