Example #1
0
def test_overdue_cars():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    rent = Rent("01.01.2021", "02.01.2021", "Thomas")
    car.rent = rent
    cars = [car]
    overdue = overdue_cars(cars)
    assert overdue == [car]
Example #2
0
def test_not_reserved_cars():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    reservation = Reservation("02.01.2021", "27.02.2021", "Thomas")
    car.add_reservation(reservation)
    car2 = Van("Van", "Volvo", "Splinter", "2", "Diesel, 14", "FWD", "1500L")
    cars = [car, car2]
    not_reserved = not_reserved_cars(cars)
    assert not_reserved == [car2]
Example #3
0
 def edit_add_to_database(self, item, info):
     """
     function that depending on input edits the item or adds new item into database
     converting input into class objects
     """
     name = self.ui.nameDatabase.text()
     type = self.ui.typeDatabase.text()
     brand = self.ui.brandDatabase.text()
     seats = self.ui.seatsDatabase.text().replace(" ", "")
     fuel_consumption = self.ui.fuelDatabase.text()
     drive_type = self.ui.driveDatabase.text()
     reservation = item.car.reservation
     rent = item.car.rent
     if type == "Van":
         volume = self.ui.volumeDatabase.text()
         car = Van(type, brand, name, seats, fuel_consumption, drive_type, volume, reservation, rent)
     elif type == "Truck":
         volume = self.ui.volumeDatabase.text()
         trailer = self.ui.trailerDatabase.text()
         if trailer == "True":
             trailer = True
         elif trailer == "False":
             trailer = False
         load = self.ui.loadDatabase.text()
         car = Truck(type, brand, name, seats, fuel_consumption, drive_type, volume, load, trailer, reservation, rent)
     else:
         car = Car(type, brand, name, seats, fuel_consumption, drive_type, reservation, rent)
     if info == "add":
         self.cars = add_to_database(car, self.cars)
     if info == "edit":
         item.car = car
         self.cars[item.car_index] = car
     self._setup_car_list(self.cars, "modify")
Example #4
0
def test_cars_as_dict():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    car2 = Van("Van", "Volvo", "Splinter", "2", "Diesel, 14", "FWD", "1500L")
    result = cars_as_dict([car, car2])
    dict = [
        {
            "Type": "Sportback",
            "Brand": "BMW",
            "Name": "X1",
            "Number of seats": "5",
            "Type of fuel and fuel Consumption per 100km": "Diesel, 7",
            "Drive Type": "AWD",
            "Additional": None,
            "Reservation": None,
            "Last reserved": None,
            "Rent": None
        },
        {
            "Type": "Van",
            "Brand": "Volvo",
            "Name": "Splinter",
            "Number of seats": "2",
            "Type of fuel and fuel Consumption per 100km": "Diesel, 14",
            "Drive Type": "FWD",
            "Additional": {
                "Max cargo volume": "1500L"
            },
            "Reservation": None,
            "Last reserved": None,
            "Rent": None
        }
    ]
    assert result == dict
Example #5
0
def test_search_availability():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    today = datetime.today()
    tommorow = today + timedelta(days=2)
    today = f'{datetime.now():%d.%m.%Y}'
    tommorow = f'{tommorow:%d.%m.%Y}'
    rent = Rent("9.01.2021", today, "Thomas")
    crit = {
        "Rent":
        {
            "Return date": tommorow
        }
    }
    car.rent = rent
    search = search_database(crit, [car])
    assert car in search
Example #6
0
def test_search_database():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    cars = [car]
    crit = {
        "Type": "Sportback",
        "Brand": "BMW"
    }
    search = search_database(crit, cars)
    assert car in search
Example #7
0
def test_car():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    assert car.type == 'Sportback'
    assert car.brand == "BMW"
    assert car.name == 'X1'
    assert car.seats == "5"
    assert car.fuel_consumption == "Diesel, 7"
    assert car.drive_type == "AWD"
    assert car.reservation is None
    assert car.rent is None
