Esempio n. 1
0
def UI():
    repo = CarRepository()
    repo.addCar(Car("Toyota", 2010, 2000))
    repo.addCar(Car("VW", 2000, 1500))
    repo.addCar(Car("Audi", 2019, 10000))

    printInstructions()
    while (True):
        choice = int(input("Enter your choice - "))
        if choice == 1:
            name = input("Enter the name of the car - ")
            year = int(input("Enter the year - "))
            price = int(input("Enter the price - "))
            repo.addCar(Car(name, year, price))

        if choice == 2:
            repo.printList()

        if choice == 3:
            year = int(input("Enter the year - "))
            repo.getByYear(year)

        if choice == 4:
            name = input("Enter the name - ")
            ok = repo.update(name)
            if ok == 1:
                print("The list after:")
                repo.printList()

        if choice == 0:
            print("The app is closing....")
            break
Esempio n. 2
0
    def add_car(self, idCar, model, year, NoKm, guarantee):
        '''
       Creates and add a car in the cars list.
       :param idCar: int, the car id
       :param model: str, the car model
       :param year: int, the year of acquisition
       :param NoKm: float, the number of km
       :param guarantee: str, in guarantee-yes/no
       :return: 
       '''
        errors = []

        if idCar in self.__repo.getAll():
            errors.append('Exista deja o masina cu id-ul []'.format(idCar))
        if year <= 0:
            errors.append('Anul fabricatiei trebuie sa fie strict pozitiv!')
        if NoKm < 0:
            errors.append('Numarul de km trebuie sa fie strict poztiv!')
        if guarantee not in ["da", "nu"]:
            errors.append("Garantia trebuie sa fie una dintre:da,nu.")
        if errors != []:
            raise ValueError(errors)
        car = Car(idCar, model, year, NoKm, guarantee)
        #self.__repo.addCar(self,car)
        self.__repo.addCar(car)
Esempio n. 3
0
    def add(self, id_client, name):

        car = Car(id_client, name)

        # TODO: validate

        self.__car_repo.add(car)
Esempio n. 4
0
def test_getter():
    car = Car(1, 'logan', 2010, 373772, True, True)
    assert car.get_model() == 'logan'
    assert car.get_year() == 2010
    assert car.get_km() == 373772
    assert car.get_guarantee() == True
    assert car.get_is_removed() == True
def test_car1():
    car = Car(1, "Mercedes", 2008, 123000, "da")
    assert car.getCarId() == 1
    assert car.getModel() == "Mercedes"
    assert car.getYear() == 2008
    assert car.getNoKm() == 123000
    assert car.getGuarantee() == "da"
Esempio n. 6
0
def update_car_test():
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    repoCar.eraseFile()
    car = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car.getCarId(), car.getModel(), car.getYear(),
                        car.getNoKm(), car.getGuarantee())
    assert car.getModel() == "Mercedes"
    car_service.update_car(1, "", "bmw", "", "", "")
    car1 = repoCar.getAll()[0]
    assert car1.getModel() == "bmw"
    repoCar.eraseFile()
Esempio n. 7
0
 def modify_guarantee(self):
     """
     Update of the warranty on each car: a car is under warranty if and only if it is maximum 3 years and
     maximum 60 000 km
     :return: -
     """
     cars = self.__car_repository.read()
     for car in cars:
         date = 2019 - car.get_year()
         if car.get_km() <= 60000 and date <= 3:
             new_car = Car(car.id_entity(), car.get_model(), car.get_year(),
                           car.get_km(), True, car.get_is_removed())
             self.__car_validator.validate_car(new_car)
             self.__car_repository.update(new_car)
         else:
             new_car = Car(car.id_entity(), car.get_model(), car.get_year(),
                           car.get_km(), False, car.get_is_removed())
             self.__car_validator.validate_car(new_car)
             self.__car_repository.update(new_car)
Esempio n. 8
0
def add_car_test():
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    assert len(repoCar.getAll()) == 0
    car = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car.getCarId(), car.getModel(), car.getYear(),
                        car.getNoKm(), car.getGuarantee())
    assert len(repoCar.getAll()) == 1
    repoCar.eraseFile()
