Example #1
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()
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"
Example #3
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()
Example #4
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()
Example #5
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()
Example #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()
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"
Example #8
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()
Example #9
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()