stub out receip search tests

This commit is contained in:
smilerz
2022-02-08 20:23:49 -06:00
parent 924ffc473b
commit c2961eede4
6 changed files with 112 additions and 15 deletions

View File

@@ -129,6 +129,39 @@ class FoodFactory(factory.django.DjangoModelFactory):
django_get_or_create = ('name', 'space',)
@register
class RecipeBookEntryFactory(factory.django.DjangoModelFactory):
"""RecipeBookEntry factory."""
book = None
recipe = None
class Meta:
model = 'cookbook.RecipeBookEntry'
@register
class RecipeBookFactory(factory.django.DjangoModelFactory):
"""RecipeBook factory."""
name = factory.LazyAttribute(lambda x: faker.sentence(nb_words=2, variable_nb_words=False))
# icon = models.CharField(max_length=16, blank=True, null=True)
description = factory.LazyAttribute(lambda x: faker.sentence(nb_words=10))
created_by = factory.SubFactory(UserFactory, space=factory.SelfAttribute('..space'))
space = factory.SubFactory(SpaceFactory)
recipe = None # used to add to RecipeBookEntry
recipe_book_entry = factory.RelatedFactory(
RecipeBookEntryFactory,
factory_related_name='book',
recipe=factory.LazyAttribute(lambda x: x.recipe),
)
class Params:
recipe = None
class Meta:
model = 'cookbook.RecipeBook'
django_get_or_create = ('name', 'space',)
@register
class UnitFactory(factory.django.DjangoModelFactory):
"""Unit factory."""

View File

@@ -1,10 +1,8 @@
import json
import pytest
from django.contrib import auth
from django.urls import reverse
from django_scopes import scope
from pytest_factoryboy import LazyFixture, register
from cookbook.helper.recipe_search import RecipeSearch
from cookbook.models import Food, Recipe

View File

@@ -1,14 +1,10 @@
import json
import pytest
from django.contrib import auth
from django.urls import reverse
from django_scopes import scope, scopes_disabled
from pytest_factoryboy import LazyFixture, register
from cookbook.models import Food, FoodInheritField, Ingredient, ShoppingList, ShoppingListEntry
from cookbook.tests.factories import (FoodFactory, IngredientFactory, ShoppingListEntryFactory,
SupermarketCategoryFactory)
from cookbook.models import Food, Recipe
from cookbook.tests.factories import FoodFactory, RecipeBookEntryFactory, RecipeFactory
# TODO food/keyword/book test or, and, or_not, and_not search
# TODO recipe name/description/instructions/keyword/book/food test search with icontains, istarts with/ full text(?? probably when word changes based on conjugation??), trigram, unaccent
@@ -25,3 +21,60 @@ from cookbook.tests.factories import (FoodFactory, IngredientFactory, ShoppingLi
# TODO test loading custom filter with overrided params
# TODO makenow with above filters
# TODO test search for number of times cooked (self vs others)
LIST_URL = 'api:recipe-list'
@pytest.fixture
def accent():
return "àèìòù"
@pytest.fixture
def unaccent():
return "aeiou"
@pytest.fixture
def recipes(space_1):
return RecipeFactory.create_batch(10, space=space_1)
@pytest.fixture
def found_recipe(request, space_1, accent, unaccent):
recipe1 = RecipeFactory.create(space=space_1)
recipe2 = RecipeFactory.create(space=space_1)
recipe3 = RecipeFactory.create(space=space_1)
related = request.param.get('related', None)
# name = request.getfixturevalue(request.param.get('name', "unaccent"))
if related == 'food':
obj1 = Food.objects.filter(ingredient__step__recipe=recipe.id).first()
obj2 = Food.objects.filter(ingredient__step__recipe=recipe.id).last()
obj1.name = unaccent
obj1.save()
obj2.name = accent
obj2.save()
elif related == 'keyword':
obj1 = recipe.keywords.first()
obj2 = recipe.keywords.last()
obj1.name = unaccent
obj1.save()
obj2.name = accent
obj2.save()
elif related == 'book':
obj1 = RecipeBookEntryFactory.create(recipe=recipe)
return (recipe1, recipe2, recipe3, obj1, obj2)
@pytest.mark.parametrize("found_recipe, param_type", [
({'related': 'food'}, 'foods'),
({'related': 'keyword'}, 'keywords'),
({'related': 'book'}, 'books'),
], indirect=['found_recipe'])
@pytest.mark.parametrize('operator', ['_or', '_and', ])
def test_search_lists(found_recipe, param_type, operator, recipes, u1_s1, space_1):
with scope(space=space_1):
assert 1 == 2
pass
assert u1_s1.get(reverse(LIST_URL) + f'?parm={share.uuid}')