Esempio n. 9
0
 def __readFile(self):
     '''
     Citeste o lista de masini dintr-un fisier.
     :return: lista de masini
     '''
     with open (self.__fileName, 'r') as f:
         try:
             for line in f:
                 str = line[:-1]
                 comp=str.split("/")
                 id=comp[0]
                 model=comp[1]
                 year=int(comp[2])
                 NoKm=float(comp[3])
                 #data=comp[3].split()
                 guarantee=comp[4]
                 c=Car(id,model,year,NoKm,guarantee)
                 self.__carsList.append(c)
         except Exception as e:
             print("fisierul este gol")
             f.close()
Esempio n. 10
0
 def update_car(self, new_car_id, new_car_model, new_car_year, new_car_km,
                new_car_guarantee, is_removed):
     """
     Update a Car object
     :param new_car_id: int
     :param new_car_model: string
     :param new_car_year: int
     :param new_car_km: int
     :param new_car_guarantee: bool
     :param is_removed: bool
     """
     if new_car_guarantee not in ['yes', 'no']:
         raise ValueError('Guarantee must be yes or no')
     if new_car_guarantee == 'yes':
         new_car_guarantee = True
     else:
         new_car_guarantee = False
     car = Car(new_car_id, new_car_model, new_car_year, new_car_km,
               new_car_guarantee, is_removed)
     self.__car_validator.validate_car(car)
     self.__car_repository.update(car)
Esempio n. 11
0
 def add_car(self, car_id, car_model, car_year, car_km, car_guarantee,
             is_removed):
     """
     Creates a car
     :param car_id: int
     :param car_model: string
     :param car_year: int
     :param car_km: int
     :param car_guarantee: bool
     :param is_removed: bool
     """
     if car_guarantee not in ['yes', 'no']:
         raise ValueError('Guarantee must be yes or no')
     if car_guarantee == 'yes':
         car_guarantee = True
     else:
         car_guarantee = False
     car = Car(car_id, car_model, car_year, car_km, car_guarantee,
               is_removed)
     self.__car_validator.validate_car(car)
     self.__car_repository.create(car)
Esempio n. 12
0
 def populate(self, n):
     """
     Creates n Car objects
     :param n: int
     :return: list of all cars from storage
     """
     list_of_id = []
     for car in self.__car_repository.read():
         car_id = car.id_entity()
         list_of_id.append(car_id)
     start_id = max(list_of_id) + 1
     for index in range(n):
         car_model = random.choice(
             ['Logan', 'Mercedes', 'BMW', 'Range Rover'])
         car_year = int(random.randint(1900, 2020))
         car_km = int(random.randint(0, 1000000))
         car_guarantee = random.choice(['yes', 'no'])
         car = Car(start_id, car_model, car_year, car_km, car_guarantee,
                   False)
         # self.__car_validator.validate_car(car)
         self.add_car(start_id, car_model, car_year, car_km, car_guarantee,
                      False)
         start_id += 1
     return self.__car_repository.read()
Esempio n. 13
0
def test_eq():
    car1 = Car(1, 'logan', 2010, 373772, True, True)
    car2 = Car(1, 'logan', 2010, 373772, True, True)
    assert car1 == car2
Esempio n. 14
0
def test_guarantee():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2008, 120000, "nu")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2018, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    dict1 = tran_service.guarantee()
    dict = {}
    dict[1200] = 0
    assert dict1 == dict
    repoTran.eraseFile()
    repoCar.eraseFile()
Esempio n. 15
0
def remove_car_test():
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    repoCar.eraseFile()
    car = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car.getCarId(), car.getModel(), car.getYear(),
                        car.getNoKm(), car.getGuarantee())
    assert len(repoCar.getAll()) == 1
    car2 = Car(2, "Audi", 2008, 130000, "da")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    assert len(repoCar.getAll()) == 2
    car_service.remove_car(car.getCarId())
    assert len(repoCar.getAll()) == 1
    repoCar.eraseFile()
