def do_save(): """User/Guest page, if user is not signed in they can save data to the guest account""" food_data = request.get_json("data") if g.user: Food.add_food(g.user.id, food_data["food"], food_data["menuName"]) return "true" else: guest = User.query.filter_by(username="******").first() Food.add_food(guest.id, food_data["food"], food_data["menuName"]) return "true"
def test_food_model(self): """Test add_food""" User.signup("test_username1", "test_pw1") test_user1 = db.session.query(User).filter_by( username="******").first() Food.add_food(test_user1.id, {"food1": {"test": "food"}}, "lunch") self.assertEqual(1, len(test_user1.foods)) """Test get_food_by_id""" # test positive test_id = test_user1.foods[0].id test_food = json.loads(Food.get_food_by_id(test_id)) self.assertEqual(test_food["food1"]["test"], "food") # test negative test_id2 = 1000 test_food2 = Food.get_food_by_id(test_id2) self.assertEqual(test_food2, None) """Test delete_food_by_id""" Food.delete_food_by_id(test_id) self.assertEqual(0, len(test_user1.foods))