def test_get_end_date(self): """Testing that get_end_time() returns the correct value """ # Creating booking object book_time = datetime.utcnow() duration = 3 booking = Booking(1, "dummy", book_time, duration) # Checking end time is correct end_time = book_time + timedelta(hours=duration) assert (end_time == booking.get_end_time())
def test_users_booking(self): u = User(username='******', email='*****@*****.**', password='******', confirmed=True) db.session.add(u) db.session.commit() response = self.client.post(url_for('service.service_login'), content_type='application/json', data=json.dumps({ 'email': '*****@*****.**', 'password': '******' })) self.assertTrue('/userapi/service/?SID' in response.data) response = self.client.get(url_for('service.service_bookings'), content_type='application/json') self.assertTrue('bookings' in response.data) booking = Booking(user=u, PNR='APPLE1') db.session.add(booking) db.session.commit() response = self.client.get(url_for('service.service_bookings'), content_type='application/json') #print response.data self.assertTrue('APPLE1' in response.data)
def checkout_items(self): print('hit') user_items = session.query(Checkout).filter( Checkout.user_id == self.CURRENT_USER.id) for item in user_items: new_booking = Booking(booked_date=item.booked_date, duration_of_booking=item.duration_of_booking, tool_id=item.tool_id, user_id=item.user_id, delivery=item.delivery) session.add(new_booking) session.delete(item) session.commit() self.treeview.delete(*self.treeview.get_children()) self.loadTable()
def create_booking(slot_id, start_time, end_time): """ Create booking entry for given parking slot. :param slot_id: :param start_time: :param end_time: :return: """ user = CommonUtility.get_authenticated_user() booking = Booking(parking_slot_id=slot_id, start_time=start_time, end_time=end_time, status=ConstantsUtility.BOOKED, user_id=user.id) db.session.add(booking) db.session.commit() return booking
def update_booking_payment(form, payment): # Update db with new booking or edit existing booking if payment['booking_type'] == 'new': booking = Booking(user_id=payment['user_id'], event_slot_id=payment['slot_id'], quantity=payment['quantity']) db.session.add(booking) elif payment['booking_type'] == 'update': booking = Booking.query.get(payment['booking_id']) booking.quantity += payment['quantity'] db.session.commit() # Update db with new payment record new_payment = Payment(quantity=payment['quantity'], amount=(payment['price'] * payment['quantity']), card_number=form.card_number.data, booking_id=booking.booking_id, promotion_id=payment['promo_id']) db.session.add(new_payment) db.session.commit()
def setup_class(cls): # Example: Load dummy sqlite DB print ("Runs before any methods in this class") cls.app = AppFactory.create_app(TestConfig) # db.init_app(cls.app) with cls.app.app_context(): db.create_all() roomPrice = RoomPrice("single", 100, 150) room = Room(1, 101, 3, "Available", 1) booking = Booking(1, 1, datetime.strptime('2017-01-02', '%Y-%m-%d').date() ,datetime.strptime('2017-01-10', '%Y-%m-%d').date(), 123123123, 2000) RoomManager.set_availability_for_booking(datetime.strptime("2017-01-01", '%Y-%m-%d').date(), 1) UserManager.create_user("*****@*****.**", "asdasd") user = UserManager.get_user("*****@*****.**") UserManager.update_details(user, "mr", "test", "05644654") db.session.add(roomPrice) db.session.add(room) db.session.add(booking) db.session.commit()
def make_booking(): """Creates a user booking for a car if it isn't already booked .. :quickref: Booking; Make a booking. **Example request**: .. sourcecode:: http POST /api/booking HTTP/1.1 Host: localhost Accept: application/json Content-Type: application/json { "car_id": 1, "username": "******", "duration": 3 } **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "message": "Success" } .. sourcecode:: http HTTP/1.1 401 UNAUTHORIZED Content-Type: application/json { "message": "Car is currently booked", } :<json string car_id: the id of the car being booked :<json string username: the username of the user booking the car :<json string duration: how long the car will be booked for in hours :>json message: repsonse information such as error information :resheader Content-Type: application/json :status 200: successful booking :status 400: malformed request :status 401: car is already booked """ response = { 'message': None, } status = 200 form_schema = BookCarFormSchema() form_errors = form_schema.validate(request.json) if form_errors: response['message'] = form_errors status = 400 else: car_id = request.json["car_id"] username = request.json["username"] duration = request.json["duration"] book_time = datetime.utcnow() # Below code block will be checking if the car is currently booked currently_booked = False # Getting most recent booking from the database prev_booking = (Booking.query.filter_by(car_id=car_id).order_by( Booking.book_time.desc()).first()) if (prev_booking is not None): # Checking if the time being booked is after the previous booking's # end time if (book_time < prev_booking.get_end_time()): currently_booked = True response['message'] = {'user': ['Car is currently booked.']} status = 401 if not currently_booked: # Adding to Google calendar if authorised gcal_id = None user = User.query.get(username) if (user.google_credentials is not None): car = Car.query.get(car_id) service = build('calendar', 'v3', credentials=user.google_credentials) end_time = book_time + timedelta(hours=int(duration)) event = { 'summary': 'Ride in {} {}'.format(car.make, car.body_type), 'description': 'Booked from RMIT Rideshare app', 'start': { 'dateTime': str(book_time.isoformat()), 'timeZone': 'UTC', }, 'end': { 'dateTime': str(end_time.isoformat()), 'timeZone': 'UTC', } } event = service.events().insert(calendarId='primary', body=event).execute() gcal_id = event.get('id') # Adding booking to database with Google calendar id if present booking = Booking(car_id, username, book_time, duration, gcal_id) db.session.add(booking) db.session.commit() response['message'] = "Success" return response, status