class ParkService(ABC): def __init__(self): self.lotHandler = None @property def IsInitialized(self): return self.lotHandler is not None @abstractmethod def allow(self, car, slotNum): pass def InitializeParkingLot(self, capacity): if self.lotHandler is None: self.lotHandler = LotHandler(capacity) return ParkingLotInit.format(capacity), self.lotHandler else: raise Exception('Already Initialized Parking Lot') def CheckCarParkedAlready(self, car): return self.lotHandler.IsCarParked(car) def ShowStatus(self): return self.lotHandler.slots def RegNumsByColor(self, color): result = self.lotHandler.GetRegNumsByColor(color) return ', '.join(result) def SlotNumsByColor(self, color): result = self.lotHandler.GetSlotNumsByColor(color) return ', '.join(result) def SlotNumForRegNum(self, regNum): return self.lotHandler.GetSlotNumByRegNum(regNum)
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)