def test_add_allergen(self): # Ensure function adds allergen to database this_allergen = Allergen.add_allergen(["eggs", "wheat", "dairy"]) this_id = this_allergen.allergen_id assert Allergen.query.filter_by(allergen_id=this_id).one()
def postlisting(): # Handles a new listing being submitted title = request.form.get('title') title = titlecase(title) texture = request.form.get('texture') datemade = request.form.get('datemade') quantity = request.form.get('quantity') freshfrozen = request.form.get('freshfrozen') description = request.form.get('description') allergens = request.form.getlist('allergens') user_id = session['user_id'] phone_number = request.form.get('phone_number') geoCheckbox = request.form.get('geoCheckbox') if len(phone_number) == 17: phone_number = phone_number[4:7]+phone_number[9:12]+phone_number[13:] else: phone_number = None allergen = Allergen.add_allergen(allergens) allergen_id = allergen.allergen_id if geoCheckbox: lat = request.form.get('lat') lng = request.form.get('lng') location = Location.add_location(lat, lng) location_id = location.location_id else: location_id = None Food.add_food(title, texture, datemade, quantity, freshfrozen, description, allergen_id, user_id, location_id, phone_number) flash('Your mush has been successfully posted!') return redirect('/home')