Exemplo n.º 1
0
def test_get_admin_by_id(mock_connect):
    """Get administrator user from database by id"""
    with allure.step('Get admin by id'):
        with app.app_context():
            db = AndrewDB()
            expected = {1: 'admin1'}
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.get_admin_by_id(1)
        assert result == expected
Exemplo n.º 2
0
def test_get_receptionist_by_id(mock_connect):
    """Get receptionist user form database by id"""
    with allure.step('Get receptionist by id'):
        with app.app_context():
            db = AndrewDB()
            expected = {1: 'receptionist1'}
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.get_receptionist_by_id(1)
        assert result == expected
Exemplo n.º 3
0
def test_get_vw_customer_by_id(mock_connect):
    """Get visual data of customer from database by id"""
    with allure.step('Get vw customer by id'):
        with app.app_context():
            db = AndrewDB()
            expected = {1: 'customer1'}
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.get_vw_customer_by_id(1)
        assert result == expected
Exemplo n.º 4
0
def test_get_receptionists(mock_connect):
    """Get all receptionist users from database"""
    with allure.step('Get all receptionists'):
        with app.app_context():
            db = AndrewDB()
            expected = {1: 'user1'}
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.get_all_receptionists(1)
        assert result == expected
Exemplo n.º 5
0
def test_get_admins(mock_connect):
    """Get all administrator users from database"""
    with allure.step('Get all admins'):
        with app.app_context():
            db = AndrewDB()
            expected = ['admin1', 'admin2']
            mock_connect().cursor.return_value.fetchall.return_value = expected
            result = db.get_all_admins()
        assert result == expected
Exemplo n.º 6
0
def test_get_room_by_params(mock_connect):
    """Get rooms list from database by parameters"""
    with allure.step('Get room by parameters'):
        with app.app_context():
            db = AndrewDB()
            expected = ['room2', 'room1']
            mock_connect().cursor.return_value.fetchall.return_value = expected
            result = db.get_rooms_by_params("recep", "2018-01-02",
                                            "2018-01-10")
        assert result == expected
Exemplo n.º 7
0
def moreInfo(hotel_id):
    logger.info("Got a more info page request: %s" % request)
    db = AndrewDB()
    form = ReserveRoomForm()
    form.csrf_enabled = False
    search = session['search']
    search['hotel_id'] = hotel_id
    if request.method == 'POST':
        info = form.data
        info['customer_id'] = current_user.user_id
        checkin = datetime.datetime.strptime(search['checkin'],
                                             '%Y-%m-%d').date()
        checkout = datetime.datetime.strptime(search['checkout'],
                                              '%Y-%m-%d').date()
        nights = (checkout - checkin).days
        cost = db.get_cost_by_id(form.room_id.data)
        info['amount'] = int(form.quantity.data) * nights * int(cost)
        info['transaction_id'] = db.create_transaction_get_id(info)
        db.add_booking(info)
        flash('Room was reserved')
        logger.info("Room with ID=%s was reserved" % form.room_id.data)
    hotel = db.get_vw_hotel_by_id(hotel_id)
    rooms = db.search_get_rooms(search)
    cust_info = db.get_vw_customer_by_id(current_user.user_id)
    logger.info("Rendering the More info page")
    return render_template('booking.html',
                           form=form,
                           search=search,
                           hotel=hotel,
                           rooms=rooms,
                           cust_info=cust_info)
Exemplo n.º 8
0
def admin():
    logger.info("Got an admin panel page request: %s" % request)
    form = CAdmin()
    db = AndrewDB()
    g.role = 'admin'
    logger.info("Validating the Create admin form")
    form.csrf_enabled = False
    if request.method == 'POST' and form.validate_on_submit():
        hash_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user_id = db.insert_sys_user_get_id(form.email.data, hash_password)
        if user_id is None:
            flash('User with this email already registered')
            logger.info(
                "User with this email already registered, Redirecting to admin page"
            )
            return redirect(url_for('admin-panel'))
        db.insert_admin(str(user_id), form.first_name.data,
                        form.last_name.data, form.telephone.data)
        flash("Admin was added")
        logger.info("Admin was added, Redirecting to admin page")
        return redirect(url_for('admin-panel'))
    hotels = db.get_all_hotels()
    users = db.get_all_system_users()
    db_stat = db.get_db_statistics()
    admins = db.get_all_admins()
    g.db.commit()
    logger.info("Rendering the admin_panel page")
    return render_template('admin_panel.html',
                           hotels=hotels,
                           users=users,
                           db_stat=db_stat,
                           form=form,
                           admins=admins)
