コード例 #1
0
def test_makenow_sibling_substitute(recipes, makenow_recipe, user1, space_1):
    request = type('', (object, ), {'space': space_1, 'user': user1})()
    search = RecipeSearch(request, makenow='true')
    with scope(space=space_1):
        food = Food.objects.filter(
            ingredient__step__recipe=makenow_recipe.id).first()
        onhand_user = food.onhand_users.first()
        food.onhand_users.clear()
        food.substitute_siblings = True
        food.save()
        assert search.get_queryset(Recipe.objects.all()).count() == 0
        new_parent = FoodFactory.create(space=space_1)
        new_sibling = FoodFactory.create(space=space_1,
                                         onhand_users=[onhand_user])
        new_sibling.move(new_parent, 'first-child')
        food.move(new_parent, 'first-child')
        assert Food.objects.filter(ingredient__step__recipe=makenow_recipe.id,
                                   onhand_users__isnull=False).count() == 9
        assert Food.objects.filter(ingredient__step__recipe=makenow_recipe.id,
                                   depth=2).count() == 1
        search = search.get_queryset(Recipe.objects.all())
    assert search.count() == 1
    assert search.first().id == makenow_recipe.id
コード例 #2
0
def test_makenow_substitute(recipes, makenow_recipe, user1, space_1):
    request = type('', (object, ), {'space': space_1, 'user': user1})()
    search = RecipeSearch(request, makenow='true')
    with scope(space=space_1):
        food = Food.objects.filter(
            ingredient__step__recipe=makenow_recipe.id).first()
        onhand_user = food.onhand_users.first()
        food.onhand_users.clear()
        assert search.get_queryset(Recipe.objects.all()).count() == 0
        food.substitute.add(
            FoodFactory.create(space=space_1, onhand_users=[onhand_user]))
        assert Food.objects.filter(ingredient__step__recipe=makenow_recipe.id,
                                   onhand_users__isnull=False).count() == 9
        assert Food.objects.filter(ingredient__step__recipe=makenow_recipe.id,
                                   substitute__isnull=False).count() == 1

        search = search.get_queryset(Recipe.objects.all())
    assert search.count() == 1
    assert search.first().id == makenow_recipe.id
コード例 #3
0
def found_recipe(request, space_1, accent, unaccent, u1_s1, u2_s1):
    user1 = auth.get_user(u1_s1)
    user2 = auth.get_user(u2_s1)
    days_3 = timezone.now() - timedelta(days=3)
    days_15 = timezone.now() - timedelta(days=15)
    days_30 = timezone.now() - timedelta(days=30)
    if request.param.get('createdon', None):
        recipe1 = RecipeFactory.create(space=space_1, created_at=days_3)
        recipe2 = RecipeFactory.create(space=space_1, created_at=days_30)
        recipe3 = RecipeFactory.create(space=space_1, created_at=days_15)

    else:
        recipe1 = RecipeFactory.create(space=space_1)
        recipe2 = RecipeFactory.create(space=space_1)
        recipe3 = RecipeFactory.create(space=space_1)
    obj1 = None
    obj2 = None

    if request.param.get('food', None):
        obj1 = FoodFactory.create(name=unaccent, space=space_1)
        obj2 = FoodFactory.create(name=accent, space=space_1)
        recipe1.steps.first().ingredients.add(IngredientFactory.create(food=obj1))
        recipe2.steps.first().ingredients.add(IngredientFactory.create(food=obj2))
        recipe3.steps.first().ingredients.add(IngredientFactory.create(food=obj1), IngredientFactory.create(food=obj2))
    if request.param.get('keyword', None):
        obj1 = KeywordFactory.create(name=unaccent, space=space_1)
        obj2 = KeywordFactory.create(name=accent, space=space_1)
        recipe1.keywords.add(obj1)
        recipe2.keywords.add(obj2)
        recipe3.keywords.add(obj1, obj2)
        recipe1.name = unaccent
        recipe2.name = accent
        recipe1.save()
        recipe2.save()
    if request.param.get('book', None):
        obj1 = RecipeBookEntryFactory.create(recipe=recipe1).book
        obj2 = RecipeBookEntryFactory.create(recipe=recipe2).book
        RecipeBookEntryFactory.create(recipe=recipe3, book=obj1)
        RecipeBookEntryFactory.create(recipe=recipe3, book=obj2)
    if request.param.get('unit', None):
        obj1 = UnitFactory.create(name=unaccent, space=space_1)
        obj2 = UnitFactory.create(name=accent, space=space_1)
        recipe1.steps.first().ingredients.add(IngredientFactory.create(unit=obj1))
        recipe2.steps.first().ingredients.add(IngredientFactory.create(unit=obj2))
        recipe3.steps.first().ingredients.add(IngredientFactory.create(unit=obj1), IngredientFactory.create(unit=obj2))
    if request.param.get('name', None):
        recipe1.name = unaccent
        recipe2.name = accent
        recipe1.save()
        recipe2.save()
    if request.param.get('description', None):
        recipe1.description = unaccent
        recipe2.description = accent
        recipe1.save()
        recipe2.save()
    if request.param.get('instruction', None):
        i1 = recipe1.steps.first()
        i2 = recipe2.steps.first()
        i1.instruction = unaccent
        i2.instruction = accent
        i1.save()
        i2.save()

    if request.param.get('viewedon', None):
        ViewLogFactory.create(recipe=recipe1, created_by=user1, created_at=days_3, space=space_1)
        ViewLogFactory.create(recipe=recipe2, created_by=user1, created_at=days_30, space=space_1)
        ViewLogFactory.create(recipe=recipe3, created_by=user2, created_at=days_15, space=space_1)
    if request.param.get('cookedon', None):
        CookLogFactory.create(recipe=recipe1, created_by=user1, created_at=days_3, space=space_1)
        CookLogFactory.create(recipe=recipe2, created_by=user1, created_at=days_30, space=space_1)
        CookLogFactory.create(recipe=recipe3, created_by=user2, created_at=days_15, space=space_1)
    if request.param.get('timescooked', None):
        CookLogFactory.create_batch(5, recipe=recipe1, created_by=user1,  space=space_1)
        CookLogFactory.create(recipe=recipe2, created_by=user1,  space=space_1)
        CookLogFactory.create_batch(3, recipe=recipe3, created_by=user2, space=space_1)
    if request.param.get('rating', None):
        CookLogFactory.create(recipe=recipe1, created_by=user1, rating=5.0, space=space_1)
        CookLogFactory.create(recipe=recipe2, created_by=user1, rating=1.0, space=space_1)
        CookLogFactory.create(recipe=recipe3, created_by=user2, rating=3.0, space=space_1)

    return (recipe1, recipe2, recipe3, obj1, obj2, request.param)