removed case insensitive get_or_create for units

This commit is contained in:
smilerz
2022-02-17 12:49:41 -06:00
parent 1c18c8faac
commit 6b5a099ba0
3 changed files with 43 additions and 28 deletions

View File

@ -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):

View File

@ -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", [

View File

@ -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))