Example #8
0
def test_search_van():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    car2 = Van("Van", "Volvo", "Splinter", "2", "Diesel, 14", "FWD", "1500L")
    crit = {
        'Additional': {
            "Max cargo volume": "1500L"
        }
    }
    search = search_database(crit, [car, car2])
    assert search == [car2]
Example #9
0
def test_search_multiple():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    car2 = Van("Van", "Volvo", "Splinter", "2", "Diesel, 14", "FWD", "1500L")
    today = datetime.today()
    tommorow = today + timedelta(days=2)
    today = f'{datetime.now():%d.%m.%Y}'
    tommorow = f'{tommorow:%d.%m.%Y}'
    reservation = Reservation("9.01.2021", today, "Thomas")
    rent = Rent("9.01.2021", today, "Thomas")
    crit = {
        "Rent":
        {
            "Return date": tommorow
        }
    }
    car.rent = rent
    car2.add_reservation(reservation)
    search = search_database(crit, [car, car2])
    assert search == [car, car2]
def read_from_json(file_handle):
    """
    function used to read from database
    returns a list
    """
    cars = []
    data = json.load(file_handle)
    for item in data:
        seats = item['Number of seats']
        name = item['Name']
        fuel_consumption = item['Type of fuel and fuel Consumption per 100km']
        type = item['Type']
        brand = item['Brand']
        drive_type = item['Drive Type']
        additional = item['Additional']
        reservation = item['Reservation']
        last_reserved = item['Last reserved']
        rent = item['Rent']

        if reservation is not None:
            reservation_date = item['Reservation']['Reservation date']
            due_reservation_date = item['Reservation']['Due Reservation Date']
            who_reserved = item['Reservation']['Who reserved']
            reservation = Reservation(reservation_date, due_reservation_date,
                                      who_reserved)
        else:
            reservation = None

        if rent is not None:
            rent_date = item['Rent']['Rent date']
            return_date = item['Rent']['Return date']
            who_rented = item['Rent']['Who rented']
            overdue = item['Rent']['Is overdue']
            rent = Rent(rent_date, return_date, who_rented, overdue)
        else:
            rent = None

        if type == "Truck":
            load = additional['Load']
            trailer = additional['Has trailer']
            volume = additional['Max cargo volume']
            car = Truck(type, brand, name, seats, fuel_consumption, drive_type,
                        volume, load, trailer, reservation, rent,
                        last_reserved)
        elif type == "Van":
            volume = additional['Max cargo volume']
            car = Van(type, brand, name, seats, fuel_consumption, drive_type,
                      volume, reservation, rent, last_reserved)
        else:
            car = Car(type, brand, name, seats, fuel_consumption, drive_type,
                      reservation, rent, last_reserved)
        cars.append(car)
    return cars
Example #11
0
def test_car_add_reservation_twice():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    reservation = Reservation("02.01.2021", "09.01.2021", "Thomas")
    car.add_reservation(reservation)
    assert car.reservation == reservation
    assert car.last_reserved() == f'{datetime.now():%d.%m.%Y}'
    assert car.add_reservation(reservation) == "Cannot reserve today"
Example #12
0
def test_car_add_reservation_expired():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    reservation = Reservation("02.01.2021", "06.01.2021", "Thomas")
    car.add_reservation(reservation)
    assert car.reservation.check_expiration() == "EXPIRED"
Example #13
0
def test_write_to_database():
    file = StringIO()
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    car2 = Van("Van", "Volvo", "Splinter", "2", "Diesel, 14", "FWD", "1500L")
    cars = [car, car2]
    write_to_json(cars, file)
Example #14
0
def test_search_empty_crit():
    car = Car("Sportback", "BMW", "X1", "5", "Diesel, 7", "AWD")
    cars = [car]
    crit = {}
    search = search_database(crit, cars)
    assert search == []