ran and fixed tests

This commit is contained in:
smilerz 2021-08-13 15:22:22 -05:00
parent 447ead59a9
commit 7b4123462d
5 changed files with 12 additions and 8 deletions

View File

@ -284,7 +284,9 @@ class FoodSerializer(UniqueFieldsMixin, WritableNestedModelSerializer):
supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False) supermarket_category = SupermarketCategorySerializer(allow_null=True, required=False)
def create(self, validated_data): 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 return obj
def update(self, instance, validated_data): def update(self, instance, validated_data):
@ -456,9 +458,11 @@ class RecipeBookEntrySerializer(serializers.ModelSerializer):
def create(self, validated_data): def create(self, validated_data):
book = validated_data['book'] book = validated_data['book']
recipe = validated_data['recipe']
if not book.get_owner() == self.context['request'].user: if not book.get_owner() == self.context['request'].user:
raise NotFound(detail=None, code=None) 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: class Meta:
model = RecipeBookEntry model = RecipeBookEntry

View File

@ -4,16 +4,16 @@ import pytest
from django.urls import reverse from django.urls import reverse
from django_scopes import scopes_disabled from django_scopes import scopes_disabled
from cookbook.models import Food, Ingredient, Step, Recipe from cookbook.models import Recipe
LIST_URL = 'api:recipe-list' LIST_URL = 'api:recipe-list'
DETAIL_URL = 'api:recipe-detail' DETAIL_URL = 'api:recipe-detail'
# TODO need to add extensive tests against recipe search to go through all of the combinations of parameters # 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 # 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. # and to ensure that all parts of the code are exercised.
# TODO should probably consider adding code coverage plugin to the test suite # TODO should probably consider adding code coverage plugin to the test suite
@pytest.mark.parametrize("arg", [ @pytest.mark.parametrize("arg", [
['a_u', 403], ['a_u', 403],
['g1_s1', 200], ['g1_s1', 200],

View File

@ -11,7 +11,7 @@ LIST_URL = 'api:recipebookentry-list'
DETAIL_URL = 'api:recipebookentry-detail' DETAIL_URL = 'api:recipebookentry-detail'
@pytest.fixture() @pytest.fixture
def obj_1(space_1, u1_s1, recipe_1_s1): 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) 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}, {'book': obj_1.book.pk, 'recipe': obj_1.recipe.pk},
content_type='application/json' content_type='application/json'
) )
assert r.status_code == 400 assert r.status_code == 201
def test_delete(u1_s1, u1_s2, obj_1): def test_delete(u1_s1, u1_s2, obj_1):

View File

@ -7,7 +7,7 @@ from django.contrib import auth
from django.contrib.auth.models import User, Group from django.contrib.auth.models import User, Group
from django_scopes import scopes_disabled 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 # hack from https://github.com/raphaelm/django-scopes to disable scopes for all fixtures

View File

@ -222,7 +222,7 @@ class TreeMixin(FuzzyFilterMixin):
content = {'error': True, 'msg': _('Cannot merge with child object!')} content = {'error': True, 'msg': _('Cannot merge with child object!')}
return Response(content, status=status.HTTP_403_FORBIDDEN) 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) recipes = Recipe.objects.filter(**{"%ss" % self.basename: source}, space=self.request.space)