2021-06-09 13:04:54 -08:00
|
|
|
import pytest
|
2021-08-28 14:27:56 -08:00
|
|
|
|
2023-12-09 17:19:27 +00:00
|
|
|
from mealie.lang.providers import local_provider
|
2021-06-09 13:04:54 -08:00
|
|
|
from mealie.services.scraper import scraper
|
2021-06-13 13:09:44 -08:00
|
|
|
from tests.utils.recipe_data import RecipeSiteTestCase, get_recipe_test_cases
|
2021-06-09 13:04:54 -08:00
|
|
|
|
2021-06-13 13:09:44 -08:00
|
|
|
test_cases = get_recipe_test_cases()
|
2021-06-09 13:04:54 -08:00
|
|
|
|
2021-06-13 13:09:44 -08:00
|
|
|
"""
|
2021-09-09 08:51:29 -08:00
|
|
|
|
2021-06-13 13:09:44 -08:00
|
|
|
These tests are skipped by default and only really used when troubleshooting the parser
|
|
|
|
directly. If you are working on improve the parser you can add test cases to the `get_recipe_test_cases` function
|
|
|
|
and then use this test case by removing the `@pytest.mark.skip` and than testing your results.
|
2021-09-09 08:51:29 -08:00
|
|
|
|
2021-06-13 13:09:44 -08:00
|
|
|
"""
|
2021-06-09 13:04:54 -08:00
|
|
|
|
|
|
|
|
2022-01-13 13:06:52 -09:00
|
|
|
@pytest.mark.skipif(True, reason="Long Running API Test - manually run when updating the parser")
|
2021-06-09 13:04:54 -08:00
|
|
|
@pytest.mark.parametrize("recipe_test_data", test_cases)
|
2023-01-29 01:43:27 +01:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_recipe_parser(recipe_test_data: RecipeSiteTestCase):
|
2023-12-09 17:19:27 +00:00
|
|
|
translator = local_provider()
|
2024-09-30 10:52:13 -05:00
|
|
|
recipe, _ = await scraper.create_from_html(recipe_test_data.url, translator)
|
2021-06-09 13:04:54 -08:00
|
|
|
|
|
|
|
assert recipe.slug == recipe_test_data.expected_slug
|
2024-10-13 09:04:29 -04:00
|
|
|
|
2023-12-09 17:19:27 +00:00
|
|
|
assert len(recipe.recipe_instructions or []) == recipe_test_data.num_steps
|
2024-10-13 09:04:29 -04:00
|
|
|
|
2021-06-09 13:04:54 -08:00
|
|
|
assert len(recipe.recipe_ingredient) == recipe_test_data.num_ingredients
|
2024-10-13 09:04:29 -04:00
|
|
|
|
|
|
|
actual = recipe.nutrition.model_dump() if recipe.nutrition else {}
|
|
|
|
assert recipe_test_data.num_nutrition_entries == len(actual.items())
|
|
|
|
|
2021-06-09 13:04:54 -08:00
|
|
|
assert recipe.org_url == recipe_test_data.url
|