From 6b5a099ba02ba7eba4022be570234ccf700d2431 Mon Sep 17 00:00:00 2001 From: smilerz Date: Thu, 17 Feb 2022 12:49:41 -0600 Subject: [PATCH] removed case insensitive get_or_create for units --- cookbook/serializer.py | 2 +- .../other/test_recipe_full_text_search.py | 53 ++++++++++--------- vue/src/components/RecipeContextMenu.vue | 16 +++++- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index 9d1c76968..6ca4c4464 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -319,7 +319,7 @@ class UnitSerializer(UniqueFieldsMixin, ExtendedRecipeMixin): def create(self, validated_data): name = validated_data.pop('name').strip() space = validated_data.pop('space', self.context['request'].space) - obj, created = Unit.objects.get_or_create(name__iexact=name, space=space, defaults=validated_data) + obj, created = Unit.objects.get_or_create(name=name, space=space, defaults=validated_data) return obj def update(self, instance, validated_data): diff --git a/cookbook/tests/other/test_recipe_full_text_search.py b/cookbook/tests/other/test_recipe_full_text_search.py index 85d24b701..7e714007f 100644 --- a/cookbook/tests/other/test_recipe_full_text_search.py +++ b/cookbook/tests/other/test_recipe_full_text_search.py @@ -257,34 +257,35 @@ def test_fuzzy_lookup(found_recipe, recipes, param_type, user1, space_1): r = json.loads(user1[0].get(reverse(list_url) + f'?{param2}&limit=10').content) assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[3].id, found_recipe[4].id]]) == user1[2] +# commenting this out for general use - it is really slow +# it should be run on occasion to ensure everything still works +# @pytest.mark.skipif(sqlite and True, reason="requires PostgreSQL") +# @pytest.mark.parametrize("user1", itertools.product( +# [ +# ('fuzzy_search', True), ('fuzzy_search', False), +# ('fulltext', True), ('fulltext', False), +# ('icontains', True), ('icontains', False), +# ('istartswith', True), ('istartswith', False), +# ], +# [('unaccent', True), ('unaccent', False)] +# ), indirect=['user1']) +# @pytest.mark.parametrize("found_recipe", [ +# ({'name': True}), +# ({'description': True}), +# ({'instruction': True}), +# ({'keyword': True}), +# ({'food': True}), +# ], indirect=['found_recipe']) +# def test_search_string(found_recipe, recipes, user1, space_1): +# with scope(space=space_1): +# param1 = f"query={user1[3]}" +# param2 = f"query={user1[4]}" -@pytest.mark.skipif(sqlite, reason="requires PostgreSQL") -@pytest.mark.parametrize("user1", itertools.product( - [ - ('fuzzy_search', True), ('fuzzy_search', False), - ('fulltext', True), ('fulltext', False), - ('icontains', True), ('icontains', False), - ('istartswith', True), ('istartswith', False), - ], - [('unaccent', True), ('unaccent', False)] -), indirect=['user1']) -@pytest.mark.parametrize("found_recipe", [ - ({'name': True}), - ({'description': True}), - ({'instruction': True}), - ({'keyword': True}), - ({'food': True}), -], indirect=['found_recipe']) -def test_search_string(found_recipe, recipes, user1, space_1): - with scope(space=space_1): - param1 = f"query={user1[3]}" - param2 = f"query={user1[4]}" +# r = json.loads(user1[0].get(reverse(LIST_URL) + f'?{param1}').content) +# assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[0].id, found_recipe[1].id]]) == user1[1] - r = json.loads(user1[0].get(reverse(LIST_URL) + f'?{param1}').content) - assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[0].id, found_recipe[1].id]]) == user1[1] - - r = json.loads(user1[0].get(reverse(LIST_URL) + f'?{param2}').content) - assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[0].id, found_recipe[1].id]]) == user1[2] +# r = json.loads(user1[0].get(reverse(LIST_URL) + f'?{param2}').content) +# assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[0].id, found_recipe[1].id]]) == user1[2] @pytest.mark.parametrize("found_recipe, param_type, result", [ diff --git a/vue/src/components/RecipeContextMenu.vue b/vue/src/components/RecipeContextMenu.vue index a1c3d3640..32812eea8 100644 --- a/vue/src/components/RecipeContextMenu.vue +++ b/vue/src/components/RecipeContextMenu.vue @@ -207,10 +207,24 @@ export default { }, copyToNew: function () { let recipename = window.prompt(this.$t("copy_to_new"), this.$t("recipe_name")) + let apiClient = new ApiApiFactory() apiClient.retrieveRecipe(this.recipe.id).then((results) => { + let recipe = { ...results.data, ...{ id: undefined, name: recipename } } + recipe.steps = recipe.steps.map((step) => { + return { + ...step, + ...{ + id: undefined, + ingredients: step.ingredients.map((ingredient) => { + return { ...ingredient, ...{ id: undefined } } + }), + }, + } + }) + console.log(recipe) apiClient - .createRecipe({ ...results.data, ...{ id: undefined, name: recipename } }) + .createRecipe(recipe) .then((newrecipe) => { StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE) window.open(this.resolveDjangoUrl("view_recipe", newrecipe.data.id))