Esempio n. 16
0
def test_order_car_desc():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2007, 120000, "da")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2001, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    l = car_service.order_car_desc()
    l1 = [car1, car2, car3]
    string = str(l1[:])
    comp = string.split(",")
    assert l == l1
    print(l)
    repoTran.eraseFile()
    repoCar.eraseFile()
Esempio n. 17
0
def test_update_car_garantie():
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    repoCar.eraseFile()
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2007, 120000, "da")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2001, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    car_service.update_cars_garantie()
    car = repoCar.getAll()[1]
    assert car1.getGuarantee() == "da"
    assert car.getGuarantee() == "nu"
    assert car3.getGuarantee() == "nu"
    repoCar.eraseFile()
Esempio n. 18
0
'''
from Repositories.Repository import GenericRepository
from Repositories.RentalRepository import RentalRepository
from Controller.ClientController import ClientController
from Controller.CarController import CarController
from Controller.RentalController import RentalController
from UI.Console import Console
from Domain.Client import Client
from Domain.Car import Car
from Repositories.ClientRepository import ClientRepository
from Repositories.CarRepository import CarRepository

repo_clients = ClientRepository()
repo_clients.add(Client("1", "client1"))
repo_clients.add(Client("2", "client2"))
repo_clients.add(Client("3", "client3"))

repo_cars = CarRepository()
repo_cars.add(Car("1", "car1"))
repo_cars.add(Car("2", "car2"))
repo_cars.add(Car("3", "car3"))

repo_rentals = RentalRepository()

ctrl_clients = ClientController(repo_clients)
ctrl_cars = CarController(repo_cars)
ctrl_rentals = RentalController(repo_clients, repo_cars, repo_rentals)

ui = Console(ctrl_cars, ctrl_clients, ctrl_rentals)

ui.show()
Esempio n. 19
0
 def validate_car(car: Car):
     """
     Function verify if an object respects some conditions and if it finds an irregularity raise an exception
     :param car: an Car object
     :return: exceptions
     """
     # VALUE ERROR
     if not isinstance(car.id_entity(), int):
         raise InvalidCarException("Car id {} is not int".format(
             car.id_entity()))
     if not isinstance(car.get_model(), str):
         raise InvalidCarException("Car model {} is not string".format(
             car.get_model()))
     if not isinstance(car.get_year(), int):
         raise InvalidCarException("Car year {} is not int".format(
             car.get_year()))
     if not isinstance(car.get_km(), int):
         raise InvalidCarException("Car kilometer {} is not int".format(
             car.get_km()))
     if car.id_entity() < 0:
         raise InvalidCarException("Car id must be a positive")
     if car.get_km() <= 0:
         raise InvalidCarException(
             "Car number of kilometer {} must be a positive "
             "number".format(car.get_km()))
     if car.get_year() <= 0:
         raise InvalidCarException("Car year {} must be a positive "
                                   "number".format(car.get_year()))
     if len("{}".format(car.get_model())) == 0:
         raise InvalidCarException("Car has to get a model ")
Esempio n. 20
0
def testCar():
    car = Car("08CJRER","FORD","Van",90)
    assert car.getNr() == "08CJRER"
    assert car.getModelName() == "FORD"
    assert car.getType() == "Van"
    assert car.getPricePerDay() == 90
def test_car2():
    car = Car(1, "Mercedes", 2008, 123000, "da")
    car.setId(2)
    assert car.getCarId() == 2
    car.setModel("BMW")
    assert car.getModel() == "BMW"
    car.setYear(2003)
    assert car.getYear() == 2003
    car.setNoKm(100000)
    assert car.getNoKm() == 100000
    car.setGuarantee("nu")
    assert car.getGuarantee() == "nu"
Esempio n. 22
0
    def update(self, id_car, new_name):

        new_car = Car(id_car, new_name)

        self.__car_repo.update(new_car)
Esempio n. 23
0
def test_search_car():
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    repoCar.eraseFile()
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2008, 120000, "nu")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2018, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    l = car_service.search_car("model", "Ford")
    assert l[0] == str(car2)
    repoCar.eraseFile()