Merge pull request #459 from smilerz/fix-456

Fix 456
This commit is contained in:
vabene1111
2021-02-25 08:14:55 +01:00
committed by GitHub
3 changed files with 26 additions and 4 deletions

View File

@@ -69,8 +69,10 @@ def find_recipe_json(ld_json, url):
if 'recipeIngredient' in ld_json:
# some pages have comma separated ingredients in a single array entry
if (len(ld_json['recipeIngredient']) == 1
and len(ld_json['recipeIngredient'][0]) > 30):
and type(ld_json['recipeIngredient']) == list):
ld_json['recipeIngredient'] = ld_json['recipeIngredient'][0].split(',') # noqa: E501
elif type(ld_json['recipeIngredient']) == str:
ld_json['recipeIngredient'] = ld_json['recipeIngredient'].split(',')
for x in ld_json['recipeIngredient']:
if '\n' in x:
@@ -223,6 +225,8 @@ def find_recipe_json(ld_json, url):
if 'recipeYield' in ld_json:
if type(ld_json['recipeYield']) == str:
ld_json['servings'] = int(re.findall(r'\b\d+\b', ld_json['recipeYield'])[0])
elif type(ld_json['recipeYield']) == list:
ld_json['servings'] = int(re.findall(r'\b\d+\b', ld_json['recipeYield'][0])[0])
except Exception as e:
print(e)

View File

@@ -4,7 +4,6 @@ from cookbook.models import Keyword
from cookbook.tests.views.test_views import TestViews
from django.urls import reverse
class TestApiKeyword(TestViews):
def setUp(self):
@@ -63,6 +62,26 @@ class TestApiKeyword(TestViews):
self.assertEqual(r.status_code, 200)
self.assertEqual(response['name'], 'new')
def test_keyword_add(self):
r = self.user_client_1.post(
reverse('api:keyword-list'),
{'name': 'test'},
content_type='application/json'
)
response = json.loads(r.content)
self.assertEqual(r.status_code, 201)
self.assertEqual(response['name'], 'test')
def test_keyword_add_duplicate(self):
r = self.user_client_1.post(
reverse('api:keyword-list'),
{'name': self.keyword_1.name},
content_type='application/json'
)
response = json.loads(r.content)
self.assertEqual(r.status_code, 201)
self.assertEqual(response['name'], {self.keyword_1.name})
def test_keyword_delete(self):
r = self.user_client_1.delete(
reverse(

View File

@@ -134,8 +134,7 @@ def import_url(request):
recipe.steps.add(step)
for kw in data['keywords']:
if kw['id'] != "null" \
and (k := Keyword.objects.filter(id=kw['id']).first()):
if k := Keyword.objects.filter(name=kw['text']).first():
recipe.keywords.add(k)
elif data['all_keywords']:
k = Keyword.objects.create(name=kw['text'])