food_alias tests added
This commit is contained in:
parent
a820b9c09e
commit
52eb876a08
@ -2,10 +2,10 @@ from django.core.cache import caches
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Lower
|
||||||
|
|
||||||
from cookbook.models import Automation, Food, Ingredient, Unit
|
from cookbook.models import Automation
|
||||||
|
|
||||||
|
|
||||||
class AutomationEngine():
|
class AutomationEngine:
|
||||||
request = None
|
request = None
|
||||||
use_cache = None
|
use_cache = None
|
||||||
food_aliases = None
|
food_aliases = None
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from django.contrib import auth
|
from django.contrib import auth
|
||||||
from django.urls import reverse
|
from django.test import RequestFactory
|
||||||
from django_scopes import scope, scopes_disabled
|
from django_scopes import scope
|
||||||
|
|
||||||
from cookbook.forms import ImportExportBase
|
from cookbook.helper.automation_helper import AutomationEngine
|
||||||
from cookbook.helper.ingredient_parser import IngredientParser
|
from cookbook.models import Automation
|
||||||
from cookbook.helper.recipe_search import RecipeSearch
|
|
||||||
from cookbook.models import Automation, ExportLog, Food, Recipe
|
|
||||||
from cookbook.tests.conftest import validate_recipe
|
|
||||||
from cookbook.tests.factories import FoodFactory, RecipeFactory
|
|
||||||
|
|
||||||
IMPORT_SOURCE_URL = 'api_recipe_from_source'
|
|
||||||
|
|
||||||
# TODO test case sensitive match, assert update value
|
# TODO test case sensitive match, assert update value
|
||||||
# TODO test case insensitive match, assert update value
|
# TODO test case insensitive match, assert update value
|
||||||
@ -21,73 +12,89 @@ IMPORT_SOURCE_URL = 'api_recipe_from_source'
|
|||||||
# TODO test accent insensitive match, assert not update value
|
# TODO test accent insensitive match, assert not update value
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
# @pytest.fixture()
|
||||||
def obj_1(space_1, u1_s1):
|
# def automation_food(space_1):
|
||||||
return ExportLog.objects.create(type=ImportExportBase.DEFAULT, running=False, created_by=auth.get_user(u1_s1), space=space_1, exported_recipes=10, total_recipes=10)
|
# return Keyword.objects.get_or_create(name='test_1', space=space_1)[0]
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("arg", [
|
@pytest.mark.parametrize("arg", [
|
||||||
['a_u', 302],
|
['Match', True],
|
||||||
['g1_s1', 302],
|
['mAtCh', True],
|
||||||
['u1_s1', 200],
|
['No Match', False],
|
||||||
['a1_s1', 200],
|
['Màtch', False],
|
||||||
['u1_s2', 404],
|
|
||||||
['a1_s2', 404],
|
|
||||||
])
|
])
|
||||||
def test_keyword_automation():
|
def test_food_automation(u1_s1, arg):
|
||||||
assert True == True
|
target_name = "Matched Automation"
|
||||||
|
user = auth.get_user(u1_s1)
|
||||||
|
space = user.userspace_set.first().space
|
||||||
|
request = RequestFactory()
|
||||||
|
request.user = user
|
||||||
|
request.space = space
|
||||||
|
automation = AutomationEngine(request, False)
|
||||||
|
|
||||||
|
with scope(space=space):
|
||||||
|
Automation.objects.get_or_create(name='food test', type=Automation.FOOD_ALIAS, param_1=arg[0], param_2=target_name, created_by=user, space=space)
|
||||||
|
assert (automation.apply_food_automation(arg[0]) == target_name) is True
|
||||||
|
|
||||||
|
|
||||||
def test_unit_automation():
|
# @pytest.mark.parametrize("arg", [
|
||||||
assert True == True
|
# ['a_u', 302],
|
||||||
|
# ['g1_s1', 302],
|
||||||
|
# ['u1_s1', 200],
|
||||||
|
# ['a1_s1', 200],
|
||||||
|
# ['u1_s2', 404],
|
||||||
|
# ['a1_s2', 404],
|
||||||
|
# ])
|
||||||
|
# def test_keyword_automation(request, u1_s1):
|
||||||
|
# assert True == True
|
||||||
|
|
||||||
|
|
||||||
def test_food_automation():
|
# def test_unit_automation():
|
||||||
assert True == True
|
# assert True == True
|
||||||
|
|
||||||
|
|
||||||
def test_description_replace_automation():
|
# def test_description_replace_automation():
|
||||||
assert True == True
|
# assert True == True
|
||||||
|
|
||||||
|
|
||||||
def test_instruction_replace_automation():
|
# def test_instruction_replace_automation():
|
||||||
assert True == True
|
# assert True == True
|
||||||
|
|
||||||
|
|
||||||
def test_never_unit_automation():
|
# def test_never_unit_automation():
|
||||||
assert True == True
|
# assert True == True
|
||||||
|
|
||||||
|
|
||||||
def test_transpose_automation():
|
# def test_transpose_automation():
|
||||||
assert True == True
|
# assert True == True
|
||||||
# for some reason this tests cant run due to some kind of encoding issue, needs to be fixed
|
# # for some reason this tests cant run due to some kind of encoding issue, needs to be fixed
|
||||||
# def test_description_replace_automation(u1_s1, space_1):
|
# # def test_description_replace_automation(u1_s1, space_1):
|
||||||
# if 'cookbook' in os.getcwd():
|
# # if 'cookbook' in os.getcwd():
|
||||||
# test_file = os.path.join(os.getcwd(), 'other', 'test_data', 'chefkoch2.html')
|
# # test_file = os.path.join(os.getcwd(), 'other', 'test_data', 'chefkoch2.html')
|
||||||
# else:
|
# # else:
|
||||||
# test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', 'chefkoch2.html')
|
# # test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', 'chefkoch2.html')
|
||||||
#
|
# #
|
||||||
# # original description
|
# # # original description
|
||||||
# # Brokkoli - Bratlinge. Über 91 Bewertungen und für vorzüglich befunden. Mit ► Portionsrechner ► Kochbuch ► Video-Tipps! Jetzt entdecken und ausprobieren!
|
# # # Brokkoli - Bratlinge. Über 91 Bewertungen und für vorzüglich befunden. Mit ► Portionsrechner ► Kochbuch ► Video-Tipps! Jetzt entdecken und ausprobieren!
|
||||||
#
|
# #
|
||||||
# with scopes_disabled():
|
# # with scopes_disabled():
|
||||||
# Automation.objects.create(
|
# # Automation.objects.create(
|
||||||
# name='test1',
|
# # name='test1',
|
||||||
# created_by=auth.get_user(u1_s1),
|
# # created_by=auth.get_user(u1_s1),
|
||||||
# space=space_1,
|
# # space=space_1,
|
||||||
# param_1='.*',
|
# # param_1='.*',
|
||||||
# param_2='.*',
|
# # param_2='.*',
|
||||||
# param_3='',
|
# # param_3='',
|
||||||
# order=1000,
|
# # order=1000,
|
||||||
# )
|
# # )
|
||||||
#
|
# #
|
||||||
# with open(test_file, 'r', encoding='UTF-8') as d:
|
# # with open(test_file, 'r', encoding='UTF-8') as d:
|
||||||
# response = u1_s1.post(
|
# # response = u1_s1.post(
|
||||||
# reverse(IMPORT_SOURCE_URL),
|
# # reverse(IMPORT_SOURCE_URL),
|
||||||
# {
|
# # {
|
||||||
# 'data': d.read(),
|
# # 'data': d.read(),
|
||||||
# 'url': 'https://www.chefkoch.de/rezepte/804871184310070/Brokkoli-Bratlinge.html',
|
# # 'url': 'https://www.chefkoch.de/rezepte/804871184310070/Brokkoli-Bratlinge.html',
|
||||||
# },
|
# # },
|
||||||
# content_type='application/json')
|
# # content_type='application/json')
|
||||||
# recipe = json.loads(response.content)['recipe_json']
|
# # recipe = json.loads(response.content)['recipe_json']
|
||||||
# assert recipe['description'] == ''
|
# # assert recipe['description'] == ''
|
||||||
|
Loading…
Reference in New Issue
Block a user