def myHotels(): logger.info("Got a My hotels page request: %s" % request) db = AndrewDB() form = UDHotelForm() form.csrf_enabled = False if current_user.is_hotel_admin(): logger.info("Validating the Update or Delete hotel form") if form.validate_on_submit(): if form.edit.data: logger.info("Redirecting to Edit hotel page") return redirect( url_for('editHotel', hotel_id=form.hotel_id.data)) if form.delete.data: img = db.remove_hotel_by_id(form.hotel_id.data) os.remove(os.path.abspath('app' + img)) flash('Hotel was removed') logger.info( "Hotel (ID=%s) was removed, Redirecting to My Hotels page" % form.hotel_id.data) return redirect(url_for('myHotels')) if form.manage.data: logger.info("Redirecting to manage hotel page") return redirect( url_for('manageHotel', hotel_id=form.hotel_id.data)) if form.add_hotel.data: logger.info("Redirecting to Add hotel page") return redirect(url_for('addHotel')) hotels = db.get_hotels_by_admin_id(current_user.get_id()) logger.info("Rendering the My hotels page") return render_template('my_hotel.html', form=form, hotels=hotels) else: flash("Access error") logger.info("Access error, Redirecting to login page") return redirect(url_for('login'))
def test_get_hotels_by_admin_id(mock_connect): with allure.step('Get user by id'): with app.app_context(): db = AndrewDB() expected = ['hotel1', 'hotel2'] mock_connect().cursor.return_value.fetchall.return_value = expected result = db.get_hotels_by_admin_id(1) assert result == expected