Esempio n. 1
0
 def cancelaReserva_hotel(self): # OJO PIOJO A ESTA FUNCION
     for hotel in self.lista_hoteles:
         hotels = Booking()
         if hotels.reserva_hotel(self.user, hotel) != True:
             return True
         else:
             return False
Esempio n. 2
0
 def confirmaReserva_hotel(self):
     if not self.lista_hoteles:
         return 0
     for hotel in self.lista_hoteles:
         if hotel.dataHotelOK() == False:
             raise ValueError("Error: La reserva de hotels ha fallat")
         hotels = Booking()
         hotels.confirm_reserve(self.user, hotel)
     return True
Esempio n. 3
0
 def confirmacion_alojamiento(self, cod_hotel, nombre_hotel, num_huespedes,
                              num_hab, reserva):
     hotel = Booking()
     aux = Hotels(cod_hotel, nombre_hotel, num_huespedes, num_hab, reserva)
     comp = aux.comprueba_hoteles(cod_hotel, nombre_hotel, num_huespedes,
                                  num_hab, reserva)
     cap = num_huespedes / num_hab
     if comp == 1 and cap <= 3:
         return hotel.confirm_reserve(self.user, self.hoteles)
     else:
         return -1
Esempio n. 4
0
    def make_booking(self, customer, period, start_date, end_date, car, location):
        # Prevent the customer from referencing 'current_user';
        # otherwise the customer recorded in each booking will be modified to
        # a different user whenever the current_user changes (i.e. when new user logs-in)
        try:
            if start_date == None:
                raise(BookingError(start_date,"Specify a valid start date"))
            elif end_date == None:
                raise(BookingError(end_date,"Specify a valid end date"))
            elif location.pickup == None:
                raise(BookingError(location.pickup,"Specify a valid start location"))
            elif location.dropoff == None:
                raise(BookingError(location.dropoff,"Specify a valid end location"))
            elif period <= 0:
                raise(BookingError(period,"Specify a valid period"))
        except BookingError:
            msg = self._msg
            return -1

        customer = copy.copy(customer)

        new_booking = Booking(customer, period, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 5
0
    def make_booking(self, customer, input_start_date, input_end_date, car,
                     start_location, end_location):
        # Prevent the customer from referencing 'current_user';
        customer = copy.copy(customer)
        ##check fileds are not empty
        if not start_location:
            raise BookingError("start_location",
                               "Specify a valid start loaction!")
        if not end_location:
            raise BookingError("end_location", "Specify a valid end loaction!")

        if not input_start_date:
            raise BookingError("start_date", "Specify a valid start date!")
        if not input_end_date:
            raise BookingError("end_date", "Specify a valid end date!")
            ##check end

        ##check end_date < start_date
        date_format = "%Y-%m-%d"
        start_date = datetime.strptime(input_start_date, date_format)
        end_date = datetime.strptime(input_end_date, date_format)
        if end_date < start_date:
            raise BookingError("period", "Specify a valid booking period!")
            ##check end

        ##all filed valid ,then make booking
        location = Location(start_location, end_location)
        new_booking = Booking(customer, start_date, end_date, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 6
0
    def test_8(self):
        aux1 = Hotels(nombre_hotel='Vela')
        aux2 = Hotels()
        aux_alojamiento = [aux1, aux2]

        x = Viajes(user=User,
                   lista_pasajeros=['p1', 'p2', 'p3'],
                   hoteles=aux_alojamiento)
        aux = User('Pepito Los Palotes', '12345678P', '08390', '678942316',
                   '*****@*****.**')

        fallo = x.anadir_alojamiento(1)
        book = Booking()
        book.confirm_reserve = MagicMock(return_value=False)

        assert book.confirm_reserve(aux, aux_alojamiento) == fallo
Esempio n. 7
0
 def mock_confirm_hotels(*args):
     retries = 0
     while retries < DEFAULT_MAX_RETRIES:
         try:
             if Booking.confirm_reserve(*args):
                 pass
         except ConnectionRefusedError:
             retries += 1
     return retries
Esempio n. 8
0
 def mock_confirm_hotels(*args):
     retries = 0
     while retries < DEFAULT_MAX_RETRIES:
         try:
             return retries, Booking.confirm_reserve(*args)
         except ConnectionRefusedError:
             retries += 1
             if retries == DEFAULT_RETRIES:
                 monkeypatch.setattr(Booking, "confirm_reserve",
                                     mock_booking_success)
Esempio n. 9
0
    def make_booking(self, customer, period, car, location):
        # Prevent the customer from referencing 'current_user';
        # otherwise the customer recorded in each booking will be modified to
        # a different user whenever the current_user changes (i.e. when new user logs-in)
        customer = copy.copy(customer)

        new_booking = Booking(customer, period, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 10
0
def test_make_booking():
    provider = system.user_manager.get_HP_by_name('toby')
    health_centre = system.hc_manager.get_HC_by_name(
        'Sydney Children Hospital')
    patient = system.user_manager.get_Patient_by_name('jack')
    date = '2019-05-20'
    year, month, day = date.split("-")
    booking_date = datetime(int(year), int(month), int(day))
    time1 = time(9, 30)
    booking_datetime = datetime.combine(booking_date, time1)
    booking = Booking(health_centre, provider, booking_datetime, patient, "")
    assert (system.booking_system.make_booking(booking))
Esempio n. 11
0
    def _fetch_hotel_price() -> float:
        """ Call the Booking API and request the price for all the hotels

        This process is extremely simplified, in a real world
        scenario we should retrieve the price for each room of each different Hotel and check if all makes sense.

        We assume that the number of hotels is correct and that the price we receive takes into account
        the number of travelers and rooms required for all the hotels, for this project we take that
        'single' hotel price and reuse it for all the Hotels.

        :return: the price to use for all the hotels
        """

        return Booking.fetch_hotel_price()
Esempio n. 12
0
    def make_booking(self, customer, period, car, location):

        if period.total_seconds() < 0:
            raise BookingError(location,period,"Start date cannot be greater than end date")

        
        if location.check_location() is False:
            raise BookingError(location,period,"Booking location cannot be empty")


            new_booking = Booking(customer, period, car, location)
            self._bookings.append(new_booking)
            car.add_booking(new_booking)
            return new_booking
    def make_booking(self, patient, time, date, provider, reason):
        # Prevent the patient from referencing 'current_user';
        # otherwise the patient recorded in each booking will be modified to
        # a different user whenever the current_user changes (i.e. when new user logs-in)
        patient = copy.copy(patient)

        #check_location_error(location)
        #validate(start_date)
        new_booking = Booking(patient, time, date, provider, reason)

        self._bookings.append(new_booking)
        provider.add_booking(new_booking)
        current_user.add_booking(new_booking)

        return new_booking
Esempio n. 14
0
    def make_booking(self, customer, period, car, location):
        try:
            if location.pickup == '' or location.pickup == None:
                raise BookingError(car, 'Specity a valid start location.')

            if location.dropoff == '' or location.dropoff == None:
                raise BookingError(car, 'Specity a valid end location.')
            if period.days < 0:
                raise BookingError(car, 'Specify a valid booking period.')

        except BookingError as error:
            return error

        else:
            new_booking = Booking(customer, period, car, location)
            self._bookings.append(new_booking)
            car.add_booking(new_booking)
            return new_booking
Esempio n. 15
0
    def _confirm_hotels(self) -> bool:
        """ Connect to the Booking API and perform the payment

        Catches ConnectionRefusedError(s) thrown by the Booking API and tries to establish the connection again.

        :return: bool value indicating if the hotels are reserved
        """

        if self._travel.has_hotels:
            retries = 0
            while retries < self.MAX_RETRIES:
                try:
                    return Booking.confirm_reserve(self._user,
                                                   self._travel._hotels)
                except ConnectionRefusedError:
                    retries += 1
            raise ConnectionRefusedError(Response.BOOKING_ERROR)
        else:
            return True
Esempio n. 16
0
    def make_booking(self, customer, period, car, location):
        try:
            if len(location.pickup) == 0:
                raise BookingError('location',
                                   'Please enter a valid pick up location')
            if len(location.dropoff) == 0:
                raise BookingError('location',
                                   'Please enter a valid drop of location')
            if period.days < 1:
                raise BookingError('period',
                                   'Please enter a valid start and end time')

        except BookingError as error:
            return error

        new_booking = Booking(customer, period, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 17
0
    def make_booking(self, customer, period, car, location):
        if location.pickup is "":
            raise BookingError(location, period,
                               "Specify a valid start location")
        if location.dropoff is None:
            raise BookingError(location, period,
                               "Specify a valid end location")
        """ if period is None: 
            raise BookingError(location, period,"Specify a valid start date")
        if period is None:
            raise BookingError(location, period,"Specify a valid end date")"""
        if period <= 0:
            raise BookingError(location, period,
                               "Specify a valid booking period")

        print("hello")
        new_booking = Booking(customer, period, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 18
0
    def make_booking(self, customer, start, end, car, pickup, dropoff):

        if (start is None):
            raise BookingException('start_date', 'Specify a valid start date ')
        if (end is None):
            raise BookingException('end_date', 'Specify a valid end date ')
        if (pickup is None):
            raise BookingException('pickup', 'Specify a valid pickup ')
        if (dropoff is None):
            raise BookingException('dropff', 'Specify a valid dropoff ')
        date_format = "%Y-%m-%d"
        start_date = datetime.strptime(start, date_format)
        end_date = datetime.strptime(end, date_format)
        if (start_date > end_date):
            raise BookingException('period', 'Specify valid booking period')
        location = Location(pickup, dropoff)
        new_booking = Booking(customer, start_date, end_date, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking
Esempio n. 19
0
def book_appointment(provider, centre):
    provider = system.get_user_by_id(provider)
    centre = system.hc_manager.get_HC_by_name(centre)
    # 404 if provider or centre does not exist in our system.
    if not provider or not centre:
        abort(404)

    booking_date = request.args.get("date")
    if booking_date:
        # Validate date
        try:
            year, month, day = booking_date.split("-")
            booking_date = date(int(year), int(month), int(day))
            if booking_date < datetime.now().date():
                raise Exception("date provided is before current date.")
        except (ValueError, Exception) as e:
            flash("Invalid date: " + str(e))
            return render_template("book_appointment.html",
                                   provider=provider,
                                   centre=centre)
        times = system.booking_system.booking_availabilities(
            provider, booking_date)
        # Handle submitted forms
        if request.method == "POST":
            form = BookingForm(request.form)
            if form.validate():
                booking_datetime = datetime.combine(booking_date,
                                                    form.time.data)
                if booking_datetime > datetime.now():
                    loader = CSVLoader(app.root_path)
                    new_booking = Booking(centre, provider, booking_datetime,
                                          copy(current_user), form.note.data)
                    booking_system.make_booking(new_booking)
                    loader.write_booking(new_booking)
                    flash("Booking Successful!")
                    return redirect(url_for("appointments"))
                else:
                    flash("Appointments cannot be made in the past.")
            else:
                flash(form.errors)
            return render_template(
                "book_appointment.html",
                times=times,
                provider=provider,
                centre=centre,
                date=request.args.get("date"),
                note=form.note.data,
            )
        # If a valid booking_date was provided but it's a GET request
        else:
            return render_template(
                "book_appointment.html",
                times=times,
                provider=provider,
                centre=centre,
                date=request.args.get("date"),
            )
    # No valid date provided
    if booking_date == "":
        flash("Please enter a date.")
    return render_template("book_appointment.html",
                           provider=provider,
                           centre=centre)
Esempio n. 20
0
def test_booking():    
  for car in car_list:
    booking = Booking(user,diff,car,location)
    assert booking.location == location
    assert booking.customer == user
    assert booking.period == diff
Esempio n. 21
0
 def anadir_alojamiento(self, e=0):
     if e:
         return False
     s = Booking()
     return s.confirm_reserve(self.user, self.hoteles)
Esempio n. 22
0
 def make_booking(self, customer, period, car, location):
     new_booking = Booking(customer, period, car, location)
     self._bookings.append(new_booking)
     car.add_booking(new_booking)
     return new_booking
Esempio n. 23
0
                cars.append(car)
        return cars

    def make_booking(self, customer, period, car, location):
    
        if location.pickup = NULL || location.dropoff = NULL:
            return
        if period.end is before period.start:
            return
        try:
            if location is NULL:
                raise BookingError(customer, period, car, NULL)
            if period is NULL: 
                raise BookingError(customer, NULL, car, location)
                
        new_booking = Booking(customer, period, car, location)
        self._bookings.append(new_booking)
        car.add_booking(new_booking)
        return new_booking

    class BookingError(Exception):
        def __init__(self, customer, period = NULL, car, location = NULL):
            if period is NULL:
                print("Specify a valid period\n")
            if location is NULL:
                print("Specify a valid location\n")               
    
    def get_customer(self, username):
        """
        Just returns the first customer, should do a search but not
        needed for this use case. Will break if no customers in list