def test_modificar_hotel_calcular_preu(self): p = Viatgers(4) past = p.get_num_viatgers() h1 = Hotel("SVC_1", "ATENEA", past, 5, 23) h2 = Hotel("SVC_2", "IBIS", past, 7, 34) hotels = [h1] H = Hotels(hotels) H.modifica_hotel(h1, h2) test_preu = 952.0 self.assertEqual(H.calcul_import_total_hotels(), test_preu)
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
def test_eliminar_hotel_calcular_preu(self): p = Viatgers(4) past = p.get_num_viatgers() h1 = Hotel("SVC_1", "ATENEA", past, 5, 23) h2 = Hotel("SVC_2", "IBIS", past, 7, 34) h3 = Hotel("SVC_3", "KINGH", past, 4, 15) hotels = [h1, h2, h3] H = Hotels(hotels) H.elimina_hotel("KINGH") test_preu = 1412.0 self.assertEqual(H.calcul_import_total_hotels(), test_preu)
def test_4(self): aux1 = Hotels(nombre_hotel='Vela') aux2 = Hotels() aux_alojamiento = [aux1, aux2] n_viajeros = 3 x = Viajes(lista_pasajeros=['p1', 'p2', 'p3'], hoteles=aux_alojamiento) x.eliminar_alojamiento('Vela') precio = x.precio precio_total = precio * n_viajeros precio_total = len(aux_alojamiento) * precio * n_viajeros assert precio_total == x.calcular_precio()
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
def test_7(self): aux1 = Hotels(nombre_hotel='Vela') aux2 = Hotels() aux_alojamiento = [aux1, aux2] user = User('Pepito Los Palotes', '12345678P', '08390', '678942316', '*****@*****.**') x = Viajes(user=user, lista_pasajeros=['p1', 'p2', 'p3'], hoteles=aux_alojamiento) datos = x.anadir_alojamiento() x.anadir_alojamiento = MagicMock(return_value=True) assert datos == x.anadir_alojamiento()
def test_confirmaReservaHotelsError(self): with pytest.raises(ValueError): viaje1 = Viaje(usr, 2) viaje1.addDestino(vuelo_2) viaje1.addDestino(vuelo_1) viaje1.añadirHotel(hotel_2) viaje1.añadirHotel( Hotels("2", "Talavera de la Reina", "C/ Lope de Vega 27", 60, 1, 1)) viaje1.confirmaReserva_hotel()
def test_hotels_ctor(default_hotel_list: list): """ Test case for Hotels.__init__(**) method Tests the constructor of the Hotels class EXPECTED BEHAVIOUR: The object is instantiated with the default values """ hotels = Hotels(default_hotel_list) assert len(hotels) != 0 assert len(hotels) == DEFAULT_HOTELS_LEN
def test_comprovacio_tipus_tarjeta_incorrecte(self): p = Viatgers(4) past = p.get_num_viatgers() f = Vol("1234ABC", "MILAN", past, 10.0) f2 = Vol("5467DEF", "PARIS", past, 20.0) Vtg = [f, f2] v = Flights(past, Vtg) c1 = Car("COTXE1", "FERRARI", "MILAN", past, 30.0) cot = [c1] c = Cars(past, cot) h1 = Hotel("HOTEL1", "MILANO", past, 4, 20.0) h2 = Hotel("HOTEL2", "LE PARIS", past, 6, 25.0) hot = [h1, h2] h = Hotels(hot) p2 = PaymentData("PAYPAL", "Samu", "123456789", "ABC", v, c, h) self.assertEqual(p2.comprobar_targeta(), False)
def test_calcula_preu(self): p = Viatgers(4) past = p.get_num_viatgers() f = Vol("1234ABC", "MILAN", past, 10.0) f2 = Vol("5467DEF", "PARIS", past, 20.0) Vtg = [f, f2] v = Flights(past, Vtg) c1 = Car("COTXE1", "FERRARI", "MILAN", 4, 30.0) cot = [c1] c = Cars(past, cot) h1 = Hotel("HOTEL1", "MILANO", past, 4, 20.0) h2 = Hotel("HOTEL2", "LE PARIS", past, 6, 25.0) hot = [h1, h2] h = Hotels(hot) p = PaymentData("Visa", "Ruben", "1234", "1342", v, c, h) self.assertEqual(p.get_import_total(), 1160.0)
def test_rm(self, mock_os, mock_path): # create the Class objHotel = Hotels() # set up the mock mock_path.isfile.return_value = False objHotel.rm("dummy path") # test the remove call is NOT called. self.assertFalse(mock_os.remove.called, "Error removing the file if not present.") # make the file 'exist' mock_path.isfile.return_value = True objHotel.rm("dummy path") mock_os.remove.assert_called_with("dummy path")
class TestHotels(unittest.TestCase): def setUp(self) -> None: self.hotel = Hotel(1234, 'Royal Palace', 5, 2, 7, 50) self.hotels = Hotels() self.hotels.añadir_hotel(self.hotel) def test_viaje_añadir_alojamiento(self): self.assertEqual(50, self.hotels.getpreciototal()) def test_viaje_eliminar_alojamiento(self): hotel = Hotel(4321, 'Port Aventura Hotel', 5, 2, 4, 100) hotel2 = Hotel(4321, 'Port Aventura Hotel', 5, 2, 4, 200) self.hotels.añadir_hotel(hotel) self.hotels.añadir_hotel(hotel2) self.hotels.eliminar_hotel(hotel) self.hotels.eliminar_hotel(hotel2) self.assertEqual(50, self.hotels.getpreciototal())
def default_hotels(default_hotel_list): """ Fixture to create a Hotels object from a default hotel list. """ return Hotels(default_hotel_list)
def testCasAfegir(self): vol = Flights() # "EF325F","Roma", 2, 50, 1 -> preu 101 vol.__codiVol__ = "EF325F" vol.__desti__ = "ROMA" vol.__numPassatgers__ = 2 vol.__importv__ = 50 vol.__taxav__ = 1 # hotel1 preu 250 hotel1 = Hotels() hotel1.__codi__ = 34 hotel1.__nom__ = "Hotel de la vila" hotel1.__numHostes__ = 2 hotel1.__numHabitacions__ = 1 hotel1.__durada__ = 10 hotel1.__importh__ = 20 hotel1.__taxah__ = 50 # hotel2 preu 350 hotel2 = Hotels() hotel2.__codi__ = 35 hotel2.__nom__ = "Hotel de la vila" hotel2.__numHostes__ = 2 hotel2.__numHabitacions__ = 1 hotel2.__durada__ = 10 hotel2.__importh__ = 30 hotel2.__taxah__ = 50 viatge = Viatge() viatge.__numPersones__ = 2 viatge.__VolsReservar__.append(vol) viatge.gestioallotjaments(0, hotel1) self.assertEqual(viatge.__dadesPagament__.__import__, 351) viatge.gestioallotjaments(0, hotel2) self.assertEqual(viatge.__dadesPagament__.__import__, 701)
from src.Viaje import Viaje from src.Cars import Cars from src.User import User from src.Flights import Flights from src.Hotels import Hotels from src.PaymentData import PaymentData usr = User("Jesus Gil y Gil", "75245896W", "654879524", "Calle Alamo 23, Marbella", "*****@*****.**") car_1 = Cars("1234ABC", "Suv", "BMW", "Calle Falsa 123", "Aeropuerto", 7, 150) car_2 = Cars("5089PFE", "Deportivo", "Audi", "Plaza del Pueblo", "Aeropuerto", 4, 70) car_3 = Cars("6205MOA", "Familiar", "Renault", "Calle Karl Marx", "Aeropuerto", 2, 25) hotel_1 = Hotels(1, "Jerez de la Frontera", "Morenos, 10, 11402 Jerez de la Frontera, España", 26, 7, 1) hotel_2 = Hotels(2, "Talavera de la Reina", "Roma, 1, 45600 Talavera de la Reina, España", 62, 7, 1) vuelo_1 = Flights("15612F", "MADRID", 55) vuelo_2 = Flights("68745A", "ESTAMBUL", 90) vuelo_3 = Flights("86452T", "LONDRES", 85) class test_viatje_v3(unittest.TestCase): def test_sumaPrecioAñadirCoche(self): viaje = Viaje(usr, 3) viaje.añadirCoche(car_1) viaje.añadirCoche(car_2) viaje.añadirCoche(car_3) self.assertEqual(viaje.calculaPrecioCoche(), 1380)
def setUp(self) -> None: self.hotel = Hotel(1234, 'Royal Palace', 5, 2, 7, 50) self.hotels = Hotels() self.hotels.añadir_hotel(self.hotel)