def main(): car_1 = Car(tire_wash_strategy=WithoutBubbles(), carbody_wash_strategy=WithWax()) car_1(car_model="Fiat Punto", wheel_diameter="16") car_2 = Car(WithBubbles(), WithoutWax()) car_2(car_model="Volkswagen Passat", wheel_diameter="16")
def find(self): print("Znajdź pojazd") print("-----------------") register_number = input('Numer rejestracyjny: ') try: status = input('(opcja) Status [d] - dostępny, [n] - niedostępny: ') except ValueError: status = None if status: cars = Car().select().where( (Car.register_number == register_number) & (CarStatus.name == ('Dostępny' if status == 'd' else 'Wypożyczony')) ).join(CarStatus) else: cars = Car().select().where(Car.register_number == register_number) result: List[Car] = [] for car in cars: result.append(car) print(car.id, car, car.status) return result
def test_car_parked_already(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') duplicateCar = Car('KA-01-HH-1234', 'White') # Act lh.FillSlot(firstCar, 1) lh.FillSlot(duplicateCar, 2) # Assert self.assertTrue(lh.IsCarParked(duplicateCar))
def test_vaccate_slot(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') secondCar = Car('KA-01-BB-0001', 'Red') lh.FillSlot(firstCar, 1) lh.FillSlot(secondCar, 2) slotNumToVaccate = 1 lh.VaccateSlot(slotNumToVaccate) self.assertTrue(slotNumToVaccate in lh.freeSlots) self.assertTrue(2 not in lh.freeSlots)
def test_vaccate_slot_not_present(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') secondCar = Car('KA-01-BB-0001', 'Red') lh.FillSlot(firstCar, 1) lh.FillSlot(secondCar, 2) slotNumToVaccate = 3 with self.assertRaises(ValueError) as ex: lh.VaccateSlot(slotNumToVaccate) self.assertEqual(ex.exception, 'No such Slot Number found in Parking lots')
def import_data(car_instance_list: list, driver_instance_list: list) -> None: """ Import saved data into the respective instance lists Args: car_instance_list (list): Car instance list driver_instance_list (list): Driver instance list """ try: with open("data/cars.json", 'r') as cars_file: json_ = json.load(cars_file) cars_ = json_["cars"] for car_ in cars_: car_instance_list.append( Car(car_["id"], car_["reg"], car_["brand"], car_["hp"], car_["kms"])) except FileNotFoundError: from ui.console_messages import warning warning("cars.json doesn't exist! -> Cars not loaded") try: with open("data/drivers.json", 'r') as drivers_file: json_ = json.load(drivers_file) drivers_ = json_["drivers"] for driver_ in drivers_: car_for_driver = return_right_car(driver_["car_id"], car_instance_list) driver_instance_list.append( Driver(driver_["id"], driver_["name"], driver_["age"], car_for_driver)) except FileNotFoundError: from ui.console_messages import warning warning("drivers.json doesn't exist! -> Drivers not loaded loaded")
def park_car(self, registration_number, color): """ :param registration_number: Registration Number of the car :param color: Color of the car :return: Desc: 1. Creates a car object with given details of the car 2. Checks for the availability of the slot 3. If available assigns the Slot and returns the associated slot number 4. Else returns the error message """ if not self.parking_lot.are_slots_available(): # no slots are available i.e parking lot is full and cannot accomadate any more cars return errors.PARKING_LOT_IS_FULL if self.check_car_already_parked( registration_number=registration_number): return errors.CAR_ALREADY_PARKED car = Car(regnumber=registration_number, color=color) slot = self.parking_lot.get_available_slot() if not slot: return errors.PARKING_LOT_IS_FULL self.parking_lot.allocate_parking(car=car, slot=slot) return 'Allocated slot number: {}'.format(slot.slotNumber)
def test_check_car_already_parked(self): s = EntryService() s.InitializeParkingLot(4) s.lotHandler.IsCarParked = MagicMock(return_value=True) result = s.CheckCarParkedAlready(Car('KA-01-HH-1234', 'White')) self.assertTrue(result)
def seed_cars(self): for c in cars: car = Car( plate=c["plate"], client_id=c["client_id"], ) session.add(car)
def post(self): carBusiness = CarBusiness() car = request.json['car'] new_car = Car(car['model'], car['brand'], car['price'], car['year'], car['car_type']) car = carBusiness.saveCar(new_car) return car, 201
def test_is_slot_available(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') # Act filledSlot = lh.FillSlot(firstCar, 1) # Assert self.assertFalse(lh.IsSlotAvailable(filledSlot.SlotNum)) self.assertTrue(lh.IsSlotAvailable(2))
def test_get_nearest_slot(self): # Arrange lh = LotHandler(4) car1 = Car('KA-01-HH-1234', 'White') car2 = Car('KA-04-HH-1231', 'Blue') car3 = Car('KA-04-HH-1231', 'Red') car4 = Car('KA-04-HH-1231', 'Blue') lh.FillSlot(car1, 1) lh.FillSlot(car2, 2) lh.FillSlot(car3, 3) lh.FillSlot(car4, 4) lh.VaccateSlot(2) lh.VaccateSlot(4) # Act val = lh.GetNearestSlot() # Assert self.assertEqual(val, 2)
def select_all(): cars = [] sql = "SELECT * FROM cars ORDER BY mot_renewal_date ASC, registration_number ASC" results = run_sql(sql) for row in results: car = Car(row['registration_number'], row['make'], row['model'], row['mot_renewal_date'], row['id']) cars.append(car) return cars
def test_allow_entry_parking_lot_full(self): # Arrange car = Car('KA-01-HH-1234', 'White') s = EntryService() s.InitializeParkingLot(6) s.lotHandler.IsLotFull = MagicMock(return_value=True) # Act status = s.allow(car) # Assert self.assertEqual(status, 'Sorry, parking lot is full')
def test_fill_slot_invalid_slot_num(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') # Act with self.assertRaises(ValueError) as ex: lh.FillSlot(firstCar, 3) # Assert self.assertEqual('No Such Slot Number foudn in Parking Lot', str(ex.exception))
def test_update_car_coordinates_when_called_with_same_ts_distance_equals_0( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 0, 'carIndex': 1, 'location': { 'lat': 1, 'long': 1 } } car.update_car_coordinates(car_coords) assert car.distance_travelled == 0
def test_update_car_coordinates_when_called_with_same_coords_speed_equals_0( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 1, 'carIndex': 1, 'location': { 'lat': 0, 'long': 0 } } car.update_car_coordinates(car_coords) assert car.curr_speed == 0
def test_update_car_coordinates_when_called_normally_returns_updated_ts( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 3600000, 'carIndex': 1, 'location': { 'lat': 0.01, 'long': 0 } } car.update_car_coordinates(car_coords) assert car.get_car_timestamp() == 3600000
def test_get_slot_num_by_reg_num(self): # Arrange lh = LotHandler(4) car1 = Car('KA-01-HH-1234', 'White') car2 = Car('KA-04-HH-1231', 'Blue') car3 = Car('KA-08-HH-1111', 'Red') car4 = Car('KA-02-HH-9999', 'Blue') lh.FillSlot(car1, 1) lh.FillSlot(car2, 2) lh.FillSlot(car3, 3) lh.FillSlot(car4, 4) expectedSlotNum = '2' # Act actualSlotNum = lh.GetSlotNumByRegNum('KA-04-HH-1231') actualNotFound = lh.GetSlotNumByRegNum('KA-04-HH-3333') # Assert self.assertEqual(expectedSlotNum, actualSlotNum) self.assertEqual('Not Found', actualNotFound)
def test_allow_re_park_car(self): # Arrange car = Car('KA-01-HH-1234', 'White') s = EntryService() s.InitializeParkingLot(6) s.lotHandler.IsCarParked = MagicMock(return_value=True) # Act status = s.allow(car) # Assert self.assertEqual( 'Cannot park already Parked Car: {0}'.format(car.RegNum), status)
def test_update_car_coordinates_when_called_normally_returns_correct_distance_travelled( self): car = Car(0, 0, 0, 1) car_coords = { 'timestamp': 3600000, 'carIndex': 1, 'location': { 'lat': 0.01, 'long': 0 } } # Calculated value of this transtion = 0.6870766960504942 car.update_car_coordinates(car_coords) assert car.distance_travelled == 0.6870766960504942
def select(id): car = None sql = "SELECT * FROM cars WHERE id = %s" values = [id] result = run_sql( sql, values )[0] # although only 1 row should be returned, making sure with the [0]..? if result is not None: car = Car(result['registration_number'], result['make'], result['model'], result['mot_renewal_date'], result['id']) return car
def create_car(): registration_number = request.form['registration_number'] make = request.form['make'] model = request.form['model'] mot_renewal_date = request.form['mot_renewal_date'] car = Car(registration_number, make, model, mot_renewal_date) # send request to save mechanic to database car_repository.save(car) # return to mechanics webpage return redirect('/cars')
def test_get_slot_nums_by_color(self): # Arrange lh = LotHandler(4) car1 = Car('KA-01-HH-1234', 'White') car2 = Car('KA-04-HH-1231', 'Blue') car3 = Car('KA-08-HH-1111', 'Red') car4 = Car('KA-02-HH-9999', 'Blue') lh.FillSlot(car1, 1) lh.FillSlot(car2, 2) lh.FillSlot(car3, 3) lh.FillSlot(car4, 4) expectedBlueSlots = ['2', '4'] expectedRedslots = ['3'] # Act actualBlueSlots = lh.GetSlotNumsByColor('Blue') actualRedSlots = lh.GetSlotNumsByColor('Red') actualYellowSlots = lh.GetSlotNumsByColor('Yellow') # Assert self.assertEqual(expectedBlueSlots, actualBlueSlots) self.assertEqual(expectedRedslots, actualRedSlots) self.assertEqual([], actualYellowSlots)
def test_fill_slot(self): # Arrange lh = LotHandler(2) firstCar = Car('KA-01-HH-1234', 'White') secondCar = Car('KA-01-HH-1231', 'Red') # Act filledSlot1 = lh.FillSlot(firstCar, 1) # Assert firstCar self.assertEqual(filledSlot1.SlotNum, 1) self.assertFalse(filledSlot1.IsAvailable) self.assertEqual(filledSlot1.ParkedCar, firstCar) self.assertFalse(lh.IsLotFull()) # Act secondCar filledSlot2 = lh.FillSlot(secondCar, 2) # Assert secondCar self.assertEqual(filledSlot2.SlotNum, 2) self.assertFalse(filledSlot2.IsAvailable) self.assertEqual(filledSlot2.ParkedCar, secondCar) self.assertTrue(lh.IsLotFull())
def test_get_reg_nums_by_color(self): # Arrange lh = LotHandler(4) car1 = Car('KA-01-HH-1234', 'White') car2 = Car('KA-04-HH-1231', 'Blue') car3 = Car('KA-04-HH-1231', 'Red') car4 = Car('KA-04-HH-1231', 'Blue') lh.FillSlot(car1, 1) lh.FillSlot(car2, 2) lh.FillSlot(car3, 3) lh.FillSlot(car4, 4) expectedBlueRegNums = ['KA-04-HH-1231', 'KA-04-HH-1231'] expectedRedRegNums = ['KA-04-HH-1231'] # Act actualBlueRegNums = lh.GetRegNumsByColor('Blue') actualRedRegNums = lh.GetRegNumsByColor('Red') actualYellowRegNums = lh.GetRegNumsByColor('Yellow') # Assert self.assertEqual(expectedBlueRegNums, actualBlueRegNums) self.assertEqual(expectedRedRegNums, actualRedRegNums) self.assertEqual([], actualYellowRegNums)
def post(self): """ Create new car. """ parsed_args = parser.parse_args() car = Car( plate=parsed_args["plate"], client_id=parsed_args["client_id"], brand=parsed_args["brand"], ) client = ( session.query(Client).filter(Client.id == parsed_args["client_id"]).first() ) client.cars.append(car) return self.finalize_post_req(car)
def test_allow_slot_unavailable(self): # Arrange car = Car('KA-01-HH-1234', 'White') s = EntryService() s.InitializeParkingLot(6) s.lotHandler.IsCarParked = MagicMock(return_value=False) s.lotHandler.IsLotFull = MagicMock(return_value=False) s.lotHandler.GetNearestSlot = MagicMock(return_value=1) s.lotHandler.IsSlotAvailable = MagicMock(return_value=False) # Act with self.assertRaises(ValueError) as ex: s.allow(car) # Assert self.assertEqual('Slot Not Available'.format(car.RegNum), str(ex.exception))
def test_allow_park_car(self): # Arrange car = Car('KA-01-HH-1234', 'White') s = EntryService() s.InitializeParkingLot(6) s.lotHandler.IsCarParked = MagicMock(return_value=False) s.lotHandler.IsLotFull = MagicMock(return_value=False) s.lotHandler.GetNearestSlot = MagicMock(return_value=1) s.lotHandler.IsSlotAvailable = MagicMock(return_value=True) slot = Slot(1) s.lotHandler.FillSlot = MagicMock(return_value=slot) # Act status = s.allow(car) # Assert self.assertEqual(status, 'Allocated slot number: {0}'.format(1))
def cars_repaired(mechanic): results = [] sql = """SELECT DISTINCT cars.* FROM cars INNER JOIN repairs ON repairs.car_id = cars.id INNER JOIN mechanics ON repairs.mechanic_id = mechanics.id WHERE mechanics.id = %s""" values = [mechanic.id] sql_results = run_sql(sql, values) for row in sql_results: car = Car(row['registration_number'], row['make'], row['model'], row['mot_renewal_date'], row['id']) results.append(car) return results