mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-03 21:37:49 -05:00
removed case insensitive get_or_create for units
This commit is contained in:
@@ -319,7 +319,7 @@ class UnitSerializer(UniqueFieldsMixin, ExtendedRecipeMixin):
|
|||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
name = validated_data.pop('name').strip()
|
name = validated_data.pop('name').strip()
|
||||||
space = validated_data.pop('space', self.context['request'].space)
|
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
|
return obj
|
||||||
|
|
||||||
def update(self, instance, validated_data):
|
def update(self, instance, validated_data):
|
||||||
|
|||||||
@@ -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)
|
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]
|
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")
|
# r = json.loads(user1[0].get(reverse(LIST_URL) + f'?{param1}').content)
|
||||||
@pytest.mark.parametrize("user1", itertools.product(
|
# assert len([x['id'] for x in r['results'] if x['id'] in [found_recipe[0].id, found_recipe[1].id]]) == user1[1]
|
||||||
[
|
|
||||||
('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)
|
# 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[1]
|
# 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", [
|
@pytest.mark.parametrize("found_recipe, param_type, result", [
|
||||||
|
|||||||
@@ -207,10 +207,24 @@ export default {
|
|||||||
},
|
},
|
||||||
copyToNew: function () {
|
copyToNew: function () {
|
||||||
let recipename = window.prompt(this.$t("copy_to_new"), this.$t("recipe_name"))
|
let recipename = window.prompt(this.$t("copy_to_new"), this.$t("recipe_name"))
|
||||||
|
|
||||||
let apiClient = new ApiApiFactory()
|
let apiClient = new ApiApiFactory()
|
||||||
apiClient.retrieveRecipe(this.recipe.id).then((results) => {
|
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
|
apiClient
|
||||||
.createRecipe({ ...results.data, ...{ id: undefined, name: recipename } })
|
.createRecipe(recipe)
|
||||||
.then((newrecipe) => {
|
.then((newrecipe) => {
|
||||||
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
|
StandardToasts.makeStandardToast(StandardToasts.SUCCESS_CREATE)
|
||||||
window.open(this.resolveDjangoUrl("view_recipe", newrecipe.data.id))
|
window.open(this.resolveDjangoUrl("view_recipe", newrecipe.data.id))
|
||||||
|
|||||||
Reference in New Issue
Block a user