refactor: moving directories around
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 114 KiB After Width: | Height: | Size: 114 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
20
mealie/tests/test_config.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from pathlib import Path
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
|
||||
|
||||
TEST_DIR = CWD
|
||||
TEST_DATA = CWD.joinpath("data")
|
||||
|
||||
# Scraper
|
||||
TEST_RAW_HTML = TEST_DATA.joinpath("scraper", "html-raw")
|
||||
TEST_RAW_RECIPES = TEST_DATA.joinpath("scraper", "recipes-raw")
|
||||
|
||||
# Migrations
|
||||
TEST_CHOWDOWN_DIR = TEST_DATA.joinpath("migrations", "chowdown")
|
||||
TEST_NEXTCLOUD_DIR = TEST_DATA.joinpath("migrations", "nextcloud")
|
||||
|
||||
# Routes
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
|
@ -1,13 +1,9 @@
|
|||
import json
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from app_config import BASE_DIR, MIGRATION_DIR
|
||||
from tests.test_services.test_migrations.test_nextcloud import NEXTCLOUD_DIR
|
||||
|
||||
TEST_DIR = BASE_DIR.joinpath("tests")
|
||||
|
||||
import pytest
|
||||
from app_config import MIGRATION_DIR
|
||||
from tests.test_config import TEST_NEXTCLOUD_DIR
|
||||
|
||||
#! Broken
|
||||
# def test_import_chowdown_recipes(api_client):
|
||||
|
@ -28,13 +24,9 @@ import pytest
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def nextcloud_zip():
|
||||
zip = TEST_DIR.joinpath(
|
||||
"test_services/test_migrations/data/nextcloud_recipes/nextcloud.zip"
|
||||
)
|
||||
zip = TEST_NEXTCLOUD_DIR.joinpath("nextcloud.zip")
|
||||
|
||||
zip_copy = TEST_DIR.joinpath(
|
||||
"test_services/test_migrations/data/nextcloud_recipes/new_nextcloud.zip"
|
||||
)
|
||||
zip_copy = TEST_NEXTCLOUD_DIR.joinpath("new_nextcloud.zip")
|
||||
|
||||
shutil.copy(zip, zip_copy)
|
||||
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
from pathlib import Path
|
||||
from app_config import TEMP_DIR
|
||||
|
||||
import pytest
|
||||
from app_config import TEMP_DIR
|
||||
from services.image_services import IMG_DIR
|
||||
from services.migrations.nextcloud import (
|
||||
cleanup,
|
||||
import_recipes,
|
||||
prep,
|
||||
process_selection,
|
||||
)
|
||||
from services.migrations.nextcloud import (cleanup, import_recipes, prep,
|
||||
process_selection)
|
||||
from services.recipe_services import Recipe
|
||||
from tests.test_config import TEST_NEXTCLOUD_DIR
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
NEXTCLOUD_DIR = CWD.joinpath("data", "nextcloud_recipes")
|
||||
TEST_NEXTCLOUD_DIR
|
||||
TEMP_NEXTCLOUD = TEMP_DIR.joinpath("nextcloud")
|
||||
|
||||
|
||||
|
@ -21,7 +19,7 @@ TEMP_NEXTCLOUD = TEMP_DIR.joinpath("nextcloud")
|
|||
)
|
||||
def test_zip_extraction(file_name: str, final_path: Path):
|
||||
prep()
|
||||
zip = NEXTCLOUD_DIR.joinpath(file_name)
|
||||
zip = TEST_NEXTCLOUD_DIR.joinpath(file_name)
|
||||
dir = process_selection(zip)
|
||||
|
||||
assert dir == final_path
|
||||
|
@ -32,9 +30,9 @@ def test_zip_extraction(file_name: str, final_path: Path):
|
|||
@pytest.mark.parametrize(
|
||||
"recipe_dir",
|
||||
[
|
||||
NEXTCLOUD_DIR.joinpath("Air Fryer Shrimp"),
|
||||
NEXTCLOUD_DIR.joinpath("Chicken Parmigiana"),
|
||||
NEXTCLOUD_DIR.joinpath("Skillet Shepherd's Pie"),
|
||||
TEST_NEXTCLOUD_DIR.joinpath("Air Fryer Shrimp"),
|
||||
TEST_NEXTCLOUD_DIR.joinpath("Chicken Parmigiana"),
|
||||
TEST_NEXTCLOUD_DIR.joinpath("Skillet Shepherd's Pie"),
|
||||
],
|
||||
)
|
||||
def test_nextcloud_migration(recipe_dir: Path):
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from services.scrape_services import (
|
||||
|
@ -8,10 +7,7 @@ from services.scrape_services import (
|
|||
normalize_data,
|
||||
normalize_instructions,
|
||||
)
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
RAW_RECIPE_DIR = CWD.joinpath("data", "recipes-raw")
|
||||
RAW_HTML_DIR = CWD.joinpath("data", "html-raw")
|
||||
from tests.test_config import TEST_RAW_HTML, TEST_RAW_RECIPES
|
||||
|
||||
# https://github.com/django/django/blob/stable/1.3.x/django/core/validators.py#L45
|
||||
url_validation_regex = re.compile(
|
||||
|
@ -46,7 +42,7 @@ url_validation_regex = re.compile(
|
|||
],
|
||||
)
|
||||
def test_normalize_data(json_file, num_steps):
|
||||
recipe_data = normalize_data(json.load(open(RAW_RECIPE_DIR.joinpath(json_file))))
|
||||
recipe_data = normalize_data(json.load(open(TEST_RAW_RECIPES.joinpath(json_file))))
|
||||
assert len(recipe_data["recipeInstructions"]) == num_steps
|
||||
|
||||
|
||||
|
@ -70,7 +66,7 @@ def test_normalize_instructions(instructions):
|
|||
|
||||
|
||||
def test_html_no_recipe_data():
|
||||
path = RAW_HTML_DIR.joinpath("carottes-rapps-with-rice-and-sunflower-seeds.html")
|
||||
path = TEST_RAW_HTML.joinpath("carottes-rapps-with-rice-and-sunflower-seeds.html")
|
||||
url = "https://www.feedtheswimmers.com/blog/2019/6/5/carottes-rapps-with-rice-and-sunflower-seeds"
|
||||
recipe_data = extract_recipe_from_html(open(path).read(), url)
|
||||
|
||||
|
@ -86,7 +82,7 @@ def test_html_no_recipe_data():
|
|||
|
||||
|
||||
def test_html_with_recipe_data():
|
||||
path = RAW_HTML_DIR.joinpath("healthy_pasta_bake_60759.html")
|
||||
path = TEST_RAW_HTML.joinpath("healthy_pasta_bake_60759.html")
|
||||
url = "https://www.bbc.co.uk/food/recipes/healthy_pasta_bake_60759"
|
||||
recipe_data = extract_recipe_from_html(open(path).read(), url)
|
||||
|
||||
|
|