Exemplo n.º 9
0
def test_get_sys_users(mock_connect):
    """Get all existing users from database"""
    with allure.step('Get all system users'):
        with app.app_context():
            db = AndrewDB()
            expected = ['user1', 'user2']
            mock_connect(
            ).cursor.return_value.fetchone.return_value.__getitem__(
                'users').return_value = expected
            result = db.get_all_system_users().return_value
        assert result == expected
Exemplo n.º 10
0
def test_get_hotels(mock_connect):
    """Get all hotels from database"""
    with allure.step('Get all hotels'):
        with app.app_context():
            db = AndrewDB()
            expected = ['hotel1']
            mock_connect(
            ).cursor.return_value.fetchone.return_value.__getitem__(
                'hotels').return_value = expected
            result = db.get_all_hotels().return_value
        assert result == expected
Exemplo n.º 11
0
def manageBooking():
    logger.info("Got a Manage booking page request: %s" % request)
    db = AndrewDB()
    if 'recep' not in session:
        session['recep'] = db.get_all_receptionists(current_user.user_id)
    if 'hotel' not in session:
        session['hotel'] = db.get_vw_hotel_by_id(session['recep']['hotel_id'])
    recep = session['recep']
    hotel = session['hotel']
    bookings = db.get_booked_rooms_by_hotel_id(recep['hotel_id'])
    logger.info("Rendering the Booked rooms page")
    return render_template('booked_rooms.html', bookings=bookings, hotel=hotel)
Exemplo n.º 12
0
def update_profile():
    logger.info("Got a profile page request: %s" % request)
    db = AndrewDB()
    form = ProfileForm()
    user = current_user
    logger.info("Validating the profile form")
    form.csrf_enabled = False
    if form.validate_on_submit():
        if user.is_customer():
            db.update_customer(user.user_id, form.first_name.data,
                               form.last_name.data, form.telephone.data,
                               form.credit_card.data)
            logger.info("Redirecting to index page")
            return redirect(url_for('index'))
        elif user.is_hotel_admin():
            db.update_hotel_admin(user.user_id, form.first_name.data,
                                  form.last_name.data, form.telephone.data)
            logger.info("Redirecting to index page")
            return redirect(url_for('index'))
        elif user.is_admin():
            db.update_admin(user.user_id, form.first_name.data,
                            form.last_name.data, form.telephone.data)
            logger.info("Redirecting to admin page")
            return redirect(url_for('admin'))

    flash("Invalid form")
    logger.info("Invalid profile form, Redirecting to add property page")
    return redirect(url_for('index'))
Exemplo n.º 13
0
def test_insert_sys_user(mock_connect):
    """Insert new user into database and return its contents"""
    with allure.step('Insert into sys_user and get user'):
        with app.app_context():
            db = AndrewDB()
            expected = {
                'user_id': 5,
                'email': "*****@*****.**",
                'password': "******",
                'role': "ROLE_ADMIN"
            }
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.insert_sys_user("*****@*****.**", "123456")
        assert result == expected
