示例#1
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)
示例#2
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