migrated space to ingredient, step and nutritional value

This commit is contained in:
vabene1111
2021-06-15 22:56:25 +02:00
parent b3504699b1
commit 018fcf27ea
6 changed files with 95 additions and 29 deletions

View File

@ -1,10 +1,11 @@
import json
import pytest
from django.db.models import Subquery, OuterRef
from django.urls import reverse
from django_scopes import scopes_disabled
from cookbook.models import Step
from cookbook.models import Step, Ingredient
LIST_URL = 'api:step-list'
DETAIL_URL = 'api:step-detail'
@ -28,6 +29,8 @@ def test_list_space(recipe_1_s1, u1_s1, u1_s2, space_2):
with scopes_disabled():
recipe_1_s1.space = space_2
recipe_1_s1.save()
Step.objects.update(space=Subquery(Step.objects.filter(pk=OuterRef('pk')).values('recipe__space')[:1]))
Ingredient.objects.update(space=Subquery(Ingredient.objects.filter(pk=OuterRef('pk')).values('step__recipe__space')[:1]))
assert len(json.loads(u1_s1.get(reverse(LIST_URL)).content)) == 0
assert len(json.loads(u1_s2.get(reverse(LIST_URL)).content)) == 2