From 6b59f532735026e09682c6550bcbc96ccd7d68c9 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 4 Jan 2023 17:27:15 +0100 Subject: [PATCH] test wip but not working --- cookbook/tests/other/test_automations.py | 49 ++++++++++++++++++++++++ cookbook/tests/other/test_url_import.py | 41 ++++++++++++++++---- 2 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 cookbook/tests/other/test_automations.py diff --git a/cookbook/tests/other/test_automations.py b/cookbook/tests/other/test_automations.py new file mode 100644 index 00000000..2a8e5d20 --- /dev/null +++ b/cookbook/tests/other/test_automations.py @@ -0,0 +1,49 @@ +import pytest +from django.contrib import auth +from django.urls import reverse +from django_scopes import scopes_disabled + +from cookbook.forms import ImportExportBase +from cookbook.helper.ingredient_parser import IngredientParser +from cookbook.models import ExportLog, Automation +import json +import os + +import pytest +from django.urls import reverse + +from cookbook.tests.conftest import validate_recipe + +IMPORT_SOURCE_URL = 'api_recipe_from_source' + + +def test_description_replace_automation(u1_s1, space_1): + if 'cookbook' in os.getcwd(): + test_file = os.path.join(os.getcwd(), 'other', 'test_data', 'chefkoch2.html') + else: + test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', 'chefkoch2.html') + + # original description + # Brokkoli - Bratlinge. Über 91 Bewertungen und für vorzüglich befunden. Mit ► Portionsrechner ► Kochbuch ► Video-Tipps! Jetzt entdecken und ausprobieren! + + with scopes_disabled(): + Automation.objects.create( + name='test1', + created_by=auth.get_user(u1_s1), + space=space_1, + param_1='.*', + param_2='.*', + param_3='', + order=1000, + ) + + with open(test_file, 'r', encoding='UTF-8') as d: + response = u1_s1.post( + reverse(IMPORT_SOURCE_URL), + { + 'data': d.read(), + 'url': 'https://www.chefkoch.de/rezepte/804871184310070/Brokkoli-Bratlinge.html', + }, + content_type='application/json') + recipe = json.loads(response.content)['recipe_json'] + assert recipe['description'] == '' diff --git a/cookbook/tests/other/test_url_import.py b/cookbook/tests/other/test_url_import.py index 394838dc..46075051 100644 --- a/cookbook/tests/other/test_url_import.py +++ b/cookbook/tests/other/test_url_import.py @@ -2,13 +2,16 @@ import json import os import pytest +from django.contrib import auth from django.urls import reverse +from django_scopes import scopes_disabled 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) +from ...models import Automation IMPORT_SOURCE_URL = 'api_recipe_from_source' DATA_DIR = "cookbook/tests/other/test_data/" @@ -74,11 +77,33 @@ def test_recipe_import(arg, u1_s1): validate_recipe(arg, recipe) -# def test_description_replace_automation(): -# if 'cookbook' in os.getcwd(): -# test_file = os.path.join(os.getcwd(), 'other', 'test_data', 'chefkoch2.html') -# else: -# test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', 'chefkoch2.html') -# -# with open(test_file, 'r', encoding='UTF-8') as d: -# pass \ No newline at end of file +def test_description_replace_automation(u1_s1, space_1): + if 'cookbook' in os.getcwd(): + test_file = os.path.join(os.getcwd(), 'other', 'test_data', 'chefkoch2.html') + else: + test_file = os.path.join(os.getcwd(), 'cookbook', 'tests', 'other', 'test_data', 'chefkoch2.html') + + # original description + # Brokkoli - Bratlinge. Über 91 Bewertungen und für vorzüglich befunden. Mit ► Portionsrechner ► Kochbuch ► Video-Tipps! Jetzt entdecken und ausprobieren! + + with scopes_disabled(): + Automation.objects.create( + name='test1', + created_by=auth.get_user(u1_s1), + space=space_1, + param_1='.*', + param_2='.*', + param_3='', + order=1000, + ) + + with open(test_file, 'r', encoding='UTF-8', errors='ignore') as d: + response = u1_s1.post( + reverse(IMPORT_SOURCE_URL), + { + 'data': d.read(), + 'url': 'https://www.chefkoch.de/rezepte/804871184310070/Brokkoli-Bratlinge.html', + }, + content_type='application/json') + recipe = json.loads(response.content)['recipe_json'] + assert recipe['description'] == ''