Exemplo n.º 14
0
def editHotel(hotel_id):
    logger.info("Got an Edit 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:
                db.insert_location_if_not_exists(form.country.data,
                                                 form.city.data)

                old_img = db.get_image_name_by_hotel_id(hotel_id)
                img_path = '/static/img/hotels/' + img_name
                db.update_hotel_by_id(hotel_id, form.city.data,
                                      form.address.data, form.hotel_name.data,
                                      form.stars.data, form.description.data,
                                      img_path)
                form.img.data.save(
                    os.path.join(app.config['UPLOAD_FOLDER'], img_name))
                os.remove(os.path.abspath('app' + old_img))
                return redirect(url_for('myHotels'))
        res = db.get_hotel_and_address_by_id(hotel_id)
        logger.info("Rendering the Edit hotel page")
        return render_template('edit_hotel.html', form=form, hotel=res)
    else:
        flash("Access error")
        logger.info("Access error, Redirecting to login page")
        return redirect(url_for('login'))
Exemplo n.º 15
0
def test_get_sys_user_by_email(mock_connect):
    """Get user from database contents by E-mail"""
    with allure.step('Get sys_user by email'):
        with app.app_context():
            db = AndrewDB()
            expected = {
                'user_id': 5,
                'email': "*****@*****.**",
                'password': "******",
                'role': "ROLE_ADMIN"
            }
            mock_connect().cursor.return_value.fetchone.return_value = expected
            result = db.get_sys_user_by_email("*****@*****.**")
        assert result == expected
Exemplo n.º 16
0
def get_profile():
    logger.info("Got a profile page request: %s" % request)
    db = AndrewDB()
    form = ProfileForm()
    user = current_user
    user_info = None
    form.csrf_enabled = False
    if user.is_customer():
        res = db.get_customer_by_id(user.user_id)
        user_info = Customer(res['first_name'], res['last_name'], user.email,
                             res['phone_number'], res['payment_info'])
    elif user.is_hotel_admin():
        res = db.get_hotel_admin_by_id(user.user_id)
        if res:
            user_info = HotelAdmin(res['first_name'], res['last_name'],
                                   user.email, res['phone_number'])
        else:
            flash("Unable to find a hotel admin entry")
            logger.info(
                "Unable to find a hotel admin entry, Redirecting to index page"
            )
            return redirect(url_for('index'))
    elif user.is_receptionist():
        user_info = db.get_receptionist_by_id(user.user_id)
        user_info['email'] = user.email
    elif user.is_admin():
        db.get_admin_by_id(user.user_id)
        user_info['email'] = user.email
    logger.info("Rendering the Profile page")
    return render_template('profile.html', form=form, user=user_info)
Exemplo n.º 17
0
def myBooking():
    logger.info("Got a My booking page request: %s" % request)
    db = AndrewDB()
    form = DBookingForm()
    today = datetime.datetime.now().date()
    logger.info("Validating the Delete booking form")
    form.csrf_enabled = False
    if form.validate_on_submit():
        if not db.delete_transaction(form.transaction_id.data):
            flash("Reservation has been cancelled")
            logger.info("Reservation was cancelled: ID = %s" %
                        form.transaction_id.data)
    info = db.get_some_info_by_user_id(current_user.get_id())
    logger.info("Rendering the My booking page")
    return render_template('my_booking.html',
                           form=form,
                           info=info,
                           today=today)
Exemplo n.º 18
0
def searchHotel():
    logger.info("Got a search hotel page request: %s" % request)
    db = AndrewDB()
    form = InfoForm()
    form.csrf_enabled = False
    search = session['search']
    if request.method == 'POST':
        if current_user.is_anonymous():
            flash("You must be authorized to reserve rooms")
            logger.info(
                "The user must be authorized to reserve rooms. Redirecting to login page"
            )
            return redirect(url_for('login'))
        logger.info("Redirecting to More info page")
        return redirect(url_for('moreInfo', hotel_id=form.hotel_id.data))

    hotels = db.search_hotels_by_form(search)
    logger.info("Rendering the Search hotel page")
    return render_template('search_hotel.html', form=form, hotels=hotels)
Exemplo n.º 19
0
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'))
Exemplo n.º 20
0
def register():
    logger.info("Got a register page request: %s" % request)
    g.role = 'customer'
    db = AndrewDB()
    form = RegisterForm()
    logger.info("Validating the register form")
    form.csrf_enabled = False
    if form.validate_on_submit():
        if not form.password.data == form.password_confirmation.data:
            logger.info(
                "Password confirmation failed, Redirecting to register page")
            return redirect(url_for('register'))

        hash_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        res = db.insert_sys_user(form.email.data, hash_password, g.role)
        if not res:
            flash('User with this email already registered')
            logger.info(
                "User with this email (%s) alredy registered, redirecting to register page"
                % form.email.data)
            return redirect(url_for('register'))

        user_id = res[0].strip('()').split(',')[0]
        db.add_customer(user_id, form.first_name.data, form.last_name.data,
                        form.telephone.data)

        user = User(user_id, form.email.data, hash_password, g.role)
        login_user(user)
        flash('User successfully registered')
        logger.info(
            "User (ID = %s) successfully registered, redirecting to index page"
            % user.get_id())
        return redirect(url_for('index'))
    logger.info("Rendering the register page")
    return render_template('register.html', form=form)
Exemplo n.º 21
0
def login():
    logger.info("Got a login page request: %s" % request)
    db = AndrewDB()
    form = LoginForm()
    logger.info("Validating the login form")
    form.csrf_enabled = False
    if form.validate_on_submit():
        sys_user = db.get_sys_user_by_email(form.email.data)
        if not sys_user or not check_password(sys_user['password'],
                                              form.password.data):
            flash('Email Address or Password is invalid')
            logger.info(
                "Email address or password is invalid, redirecting to the login page"
            )
            return redirect(url_for('login'))
        user = User(sys_user['user_id'], sys_user['email'],
                    sys_user['password'], sys_user['role'])
        if form.remember_me.data:
            login_user(user, remember=True)
        else:
            login_user(user)
        flash('Logged in successfully')
        logger.info("Logged in successfully: ID = %s" % user.get_id())
        if user.is_receptionist():
            logger.info("Redirecting to Manage booking page")
            return redirect(url_for('manageBooking'))
        if user.is_hotel_admin():
            logger.info("Redirecting to My hotels page")
            return redirect(url_for('myHotels'))
        if user.is_admin():
            logger.info("Redirecting to admin page")
            return redirect(url_for('admin'))
        logger.info("Redirecting to index page")
        return redirect(url_for('index'))
    logger.info("Rendering the login page")
    return render_template('login.html', form=form)
Exemplo n.º 22
0
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")
Exemplo n.º 23
0
def test_delete_hotel_by_id(mock_connect):
    with allure.step('Delete hotel'):
        with app.app_context():
            db = AndrewDB()
            db.remove_hotel_by_id(1)
Exemplo n.º 24
0
def test_add_customer(mock_connect):
    with allure.step('Add customer'):
        with app.app_context():
            db = AndrewDB()
            db.add_customer(1, "John", "Doe", "+0-000-00-00-00")
Exemplo n.º 25
0
def test_add_booking(mock_connect):
    with allure.step('Add booking'):
        with app.app_context():
            db = AndrewDB()
            db.add_booking({})
Exemplo n.º 26
0
def test_update_customer(mock_connect):
    with allure.step('Update customer'):
        with app.app_context():
            db = AndrewDB()
            db.update_customer(1, "John", "Doe", "+0-000-00-00-00",
                               "000000000000000")
Exemplo n.º 27
0
def manageHotel(hotel_id):
    logger.info("Got a manage hotel page request: %s" % request)
    db = AndrewDB()
    g.role = 'receptionist'
    recForm = CReceptionistForm()
    roomForm = CRoomForm()
    form = UDRoomForm()
    form2 = URoomForm()
    form3 = DReceptionistForm()
    form.csrf_enabled = False
    form2.csrf_enabled = False
    form3.csrf_enabled = False
    if current_user.is_hotel_admin():
        if form.delete.data:
            if db.delete_room_by_id(form.room_id.data):
                flash('Room was removed')
                logger.info("Room was removed: ID = %s" % form.room_id.data)
            logger.info("Redirecting to manage hotel page")
            return redirect(url_for('manageHotel', hotel_id=hotel_id))

        if form2.edit.data:
            logger.info("Validating the Update room form")
            if form2.validate_on_submit():
                option_id = None
                config_id = None
                res = db.get_option_by_params(form2.is_bathroom.data,
                                              form2.is_tv.data,
                                              form2.is_wifi.data,
                                              form2.is_bathhub.data,
                                              form2.is_aircond.data)
                if not res:
                    option_id = db.insert_option(form2.is_bathroom.data,
                                                 form2.is_tv.data,
                                                 form2.is_wifi.data,
                                                 form2.is_bathhub.data,
                                                 form2.is_aircond.data)
                else:
                    option_id = res['option_id']
                res = db.select_config(form2.sing_bed.data,
                                       form2.doub_bed.data,
                                       form2.sofa_bed.data)
                if not res:
                    config_id = db.insert_config(form2.sing_bed.data,
                                                 form2.doub_bed.data,
                                                 form2.sofa_bed.data)
                else:
                    config_id = res['config_id']
                db.set_up_room_by_id(config_id, option_id, form2.quantity.data,
                                     form2.title.data, form2.description.data,
                                     form2.cost.data, form2.room_id.data)

        if form3.del_rec.data:
            if db.delete_receptionist_by_id(form3.user_id.data):
                flash("Receptionist was removed")
                logger.info("Receptionist was removed: ID = %s" %
                            form3.user_id.data)

        if recForm.save.data:
            logger.info("Validating the Create receptionist form")
            if recForm.validate_on_submit():
                hash_password = bcrypt.generate_password_hash(
                    recForm.password.data).decode('utf-8')
                user_id = db.insert_sys_user_get_id(recForm.email.data,
                                                    hash_password, g.role)
                if user_id:
                    flash('User with this email already registered')
                else:
                    logger.info("Redirecting to manage hotel page")
                    redirect(url_for('manageHotel', hotel_id=hotel_id))
                if db.add_new_receptionist(user_id, hotel_id,
                                           recForm.first_name.data,
                                           recForm.last_name.data,
                                           recForm.telephone.data,
                                           recForm.salary.data):
                    flash("Receptionist was added")
                    logger.info("Receptionist was added: ID = %s" %
                                recForm.user_id.data)
                logger.info("Redirecting to manage hotel page")
                return redirect(url_for('manageHotel', hotel_id=hotel_id))

        if roomForm.save.data:
            logger.info("Validating the Create room form")
            if roomForm.validate_on_submit():
                option_id = None
                config_id = None

                res = db.get_option_by_params(roomForm.is_bathroom.data,
                                              roomForm.is_tv.data,
                                              roomForm.is_wifi.data,
                                              roomForm.is_bathhub.data,
                                              roomForm.is_aircond.data)
                if not res:
                    option_id = db.insert_option(roomForm.is_bathroom.data,
                                                 roomForm.is_tv.data,
                                                 roomForm.is_wifi.data,
                                                 roomForm.is_bathhub.data,
                                                 roomForm.is_aircond.data)
                else:
                    option_id = res['option_id']

                res = db.select_config(roomForm.sing_bed.data,
                                       roomForm.doub_bed.data,
                                       roomForm.sofa_bed.data)
                if not res:
                    config_id = db.insert_config(roomForm.sing_bed.data,
                                                 roomForm.doub_bed.data,
                                                 roomForm.sofa_bed.data)
                else:
                    config_id = res['config_id']
                db.add_new_room(hotel_id, config_id, option_id,
                                roomForm.quantity.data, roomForm.title.data,
                                roomForm.description.data, roomForm.cost.data)
                flash('Room was added')
                logger.info(
                    "Receptionist was added (ID = %s), Redirecting to manage hotel page"
                    % roomForm.user_id.data)
                return redirect(url_for('manageHotel', hotel_id=hotel_id))
        hotel = db.get_hotel_by_id(hotel_id)
        rooms = db.get_rooms_with_settings_by_id(hotel_id)
        recep = db.get_receptionists_by_hotel_id(hotel_id)
        logger.info("Rendering the Manage hotel page")
        return render_template('manage_hotel.html',
                               recForm=recForm,
                               roomForm=roomForm,
                               form=form,
                               form2=form2,
                               form3=form3,
                               hotel=hotel,
                               rooms=rooms,
                               recep=recep)
    else:
        flash("Access error")
        logger.info("Access error, Redirecting to login page")
        return redirect(url_for('login'))
Exemplo n.º 28
0
def test_update_admin(mock_connect):
    with allure.step('Update admin'):
        with app.app_context():
            db = AndrewDB()
            db.update_admin(1, "John", "Doe", "+0-000-00-00-00")
Exemplo n.º 29
0
def test_insert_admin(mock_connect):
    """Insert new admin into database"""
    with allure.step('Insert into admin'):
        with app.app_context():
            db = AndrewDB()
            db.insert_admin(10, "John", "Doe", "+0-000-00-00-00")
Exemplo n.º 30
0
def test_insert_location_if_not_exists(mock_connect):
    """"""
    with allure.step('Add new room'):
        with app.app_context():
            db = AndrewDB()
            db.insert_location_if_not_exists("Russia", "Innopolis")