def addHotel(): logger.info("Got an Add hotel page request: %s" % request) db = AndrewDB() form = CUHotelForm() form.csrf_enabled = False if current_user.is_hotel_admin(): logger.info("Validating the Create and Update hotel form") if form.validate_on_submit(): img_name = imgName(form.img.data.filename) if img_name: img_path = '/static/img/hotels/' + img_name try: db.insert_location_if_not_exists(form.country.data, form.city.data) db.add_hotel(form.city.data, form.address.data, form.hotel_name.data, form.stars.data, form.description.data, current_user.user_id, img_path) except Exception as e: logger.exception("Unable to add Hotel") print(e) logger.info("Redirecting to My hotels page") return redirect(url_for('myHotels')) form.img.data.save( os.path.join(app.config['UPLOAD_FOLDER'], img_name)) flash('Hotel was added') logger.info("Hotel was added, Redirecting to My hotels page") return redirect(url_for('myHotels')) logger.info("Rendering the Edit hotel page") return render_template('edit_hotel.html', form=form, hotel=None) else: flash("Access error") logger.info("Access error, Redirecting to login page") return redirect(url_for('login'))
def test_add_hotel(mock_connect): with allure.step('Add hotel'): with app.app_context(): db = AndrewDB() db.add_hotel("Moscow", "Innopolis", "NoName", 4, "Not named hotel", 1, "noname.png")