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))
def get_food_by_id(): """returns value of food data""" data = request.get_json("data") food = Food.get_food_by_id(data["food_id"]) return food