def test_add_user(session): new_user = User(username='******', email='*****@*****.**', password='******') session.add(new_user) session.commit() assert User.query.first().username == 'potato'
def add_user_recipe_list_and_recipes(session): u = add_user(session) token = u.generate_auth_token().decode('utf-8') recipe_list = add_recipe_list(session, u.id, 'test list') r1 = Recipes( recipe_name='potato', recipe_url='http://blah.com', pic_url='http://picturesofpotatoes.com', recipe_list_id=recipe_list.id, recipe_id=12, added_by=u.id ) r2 = Recipes( recipe_name='potato', recipe_url='http://blah.com', pic_url='http://picturesofpotatoes.com', recipe_list_id=recipe_list.id, recipe_id=123, added_by=u.id ) session.add(r1) session.add(r2) session.commit() assert Recipes.query.count() == 2 assert len(RecipeList.query.first().recipes) == 2 return (u, token, recipe_list)
def create_user(session, username="******", email='*****@*****.**', password='******'): u = User(username=username, email=email, password=password) session.add(u) session.commit() return u
def create_user(session, username='******', email='*****@*****.**', pw='test'): u = User(username=username, email=email, password=pw) session.add(u) session.commit() return u
def test_recipes_on_list_come_through(session, client): user = add_user(session) recipe_list = add_recipe_list(session, user, 'test list') r1 = Recipes( recipe_name='recipe1', recipe_url='https://recipe.com', pic_url='http://thisismyfakeurl.com', recipe_list_id=recipe_list.id, recipe_id=123, added_by=user.id ) session.add(r1) session.commit() token = user.generate_auth_token() response = client.get( url_for('users.get_recipe_lists'), headers={'Authorization': token} ) assert response.status_code == 200 data = response.get_json()['recipeList'][0] assert len(data['recipes']) == 1
def test_add_two_users(session): user1 = User(username='******', email='*****@*****.**', password='******') user2 = User(username='******', email='*****@*****.**', password='******') session.add(user1) session.add(user2) session.commit() assert len(User.query.all()) == 2 assert User.query.first().username == 'hudson' assert User.query.all()[1].username == 'stephanie' user3 = User(username='******', email='*****@*****.**', password='******') session.add(user3) session.commit() assert len(User.query.all()) == 3 assert User.query.all()[-1].username == 'tyler' assert User.query.first().email == '*****@*****.**'
def add_recipe_to_recipe_list(session, list_id, recipe_id, user_id): recipe = Recipes('test name', 'http://testurl', 'http://testpicurl.com', list_id, recipe_id, user_id) session.add(recipe) session.commit() return recipe
def add_recipe_list(session, userid, listname): r = RecipeList(list_creator=userid, list_name=listname) session.add(r) session.commit() return r
def add_recipe_list(session, user, list_name): recipe_list = RecipeList(list_creator=user.id, list_name=list_name) session.add(recipe_list) user.recipe_lists.append(recipe_list) session.commit() return recipe_list