commit36403ecbae
Author: smilerz <smilerz@gmail.com> Date: Fri Sep 1 12:04:04 2023 -0500 update migration for new Automation Types commit4620ebaf30
Author: smilerz <smilerz@gmail.com> Date: Fri Sep 1 07:49:10 2023 -0500 add Name and Instruction automation to YouTube importer commitc907da84c1
Author: smilerz <smilerz@gmail.com> Date: Fri Sep 1 07:45:32 2023 -0500 remove old commented automation code commit9b5e39415e
Author: smilerz <smilerz@gmail.com> Date: Fri Sep 1 07:37:36 2023 -0500 test for automations applied during url import renamed TITLE_REPLACE to NAME_REPLACE commit2679a22464
Author: smilerz <smilerz@gmail.com> Date: Thu Aug 31 15:29:59 2023 -0500 added tests for regex_replace commit8bae21025b
Author: smilerz <smilerz@gmail.com> Date: Thu Aug 31 13:51:46 2023 -0500 updated Automation Modal and translations commit4120adc546
Author: smilerz <smilerz@gmail.com> Date: Thu Aug 31 13:12:41 2023 -0500 applied regex_replace automation to food and unit automations updated automation documentation commit30c891abfc
Author: smilerz <smilerz@gmail.com> Date: Thu Aug 31 12:46:34 2023 -0500 migrate regex_replace functions to AutomationEngine create TITLE_REPLACE, UNIT_REPLACE and FOOD REPLACE automation types create migration for new types commitb8317c2c29
Author: smilerz <smilerz@gmail.com> Date: Wed Aug 30 20:44:40 2023 -0500 move transpose words to AutomationEngine create tests for transpose words commit39253cfd02
Author: smilerz <smilerz@gmail.com> Date: Wed Aug 30 17:03:29 2023 -0500 refactor never_unit automation to AutomationEngine create tests for never_unit commit7c0b8b151c
Author: smilerz <smilerz@gmail.com> Date: Wed Aug 30 11:21:06 2023 -0500 update ingredient parser to use AutomationEngine for unt, keyword, food update test_ingredient_parser tests to accomodate changes commit8e1b8923af
Author: smilerz <smilerz@gmail.com> Date: Mon Aug 28 16:44:35 2023 -0500 keyword and unit Automtations refactored to Automation Engine keyword and unit automation tests added commit52eb876a08
Author: smilerz <smilerz@gmail.com> Date: Mon Aug 28 15:03:19 2023 -0500 food_alias tests added commita820b9c09e
Author: smilerz <smilerz@gmail.com> Date: Sat Aug 26 12:37:16 2023 -0500 create AutomationEngine class create food_automation method refactor food automations to use AutomationEngine
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
import json
|
|
import os
|
|
|
|
import pytest
|
|
from django.urls import reverse
|
|
|
|
from cookbook.tests.conftest import validate_recipe
|
|
|
|
from ._recipes import (ALLRECIPES, AMERICAS_TEST_KITCHEN, CHEF_KOCH, CHEF_KOCH2, COOKPAD,
|
|
COOKS_COUNTRY, DELISH, FOOD_NETWORK, GIALLOZAFFERANO, JOURNAL_DES_FEMMES,
|
|
MADAME_DESSERT, MARMITON, TASTE_OF_HOME, THE_SPRUCE_EATS, TUDOGOSTOSO)
|
|
|
|
IMPORT_SOURCE_URL = 'api_recipe_from_source'
|
|
DATA_DIR = "cookbook/tests/other/test_data/"
|
|
|
|
|
|
# These were chosen arbitrarily from:
|
|
# Top 10 recipe websites listed here https://www.similarweb.com/top-websites/category/food-and-drink/cooking-and-recipes/
|
|
# plus the test that previously existed
|
|
# plus the custom scraper that was created
|
|
# plus any specific defects discovered along the way
|
|
|
|
|
|
@pytest.mark.parametrize("arg", [
|
|
['a_u', 403],
|
|
['g1_s1', 403],
|
|
['u1_s1', 405],
|
|
['a1_s1', 405],
|
|
])
|
|
def test_import_permission(arg, request):
|
|
c = request.getfixturevalue(arg[0])
|
|
assert c.get(reverse(IMPORT_SOURCE_URL)).status_code == arg[1]
|
|
|
|
|
|
@pytest.mark.parametrize("arg", [
|
|
ALLRECIPES,
|
|
# test of custom scraper ATK
|
|
AMERICAS_TEST_KITCHEN,
|
|
CHEF_KOCH,
|
|
# test for empty ingredient in ingredient_parser
|
|
CHEF_KOCH2,
|
|
COOKPAD,
|
|
# test of custom scraper ATK
|
|
COOKS_COUNTRY,
|
|
DELISH,
|
|
FOOD_NETWORK,
|
|
GIALLOZAFFERANO,
|
|
JOURNAL_DES_FEMMES,
|
|
# example of recipes_scraper in with wildmode
|
|
# example of json only source
|
|
MADAME_DESSERT,
|
|
MARMITON,
|
|
TASTE_OF_HOME,
|
|
# example of non-json recipes_scraper
|
|
THE_SPRUCE_EATS, # TODO seems to be broken in recipe scrapers
|
|
TUDOGOSTOSO,
|
|
])
|
|
def test_recipe_import(arg, u1_s1):
|
|
url = arg['url']
|
|
for f in list(arg['file']): # url and files get popped later
|
|
if 'cookbook' in os.getcwd():
|
|
test_file = os.path.join(os.getcwd(), 'other', 'test_data', f)
|
|
else:
|
|
test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', f)
|
|
with open(test_file, 'r', encoding='UTF-8') as d:
|
|
response = u1_s1.post(
|
|
reverse(IMPORT_SOURCE_URL),
|
|
{
|
|
'data': d.read(),
|
|
'url': url,
|
|
},
|
|
content_type='application/json')
|
|
recipe = json.loads(response.content)['recipe_json']
|
|
validate_recipe(arg, recipe)
|