示例#1
0
    def reserva_vol(self, user):
        skyscanner = Skyscanner()

        if self.dataVolOK() and skyscanner.confirm_reserve(user, self):
            return True
        else:
            return False
示例#2
0
 def confirmaReserva_vol(self): 
     if not self.lista_vuelos:
         return 0
     for vuelo in self.lista_vuelos:
         if vuelo.dataVolOK() == False:
             raise ValueError("Error: La reserva de vols ha fallat")
         sksc = Skyscanner()
         sksc.confirm_reserve(self.user, vuelo)
     return True
示例#3
0
    def anadir_reserva_1(self, e=0, reintentos=0, max=0):
        if e:
            return False
        if reintentos:
            return False
        if max >= 3:
            exit(0)

        s = Skyscanner()
        return s.confirm_reserve(self.user, self.vuelos)
    def test3(self):
        aux1 = Vuelos(destino='BCN')
        aux2 = Vuelos(destino='ITA')
        aux_vuelo = [aux1, aux2]

        x = Viajes(user=User,
                   lista_pasajeros=['p1', 'p2', 'p3'],
                   vuelos=aux_vuelo)
        aux = User('Pol', '12345678J', '08390', '123456789', '*****@*****.**')

        fallo = x.anadir_reserva(1)
        sky = Skyscanner()
        sky.confirm_reserve = MagicMock(return_value=False)

        assert sky.confirm_reserve(aux, aux_vuelo) == fallo
示例#5
0
    def _fetch_ticket_price() -> float:
        """ Call the Skyscanner API and request the price of a flight ticket

        This process is extremely simplified, in a real world
        scenario we should retrieve the price for each different flight

        :return: the price of a single flight ticket
        """

        return Skyscanner.fetch_ticket_price()
示例#6
0
 def mock_confirm_payment(*args):
     retries = 0
     while retries < DEFAULT_MAX_RETRIES:
         try:
             return retries, Skyscanner.confirm_reserve(*args)
         except ConnectionRefusedError:
             retries += 1
             if retries == DEFAULT_RETRIES:
                 monkeypatch.setattr(Skyscanner, "confirm_reserve",
                                     mock_skyscanner_success)
示例#7
0
    def mock_confirm_flights(*args):
        retries = 0
        while retries < DEFAULT_MAX_RETRIES:
            try:
                if Skyscanner.confirm_reserve(*args):
                    pass
            except ConnectionRefusedError:
                retries += 1

        return retries
示例#8
0
    def _confirm_flights(self) -> bool:
        """ Connect to the Skyscanner API and perform the payment

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

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

        retries = 0
        while retries < self.MAX_RETRIES:
            try:
                return Skyscanner.confirm_reserve(self._user,
                                                  self._travel._flights)
            except ConnectionRefusedError:
                retries += 1

        raise ConnectionRefusedError(Response.SKYSCANNER_ERROR)
示例#9
0
    def test_4(self):
        aux1 = Vuelos(destino='BCN')
        aux2 = Vuelos(destino='ITA')
        aux_vuelo = [aux1, aux2]

        x = Viajes(user=User,
                   lista_pasajeros=['p1', 'p2', 'p3'],
                   vuelos=aux_vuelo)
        aux = User('Pol', '12345678J', '08390', '123456789', '*****@*****.**')

        fallo = x.anadir_reserva_1(1, 1, 0)
        i = Skyscanner()
        i.confirm_reserve = MagicMock(return_value=False)

        acierto_reintento = x.anadir_reserva_1(0, 0, 1)
        j = Skyscanner()
        j.confirm_reserve = MagicMock(return_value=True)

        assert i.confirm_reserve(aux, aux_vuelo) == fallo
        assert j.confirm_reserve(aux, aux_vuelo) == acierto_reintento
示例#10
0
 def anadir_reserva(self, e=0):
     if e:
         return False
     s = Skyscanner()
     return s.confirm_reserve(self.user, self.vuelos)