mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2025-12-24 02:39:20 -05:00
more tests
This commit is contained in:
2
.idea/recipes.iml
generated
2
.idea/recipes.iml
generated
@@ -14,7 +14,7 @@
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/cookbook/tests/pytest/resources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/staticfiles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
from cookbook.models import Food, Recipe, Storage, Unit
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class TestEditsRecipe(TestViews):
|
||||
|
||||
def test_switch_recipe(self):
|
||||
internal_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=True,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
external_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=False,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
url = reverse('edit_recipe', args=[internal_recipe.pk])
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.user_client_1.get(r.url)
|
||||
self.assertTemplateUsed(r, 'forms/edit_internal_recipe.html')
|
||||
|
||||
url = reverse('edit_recipe', args=[external_recipe.pk])
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.user_client_1.get(r.url)
|
||||
self.assertTemplateUsed(r, 'generic/edit_template.html')
|
||||
|
||||
def test_convert_recipe(self):
|
||||
url = reverse('edit_convert_recipe', args=[42])
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 404)
|
||||
|
||||
external_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=False,
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
url = reverse('edit_convert_recipe', args=[external_recipe.pk])
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
recipe = Recipe.objects.get(pk=external_recipe.pk)
|
||||
self.assertTrue(recipe.internal)
|
||||
|
||||
url = reverse('edit_convert_recipe', args=[recipe.pk])
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
def test_internal_recipe_update(self):
|
||||
recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
created_by=auth.get_user(self.user_client_1)
|
||||
)
|
||||
|
||||
url = reverse('api:recipe-detail', args=[recipe.pk])
|
||||
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 403)
|
||||
|
||||
r = self.user_client_1.put(
|
||||
url,
|
||||
{
|
||||
'name': 'Changed',
|
||||
'working_time': 15,
|
||||
'waiting_time': 15,
|
||||
'keywords': [],
|
||||
'steps': []
|
||||
},
|
||||
content_type='application/json'
|
||||
)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
recipe = Recipe.objects.get(pk=recipe.pk)
|
||||
self.assertEqual('Changed', recipe.name)
|
||||
|
||||
Food.objects.create(name='Egg')
|
||||
Unit.objects.create(name='g')
|
||||
|
||||
r = self.user_client_1.put(
|
||||
url,
|
||||
{
|
||||
'name': 'Changed',
|
||||
'working_time': 15,
|
||||
'waiting_time': 15,
|
||||
'keywords': [],
|
||||
'steps': [
|
||||
{
|
||||
'ingredients': [
|
||||
{
|
||||
'food': {'name': 'test food'},
|
||||
'unit': {'name': 'test unit'},
|
||||
'amount': 12, 'note': 'test note'
|
||||
},
|
||||
{
|
||||
'food': {'name': 'test food 2'},
|
||||
'unit': {'name': 'test unit 2'},
|
||||
'amount': 42, 'note': 'test note 2'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
content_type='application/json'
|
||||
)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(2, recipe.steps.first().ingredients.count())
|
||||
|
||||
with open('cookbook/tests/resources/image.jpg', 'rb') as file: # noqa: E501,F841
|
||||
pass # TODO new image tests
|
||||
|
||||
with open('cookbook/tests/resources/image.png', 'rb') as file: # noqa: E501,F841
|
||||
pass # TODO new image tests
|
||||
|
||||
def test_external_recipe_update(self):
|
||||
storage = Storage.objects.create(
|
||||
name='TestStorage',
|
||||
method=Storage.DROPBOX,
|
||||
created_by=auth.get_user(self.user_client_1),
|
||||
token='test',
|
||||
username='test',
|
||||
password='test',
|
||||
)
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
created_by=auth.get_user(self.user_client_1),
|
||||
storage=storage,
|
||||
)
|
||||
|
||||
url = reverse('edit_external_recipe', args=[recipe.pk])
|
||||
|
||||
r = self.user_client_1.get(url)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
|
||||
r = self.anonymous_client.get(url)
|
||||
self.assertEqual(r.status_code, 302)
|
||||
|
||||
r = self.user_client_1.post(
|
||||
url,
|
||||
{'name': 'Test', 'working_time': 15, 'waiting_time': 15, 'servings': 1, }
|
||||
)
|
||||
recipe.refresh_from_db()
|
||||
self.assertEqual(recipe.working_time, 15)
|
||||
self.assertEqual(recipe.waiting_time, 15)
|
||||
@@ -1,94 +0,0 @@
|
||||
import json
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
from cookbook.tests.test_setup import TestBase
|
||||
|
||||
|
||||
class TestEditsRecipe(TestBase):
|
||||
|
||||
# flake8: noqa
|
||||
def test_ld_json(self):
|
||||
test_list = [
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_1.html', 'result_length': 3237},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_2.html', 'result_length': 1525},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_3.html', 'result_length': 1644},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_4.html', 'result_length': 1744},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_itemList.html', 'result_length': 3222},
|
||||
{'file': 'cookbook/tests/resources/websites/ld_json_multiple.html', 'result_length': 1621},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_1.html', 'result_length': 1094},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_2.html', 'result_length': 1453},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_3.html', 'result_length': 1163},
|
||||
{'file': 'cookbook/tests/resources/websites/micro_data_4.html', 'result_length': 4411},
|
||||
]
|
||||
|
||||
for test in test_list:
|
||||
with open(test['file'], 'rb') as file:
|
||||
print(f'Testing {test["file"]} expecting length {test["result_length"]}')
|
||||
parsed_content = json.loads(get_from_html(file.read(), 'test_url', None).content)
|
||||
self.assertEqual(len(str(parsed_content)), test['result_length'])
|
||||
file.close()
|
||||
|
||||
def test_ingredient_parser(self):
|
||||
expectations = {
|
||||
"2¼ l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"2¼l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"¼ l Wasser": (0.25, "l", "Wasser", ""),
|
||||
"3l Wasser": (3, "l", "Wasser", ""),
|
||||
"4 l Wasser": (4, "l", "Wasser", ""),
|
||||
"½l Wasser": (0.5, "l", "Wasser", ""),
|
||||
"⅛ Liter Sauerrahm": (0.125, "Liter", "Sauerrahm", ""),
|
||||
"5 Zwiebeln": (5, "", "Zwiebeln", ""),
|
||||
"3 Zwiebeln, gehackt": (3, "", "Zwiebeln", "gehackt"),
|
||||
"5 Zwiebeln (gehackt)": (5, "", "Zwiebeln", "gehackt"),
|
||||
"1 Zwiebel(n)": (1, "", "Zwiebel(n)", ""),
|
||||
"4 1/2 Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"4 ½ Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"1/2 EL Mehl": (0.5, "EL", "Mehl", ""),
|
||||
"1/2 Zwiebel": (0.5, "", "Zwiebel", ""),
|
||||
"1/5g Mehl, gesiebt": (0.2, "g", "Mehl", "gesiebt"),
|
||||
"1/2 Zitrone, ausgepresst": (0.5, "", "Zitrone", "ausgepresst"),
|
||||
"etwas Mehl": (0, "", "etwas Mehl", ""),
|
||||
"Öl zum Anbraten": (0, "", "Öl zum Anbraten", ""),
|
||||
"n. B. Knoblauch, zerdrückt": (0, "", "n. B. Knoblauch", "zerdrückt"),
|
||||
"Kräuter, mediterrane (Oregano, Rosmarin, Basilikum)": (
|
||||
0, "", "Kräuter, mediterrane", "Oregano, Rosmarin, Basilikum"),
|
||||
"600 g Kürbisfleisch (Hokkaido), geschält, entkernt und geraspelt": (
|
||||
600, "g", "Kürbisfleisch (Hokkaido)", "geschält, entkernt und geraspelt"),
|
||||
"Muskat": (0, "", "Muskat", ""),
|
||||
"200 g Mehl, glattes": (200, "g", "Mehl", "glattes"),
|
||||
"1 Ei(er)": (1, "", "Ei(er)", ""),
|
||||
"1 Prise(n) Salz": (1, "Prise(n)", "Salz", ""),
|
||||
"etwas Wasser, lauwarmes": (0, "", "etwas Wasser", "lauwarmes"),
|
||||
"Strudelblätter, fertige, für zwei Strudel": (0, "", "Strudelblätter", "fertige, für zwei Strudel"),
|
||||
"barrel-aged Bourbon": (0, "", "barrel-aged Bourbon", ""),
|
||||
"golden syrup": (0, "", "golden syrup", ""),
|
||||
"unsalted butter, for greasing": (0, "", "unsalted butter", "for greasing"),
|
||||
"unsalted butter , for greasing": (0, "", "unsalted butter", "for greasing"), # trim
|
||||
"1 small sprig of fresh rosemary": (1, "small", "sprig of fresh rosemary", ""),
|
||||
# does not always work perfectly!
|
||||
"75 g fresh breadcrumbs": (75, "g", "fresh breadcrumbs", ""),
|
||||
"4 acorn squash , or onion squash (600-800g)": (4, "acorn", "squash , or onion squash", "600-800g"),
|
||||
"1 x 250 g packet of cooked mixed grains , such as spelt and wild rice": (
|
||||
1, "x", "250 g packet of cooked mixed grains", "such as spelt and wild rice"),
|
||||
"1 big bunch of fresh mint , (60g)": (1, "big", "bunch of fresh mint ,", "60g"),
|
||||
"1 large red onion": (1, "large", "red onion", ""),
|
||||
# "2-3 TL Curry": (), # idk what it should use here either
|
||||
"1 Zwiebel gehackt": (1, "Zwiebel", "gehackt", ""),
|
||||
"1 EL Kokosöl": (1, "EL", "Kokosöl", ""),
|
||||
"0.5 paket jäst (à 50 g)": (0.5, "paket", "jäst", "à 50 g"),
|
||||
"ägg": (0, "", "ägg", ""),
|
||||
"50 g smör eller margarin": (50, "g", "smör eller margarin", ""),
|
||||
"3,5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"3.5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"400 g Karotte(n)": (400, "g", "Karotte(n)", "")
|
||||
}
|
||||
# for German you could say that if an ingredient does not have
|
||||
# an amount # and it starts with a lowercase letter, then that
|
||||
# is a unit ("etwas", "evtl.") does not apply to English tho
|
||||
|
||||
count = 0
|
||||
for key, val in expectations.items():
|
||||
count += 1
|
||||
parsed = parse(key)
|
||||
self.assertEqual(val, parsed)
|
||||
@@ -47,7 +47,8 @@ def get_random_recipe(space_1, u1_s1):
|
||||
working_time=20,
|
||||
servings=4,
|
||||
created_by=auth.get_user(u1_s1),
|
||||
space=space_1
|
||||
space=space_1,
|
||||
internal=True,
|
||||
)
|
||||
|
||||
s1 = Step.objects.create(name=uuid.uuid4(), instruction=uuid.uuid4(), )
|
||||
|
||||
7
cookbook/tests/pytest/edits/__init__.py
Normal file
7
cookbook/tests/pytest/edits/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
||||
83
cookbook/tests/pytest/edits/test_edits_recipe.py
Normal file
83
cookbook/tests/pytest/edits/test_edits_recipe.py
Normal file
@@ -0,0 +1,83 @@
|
||||
from cookbook.models import Food, Recipe, Storage, Unit
|
||||
from cookbook.tests.views.test_views import TestViews
|
||||
from django.contrib import auth
|
||||
from django.urls import reverse
|
||||
from pytest_django.asserts import assertTemplateUsed
|
||||
|
||||
|
||||
def test_switch_recipe(u1_s1, recipe_1_s1, space_1):
|
||||
external_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=False,
|
||||
created_by=auth.get_user(u1_s1),
|
||||
space=space_1,
|
||||
)
|
||||
|
||||
url = reverse('edit_recipe', args=[recipe_1_s1.pk])
|
||||
r = u1_s1.get(url)
|
||||
assert r.status_code == 302
|
||||
|
||||
r = u1_s1.get(r.url)
|
||||
assertTemplateUsed(r, 'forms/edit_internal_recipe.html')
|
||||
|
||||
url = reverse('edit_recipe', args=[external_recipe.pk])
|
||||
r = u1_s1.get(url)
|
||||
assert r.status_code == 302
|
||||
|
||||
r = u1_s1.get(r.url)
|
||||
assertTemplateUsed(r, 'generic/edit_template.html')
|
||||
|
||||
|
||||
def test_convert_recipe(u1_s1, space_1):
|
||||
external_recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
internal=False,
|
||||
created_by=auth.get_user(u1_s1),
|
||||
space=space_1,
|
||||
)
|
||||
|
||||
r = u1_s1.get(reverse('edit_convert_recipe', args=[external_recipe.pk]))
|
||||
assert r.status_code == 302
|
||||
|
||||
external_recipe.refresh_from_db()
|
||||
assert external_recipe.internal
|
||||
|
||||
|
||||
def test_external_recipe_update(u1_s1, u1_s2, space_1):
|
||||
storage = Storage.objects.create(
|
||||
name='TestStorage',
|
||||
method=Storage.DROPBOX,
|
||||
created_by=auth.get_user(u1_s1),
|
||||
token='test',
|
||||
username='test',
|
||||
password='test',
|
||||
space=space_1,
|
||||
)
|
||||
|
||||
recipe = Recipe.objects.create(
|
||||
name='Test',
|
||||
created_by=auth.get_user(u1_s1),
|
||||
storage=storage,
|
||||
space=space_1,
|
||||
)
|
||||
|
||||
url = reverse('edit_external_recipe', args=[recipe.pk])
|
||||
|
||||
r = u1_s1.get(url)
|
||||
assert r.status_code == 200
|
||||
|
||||
u1_s2.post(
|
||||
url,
|
||||
{'name': 'Test', 'working_time': 15, 'waiting_time': 15, 'servings': 1, }
|
||||
)
|
||||
recipe.refresh_from_db()
|
||||
assert recipe.working_time == 0
|
||||
assert recipe.waiting_time == 0
|
||||
|
||||
u1_s1.post(
|
||||
url,
|
||||
{'name': 'Test', 'working_time': 15, 'waiting_time': 15, 'servings': 1, }
|
||||
)
|
||||
recipe.refresh_from_db()
|
||||
assert recipe.working_time == 15
|
||||
assert recipe.waiting_time == 15
|
||||
7
cookbook/tests/pytest/other/__init__.py
Normal file
7
cookbook/tests/pytest/other/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.test import utils
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
# disables scoping error in all queries used inside the test FUNCTIONS
|
||||
# FIXTURES need to have their own scopes_disabled!!
|
||||
# This is done by hook pytest_fixture_setup in conftest.py for all non yield fixtures
|
||||
utils.setup_databases = scopes_disabled()(utils.setup_databases)
|
||||
66
cookbook/tests/pytest/other/test_ingredient_parser.py
Normal file
66
cookbook/tests/pytest/other/test_ingredient_parser.py
Normal file
@@ -0,0 +1,66 @@
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
|
||||
|
||||
def test_ingredient_parser():
|
||||
expectations = {
|
||||
"2¼ l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"2¼l Wasser": (2.25, "l", "Wasser", ""),
|
||||
"¼ l Wasser": (0.25, "l", "Wasser", ""),
|
||||
"3l Wasser": (3, "l", "Wasser", ""),
|
||||
"4 l Wasser": (4, "l", "Wasser", ""),
|
||||
"½l Wasser": (0.5, "l", "Wasser", ""),
|
||||
"⅛ Liter Sauerrahm": (0.125, "Liter", "Sauerrahm", ""),
|
||||
"5 Zwiebeln": (5, "", "Zwiebeln", ""),
|
||||
"3 Zwiebeln, gehackt": (3, "", "Zwiebeln", "gehackt"),
|
||||
"5 Zwiebeln (gehackt)": (5, "", "Zwiebeln", "gehackt"),
|
||||
"1 Zwiebel(n)": (1, "", "Zwiebel(n)", ""),
|
||||
"4 1/2 Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"4 ½ Zwiebeln": (4.5, "", "Zwiebeln", ""),
|
||||
"1/2 EL Mehl": (0.5, "EL", "Mehl", ""),
|
||||
"1/2 Zwiebel": (0.5, "", "Zwiebel", ""),
|
||||
"1/5g Mehl, gesiebt": (0.2, "g", "Mehl", "gesiebt"),
|
||||
"1/2 Zitrone, ausgepresst": (0.5, "", "Zitrone", "ausgepresst"),
|
||||
"etwas Mehl": (0, "", "etwas Mehl", ""),
|
||||
"Öl zum Anbraten": (0, "", "Öl zum Anbraten", ""),
|
||||
"n. B. Knoblauch, zerdrückt": (0, "", "n. B. Knoblauch", "zerdrückt"),
|
||||
"Kräuter, mediterrane (Oregano, Rosmarin, Basilikum)": (
|
||||
0, "", "Kräuter, mediterrane", "Oregano, Rosmarin, Basilikum"),
|
||||
"600 g Kürbisfleisch (Hokkaido), geschält, entkernt und geraspelt": (
|
||||
600, "g", "Kürbisfleisch (Hokkaido)", "geschält, entkernt und geraspelt"),
|
||||
"Muskat": (0, "", "Muskat", ""),
|
||||
"200 g Mehl, glattes": (200, "g", "Mehl", "glattes"),
|
||||
"1 Ei(er)": (1, "", "Ei(er)", ""),
|
||||
"1 Prise(n) Salz": (1, "Prise(n)", "Salz", ""),
|
||||
"etwas Wasser, lauwarmes": (0, "", "etwas Wasser", "lauwarmes"),
|
||||
"Strudelblätter, fertige, für zwei Strudel": (0, "", "Strudelblätter", "fertige, für zwei Strudel"),
|
||||
"barrel-aged Bourbon": (0, "", "barrel-aged Bourbon", ""),
|
||||
"golden syrup": (0, "", "golden syrup", ""),
|
||||
"unsalted butter, for greasing": (0, "", "unsalted butter", "for greasing"),
|
||||
"unsalted butter , for greasing": (0, "", "unsalted butter", "for greasing"), # trim
|
||||
"1 small sprig of fresh rosemary": (1, "small", "sprig of fresh rosemary", ""),
|
||||
# does not always work perfectly!
|
||||
"75 g fresh breadcrumbs": (75, "g", "fresh breadcrumbs", ""),
|
||||
"4 acorn squash , or onion squash (600-800g)": (4, "acorn", "squash , or onion squash", "600-800g"),
|
||||
"1 x 250 g packet of cooked mixed grains , such as spelt and wild rice": (
|
||||
1, "x", "250 g packet of cooked mixed grains", "such as spelt and wild rice"),
|
||||
"1 big bunch of fresh mint , (60g)": (1, "big", "bunch of fresh mint ,", "60g"),
|
||||
"1 large red onion": (1, "large", "red onion", ""),
|
||||
# "2-3 TL Curry": (), # idk what it should use here either
|
||||
"1 Zwiebel gehackt": (1, "Zwiebel", "gehackt", ""),
|
||||
"1 EL Kokosöl": (1, "EL", "Kokosöl", ""),
|
||||
"0.5 paket jäst (à 50 g)": (0.5, "paket", "jäst", "à 50 g"),
|
||||
"ägg": (0, "", "ägg", ""),
|
||||
"50 g smör eller margarin": (50, "g", "smör eller margarin", ""),
|
||||
"3,5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"3.5 l Wasser": (3.5, "l", "Wasser", ""),
|
||||
"400 g Karotte(n)": (400, "g", "Karotte(n)", "")
|
||||
}
|
||||
# for German you could say that if an ingredient does not have
|
||||
# an amount # and it starts with a lowercase letter, then that
|
||||
# is a unit ("etwas", "evtl.") does not apply to English tho
|
||||
|
||||
count = 0
|
||||
for key, val in expectations.items():
|
||||
count += 1
|
||||
parsed = parse(key)
|
||||
assert val == parsed
|
||||
30
cookbook/tests/pytest/other/test_url_import.py
Normal file
30
cookbook/tests/pytest/other/test_url_import.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import json
|
||||
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.helper.ingredient_parser import parse
|
||||
from cookbook.helper.recipe_url_import import get_from_html
|
||||
from cookbook.tests.test_setup import TestBase
|
||||
|
||||
|
||||
def test_ld_json():
|
||||
with scopes_disabled():
|
||||
test_list = [
|
||||
{'file': '../resources/websites/ld_json_1.html', 'result_length': 3237},
|
||||
{'file': '../resources/websites/ld_json_2.html', 'result_length': 1525},
|
||||
{'file': '../resources/websites/ld_json_3.html', 'result_length': 1644},
|
||||
{'file': '../resources/websites/ld_json_4.html', 'result_length': 1744},
|
||||
{'file': '../resources/websites/ld_json_itemList.html', 'result_length': 3222},
|
||||
{'file': '../resources/websites/ld_json_multiple.html', 'result_length': 1621},
|
||||
{'file': '../resources/websites/micro_data_1.html', 'result_length': 1094},
|
||||
{'file': '../resources/websites/micro_data_2.html', 'result_length': 1453},
|
||||
{'file': '../resources/websites/micro_data_3.html', 'result_length': 1163},
|
||||
{'file': '../resources/websites/micro_data_4.html', 'result_length': 4411},
|
||||
]
|
||||
|
||||
for test in test_list:
|
||||
with open(test['file'], 'rb') as file:
|
||||
print(f'Testing {test["file"]} expecting length {test["result_length"]}')
|
||||
parsed_content = json.loads(get_from_html(file.read(), 'test_url', None).content)
|
||||
assert len(str(parsed_content)) == test['result_length']
|
||||
file.close()
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
@@ -1,20 +0,0 @@
|
||||
import json
|
||||
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Keyword, Space
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_user_create(u1_s1,u1_s2):
|
||||
r = u1_s1.post(reverse('api:keyword-list'), {'name': 'test', 'space': 1}, content_type='application/json')
|
||||
response = json.loads(r.content)
|
||||
assert r.status_code == 201
|
||||
assert response['name'] == 'test'
|
||||
|
||||
r = u1_s2.get(reverse('api:keyword-detail', args={response['id']}), content_type='application/json')
|
||||
assert r.status_code == 404
|
||||
Reference in New Issue
Block a user