def test_add_with_shopping(u1_s1, meal_type): space = meal_type.space with scope(space=space): recipe = RecipeFactory.create(space=space) r = u1_s1.post(reverse(LIST_URL), { 'recipe': { 'id': recipe.id, 'name': recipe.name, 'keywords': [] }, 'meal_type': { 'id': meal_type.id, 'name': meal_type.name }, 'date': (datetime.now()).strftime("%Y-%m-%d"), 'servings': 1, 'title': 'test', 'shared': [], 'addshopping': True }, content_type='application/json') assert len( json.loads(u1_s1.get( reverse('api:shoppinglistentry-list')).content)) == 10
def makenow_recipe(request, space_1): onhand_user = auth.get_user( request.getfixturevalue(request.param.get('onhand_users', 'u1_s1'))) recipe = RecipeFactory.create(space=space_1) for food in Food.objects.filter(ingredient__step__recipe=recipe.id): food.onhand_users.add(onhand_user) return recipe
def recipe(request, space_1, u1_s1): try: params = request.param # request.param is a magic variable except AttributeError: params = {} params['created_by'] = params.get('created_by', auth.get_user(u1_s1)) params['space'] = space_1 return RecipeFactory(**params)
def recipe(request, space_1, u1_s1): try: params = request.param # request.param is a magic variable except AttributeError: params = {} step_recipe = params.get('steps__count', 1) steps__recipe_count = params.get('steps__recipe_count', 0) steps__food_recipe_count = params.get('steps__food_recipe_count', {}) created_by = params.get('created_by', auth.get_user(u1_s1)) return RecipeFactory.create( steps__recipe_count=steps__recipe_count, steps__food_recipe_count=steps__food_recipe_count, created_by=created_by, space=space_1, )
def test_shopping_recipe_mixed_authors(u1_s1, u2_s1): with scopes_disabled(): user1 = auth.get_user(u1_s1) user2 = auth.get_user(u2_s1) space = user1.userpreference.space user3 = UserFactory(space=space) recipe1 = RecipeFactory(created_by=user1, space=space) recipe2 = RecipeFactory(created_by=user2, space=space) recipe3 = RecipeFactory(created_by=user3, space=space) food = Food.objects.get( id=recipe1.steps.first().ingredients.first().food.id) food.recipe = recipe2 food.save() recipe1.steps.add( StepFactory(step_recipe=recipe3, ingredients__count=0, space=space)) recipe1.save() u1_s1.put(reverse(SHOPPING_RECIPE_URL, args={recipe1.id})) assert len(json.loads(u1_s1.get( reverse(SHOPPING_LIST_URL)).content)) == 29 assert len(json.loads(u2_s1.get( reverse(SHOPPING_LIST_URL)).content)) == 0
def recipes(space_1): return RecipeFactory.create_batch(10, space=space_1)
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)