ran and fixed tests
This commit is contained in:
parent
447ead59a9
commit
7b4123462d
@ -284,7 +284,9 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
|
||||
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
|
||||
|
||||
def create(self, validated_data):
|
||||
obj, created = Food.objects.get_or_create(name=validated_data['name'].strip(), space=self.context['request'].space)
|
||||
validated_data['name'] = validated_data['name'].strip()
|
||||
validated_data['space'] = self.context['request'].space
|
||||
obj, created = Food.objects.get_or_create(validated_data)
|
||||
return obj
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
@ -456,9 +458,11 @@ class RecipeBookEntrySerializer(serializers.ModelSerializer):
|
||||
|
||||
def create(self, validated_data):
|
||||
book = validated_data['book']
|
||||
recipe = validated_data['recipe']
|
||||
if not book.get_owner() == self.context['request'].user:
|
||||
raise NotFound(detail=None, code=None)
|
||||
return super().create(validated_data)
|
||||
obj, created = RecipeBookEntry.objects.get_or_create(book=book, recipe=recipe)
|
||||
return obj
|
||||
|
||||
class Meta:
|
||||
model = RecipeBookEntry
|
||||
|
@ -4,16 +4,16 @@ import pytest
|
||||
from django.urls import reverse
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Food, Ingredient, Step, Recipe
|
||||
from cookbook.models import Recipe
|
||||
|
||||
LIST_URL = 'api:recipe-list'
|
||||
DETAIL_URL = 'api:recipe-detail'
|
||||
|
||||
|
||||
# TODO need to add extensive tests against recipe search to go through all of the combinations of parameters
|
||||
# probably needs to include a far more extensive set of initial recipes to effectively test results
|
||||
# and to ensure that all parts of the code are exercised.
|
||||
# TODO should probably consider adding code coverage plugin to the test suite
|
||||
|
||||
@pytest.mark.parametrize("arg", [
|
||||
['a_u', 403],
|
||||
['g1_s1', 200],
|
||||
|
@ -11,7 +11,7 @@ LIST_URL = 'api:recipebookentry-list'
|
||||
DETAIL_URL = 'api:recipebookentry-detail'
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@pytest.fixture
|
||||
def obj_1(space_1, u1_s1, recipe_1_s1):
|
||||
b = RecipeBook.objects.create(name='test_1', created_by=auth.get_user(u1_s1), space=space_1)
|
||||
|
||||
@ -100,7 +100,7 @@ def test_add_duplicate(u1_s1, obj_1):
|
||||
{'book': obj_1.book.pk, 'recipe': obj_1.recipe.pk},
|
||||
content_type='application/json'
|
||||
)
|
||||
assert r.status_code == 400
|
||||
assert r.status_code == 201
|
||||
|
||||
|
||||
def test_delete(u1_s1, u1_s2, obj_1):
|
||||
|
@ -7,7 +7,7 @@ from django.contrib import auth
|
||||
from django.contrib.auth.models import User, Group
|
||||
from django_scopes import scopes_disabled
|
||||
|
||||
from cookbook.models import Space, Recipe, Step, Ingredient, Food, Unit, Storage
|
||||
from cookbook.models import Space, Recipe, Step, Ingredient, Food, Unit
|
||||
|
||||
|
||||
# hack from https://github.com/raphaelm/django-scopes to disable scopes for all fixtures
|
||||
|
@ -222,7 +222,7 @@ class TreeMixin(FuzzyFilterMixin):
|
||||
content = {'error': True, 'msg': _('Cannot merge with child object!')}
|
||||
return Response(content, status=status.HTTP_403_FORBIDDEN)
|
||||
########################################################################
|
||||
# this needs abstracted to update steps instead of recipes for food merge
|
||||
# TODO this needs abstracted to update steps instead of recipes for food merge
|
||||
########################################################################
|
||||
recipes = Recipe.objects.filter(**{"%ss" % self.basename: source}, space=self.request.space)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user