예제 #1
0
 def create(self, clientId, licenseNumber, make, model):
     car = Car(clientId, licenseNumber, make, model)
     self._validator.validate(car)
     self._repository.store(car)
     '''
     If the operation did not raise an Exception, then we record it for Undo/Redo
     '''
     self._operations.append(AddOperation(car))
     self._index += 1
     self._undoController.recordUpdatedControllers([self])
예제 #2
0
 def _loadFromFile(self):
     try:
         f = open(self._fName, "r")
     except IOError:
         return
     line = f.readline().strip()
     while line != "":
         t = line.split(";")
         c = Car(int(t[0]), t[1], t[2], t[3])
         Repository.store(self, c)
         line = f.readline().strip()
     f.close()
예제 #3
0
    def create(self, carId, licensePlate, carMake, carModel):
        car = Car(carId, licensePlate, carMake, carModel)
        self.__repository.store(car)

        '''
        If the operation did not raise an Exception, then we record it for Undo/Redo
        '''
        redo = FunctionCall(self.create, carId,
                            licensePlate, carMake, carModel)
        undo = FunctionCall(self.delete, carId)
        cascadeOp = CascadedOperation(Operation(redo, undo))
        self._undoController.recordOperation(cascadeOp)
        return car
예제 #4
0
 def _loadFile(self):
     '''
     1. Open self._fileName fro text file reading
     2. For each line in input file:
         -> separate into tokens (by commas)
         -> build the car from the input
         -> store the car in the Repo
     3. Close input file
     :return: -
     '''
     with open(self._fileName, "r") as f:
         lines = f.readlines()
         for line in lines:
             line = line.strip()
             tokens = line.split(',')
             newCar = Car(*tokens)
             self.store(newCar)
         f.close()
예제 #5
0
 def setUp(self):
     self.v = CarValidator()
     self.c = Car("1", "AB 01 RTY", "Dacia", "Duster")
예제 #6
0
class CarValidatorTestCase(unittest.TestCase):
    '''
    A unit test example
    '''
    def setUp(self):
        self.v = CarValidator()
        self.c = Car("1", "AB 01 RTY", "Dacia", "Duster")

    def testCarValidator(self):
        self.assertTrue(self.v.validate, self.c)
        self.c.setMake("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setMake("Dacia")
        self.c.setModel("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)

    def testCarLicenseValidatorBlackBox(self):
        self.c.setLicenseNumber("AB 01 ABC")
        self.assertTrue(self.v.validate, self.c)

        self.c.setLicenseNumber("B 101 ABC")
        self.assertTrue(self.v.validate, self.c)

        self.c.setLicenseNumber("TY 01 ABC")
        self.assertTrue(self.v.validate, self.c)

        self.c.setLicenseNumber("CJ 121 AABC")
        self.assertTrue(self.v.validate, self.c)
        '''
        and so on...
        '''

    def testCarLicenseValidatorWhiteBox(self):
        '''
        Testing for license plate tokens
        '''
        self.c.setLicenseNumber("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 01")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 02 AAB S")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("AB 02 MMS")
        self.assertTrue(self.v.validate, self.c)
        '''
        Testing for counties
        '''
        self.c.setLicenseNumber("X 02 MMS")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("XMAS 02 MMS")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        '''
        Testing for number part
        '''
        self.c.setLicenseNumber("AB 223 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("B 1 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        '''
        Testing for special Bucharest case
        '''
        self.c.setLicenseNumber("AB 223 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("B 223 MKJ")
        self.assertTrue(self.v.validate, self.c)
        '''
        Test for letter combination length & validity
        '''
        self.c.setLicenseNumber("AB 22 AA")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 AAAB")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("AB 22 AAQ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 IOP")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 OIP")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
예제 #7
0
def init_cars():
    (licensePlate, makeList, modelList) = carListGenerator()
    for index in range(0, len(licensePlate)):
        carRepo.store(
            Car(index + 1, licensePlate[index], makeList[index],
                modelList[index]))
예제 #8
0
'''
from repository.ClientCSVFileRepository import ClientCSVFileRepository
from repository.CarCSVFileRepository import CarCSVFileRepository
from repository.RentalCSVFileRepository import RentalCSVFileRepository
from repository.PickleFileRepository import PickleFileRepository
'''
from repository.CarTextRepository import *
from domain.Car import Car

carRepo = CarTextRepository('cars.txt')
carRepo.store(Car(100, 'cj 01 uyc', 'Dacia', 'Duster'))
carRepo.store(Car(102, 'cj 01 xyz', 'Dacia', 'Duster'))
print(carRepo)
'''
carRepo = None
clientRepo = None
rentalRepo = None

print('-' * 10 + " Clients " + '-' * 10)
print(clientRepo)
print('-' * 10 + " Cars " + '-' * 10)
print(carRepo)
print('-' * 10 + " Rentals " + '-' * 10)
print(rentalRepo)
'''
예제 #9
0
 def create(self, carId, licensePlate, carMake, carModel):
     car = Car(carId, licensePlate, carMake, carModel)
     self.__validator.validate(car)
     self.__repository.store(car)
     return car
예제 #10
0
 def setUp(self):
     self.v = CarValidator()
     self.c = Car("1", "AB 01 RTY", "Dacia", "Duster")
예제 #11
0
class CarValidatorTestCase(unittest.TestCase):
    '''
    A unit test example
    '''
    def setUp(self):
        self.v = CarValidator()
        self.c = Car("1", "AB 01 RTY", "Dacia", "Duster")
    
    def testCarValidator(self):
        self.assertTrue(self.v.validate, self.c)
        self.c.setMake("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setMake("Dacia")
        self.c.setModel("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)        

    def testCarLicenseValidatorBlackBox(self):
        self.c.setLicenseNumber("AB 01 ABC")
        self.assertTrue(self.v.validate, self.c)
        
        self.c.setLicenseNumber("B 101 ABC")
        self.assertTrue(self.v.validate, self.c)
        
        self.c.setLicenseNumber("TY 01 ABC")
        self.assertTrue(self.v.validate, self.c)
                
        self.c.setLicenseNumber("CJ 121 AABC")
        self.assertTrue(self.v.validate, self.c)
        '''
        and so on...
        '''

    def testCarLicenseValidatorWhiteBox(self):
        '''
        Testing for license plate tokens
        '''
        self.c.setLicenseNumber("")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 01")
        self.assertRaises(ValidatorException, self.v.validate, self.c)        
        self.c.setLicenseNumber("CJ 02 AAB S")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("AB 02 MMS")
        self.assertTrue(self.v.validate, self.c)
        '''
        Testing for counties
        '''
        self.c.setLicenseNumber("X 02 MMS")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("XMAS 02 MMS")
        self.assertRaises(ValidatorException, self.v.validate, self.c)                
        '''
        Testing for number part
        '''
        self.c.setLicenseNumber("AB 223 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("B 1 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)        
        '''
        Testing for special Bucharest case
        '''
        self.c.setLicenseNumber("AB 223 MKJ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("B 223 MKJ")
        self.assertTrue(self.v.validate, self.c)
        '''
        Test for letter combination length & validity
        '''
        self.c.setLicenseNumber("AB 22 AA")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 AAAB")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("AB 22 AAQ")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 IOP")
        self.assertRaises(ValidatorException, self.v.validate, self.c)
        self.c.setLicenseNumber("CJ 23 OIP")
        self.assertRaises(ValidatorException, self.v.validate, self.c)