コード例 #1
0
def test_car_wash_repo():
    car_wash_list = RepoCarWash()
    car_wash = CarWash(1, "Bob")
    car_wash_list.store(car_wash)
    assert car_wash_list.get_all() is not None
    car_wash2 = CarWash(1, "Ian")
    car_wash_list.modify(car_wash2)
    assert car_wash_list.get(1) == car_wash2
    car_wash_list.delete(1)
    car_wash_list.store(car_wash)
    assert car_wash_list.get_all() is not None
コード例 #2
0
 def __load_from_file(self):
     file = open(self.__file_name, "r+")
     json_file = json.loads(file.read())
     if "car_wash" in json_file:
         for index in json_file["car_wash"]:
             id_car_wash = index["id"]
             name = index["name"]
             cars = index["cars"]
             car_wash = CarWash(id_car_wash, name)
             car_wash.set_cars(cars)
             self._list.append(car_wash)
     file.close()
コード例 #3
0
ファイル: test_car_wash.py プロジェクト: radu9917/Car_Wash
def test_car_wash_str():
    car_wash1 = CarWash(1, "Bob")
    car_wash2 = CarWash(1, "Bob")
    car1 = Car(1, "AG 67 NIG", "Ion")
    car_wash1.add_car(car1.get_id())
    car_wash2.add_car(car1.get_id())
    assert str(car_wash1) == str(car_wash2)
コード例 #4
0
ファイル: test_car_wash.py プロジェクト: radu9917/Car_Wash
def test_car_wash_getters():
    car_wash = CarWash(1, "BOB")
    car = Car(1, "IAN", "ION")
    car_wash.add_car(car.get_id())

    assert car_wash.get_id() == 1
    assert car_wash.get_name() == "BOB"
    assert car_wash.get_cars() == [car.get_id()]
コード例 #5
0
def test_json():
    car_repo = JsonRepoCar("test.json")
    car_wash_repo = JsonRepoCarWash("test.json")
    car_repo.delete(1)
    car_wash_repo.delete(1)
    car = Car(1, "AG 76 DYK", "Costi")
    car_repo.store(car)
    car_wash = CarWash(1, "Bob's")
    car_wash_repo.store(car_wash)
    assert car_wash == car_wash_repo.get(1)
    assert car == car_repo.get(1)
    assert len(car_repo.get_all()) == len(car_wash_repo.get_all())
    car_repo.modify(1, Car(1, "AG 69 COC", "Sorin"))
    car_wash_repo.modify(CarWash(1, "La Daniel"))
    car_r2 = JsonRepoCar("test_else.json")
    car_r2.store(car)
    car_w_r2 = JsonRepoCarWash("test_else2.json")
    car_w_r2.store(car_wash)
    car_r2.delete(1)
    car_w_r2.delete(1)
コード例 #6
0
ファイル: test_car_wash.py プロジェクト: radu9917/Car_Wash
def test_car_wash_eq():
    car_wash1 = CarWash(1, "Bob")
    car_wash2 = CarWash(1, "Bobul")
    car_wash3 = CarWash(1, "Bob")
    car_wash4 = CarWash(2, "Bob")
    car1 = Car(1, "AG 67 NIG", "Ion")
    car_wash3.add_car(car1.get_id())
    assert not car_wash1 == car_wash2
    assert not car_wash1 == car_wash3
    assert not car_wash1 == car_wash4
コード例 #7
0
def test_observer():
    car_list = RepoCar()
    car_wash_list = RepoCarWash()
    car = Car(1, "AG 67 NIG", "Radu")
    car_wash = CarWash(1, "Geani's")
    car.add_observer(car_wash)
    car_list.store(car)
    assert len(car_list.get_all()) == 1
    car_wash_list.store(car_wash)
    car_wash_list.get(1).add_car(car.get_id())
    assert len(car_wash_list.get(1).get_cars()) == 1
    car_list.delete(car.get_id())
    assert len(car_list.get_all()) == 0
    assert len(car_wash_list.get(1).get_cars()) == 0
コード例 #8
0
ファイル: console.py プロジェクト: radu9917/Car_Wash
 def modify_car_wash(self):
     correct = False
     while not correct:
         j = int(input("Choose a car wash to rename:"))
         name = input("Choose the name for the car wash")
         car_wash = CarWash(j, name)
         try:
             self.__service.modify_car_wash(car_wash)
             correct = True
             print(font_colors.OKGREEN + "Car wash successfully modified" +
                   font_colors.ENDC)
         except ValidationError as exp:
             print(font_colors.FAIL + "An error has occured: " + str(exp) +
                   font_colors.ENDC)
コード例 #9
0
ファイル: console.py プロジェクト: radu9917/Car_Wash
 def create_car_wash(self):
     nr = int(input("How many car washes do you wan to create"))
     while nr > 0:
         print("Create car wash:")
         index = int(input("Give index:"))
         name = input("Give name:")
         try:
             self.__service.create_car_wash(CarWash(index, name))
             nr -= 1
             print(font_colors.OKGREEN + "Car successfully added" +
                   font_colors.ENDC)
         except ValidationError as exp:
             print(font_colors.FAIL + "An error has occured: " + str(exp) +
                   font_colors.ENDC)
コード例 #10
0
def test_functions():
    repo_car = FileCarRepo("test_car.txt")
    repo_car_wash = FileCarWashRepo("test_car_wash.txt")
    service = Service(repo_car, repo_car_wash)
    # TEST CAR FUNCTIONS
    car1 = Car(1, "AG 25 DMG", "Ian")
    service.create_car(car1)
    file = open("test_car.txt", "r")
    read_car_line = file.readline()
    file.close()
    read_car = read_car_line.split(",")
    car2 = Car(int(read_car[0]), read_car[1], read_car[2].strip("\n"))
    assert car2 == car1
    car3 = Car(1, "AG 65 DYN", "Ionel")
    service.modify_car(1, car3)
    file = open("test_car.txt", "r+")
    read_car_line = file.readline()
    read_car = read_car_line.split(",")
    car4 = Car(int(read_car[0]), read_car[1], read_car[2].strip("\n"))
    assert car4 == car3
    service.delete_car(car3.get_id())
    assert service.get_all_car() is not None
    # TEST CAR WASH FUNCTIONS
    car_wash1 = CarWash(1, "At Bob")
    service.create_car_wash(car_wash1)
    assert service.get_car_wash(1) == car_wash1
    car_wash2 = CarWash(1, "La Geani")
    service.modify_car_wash(car_wash2)
    assert service.get_car_wash(1) == car_wash2
    service.delete_car_wash(1)
    assert service.get_all_car_wash() == []
    # TEST ADD AND REMOVE FUNCTIONS
    service.create_car_wash(car_wash1)
    service.create_car(car1)
    service.add_to_car_wash(1, 1)
    assert service.get_cars_in_car_wash(1)
    assert service.filter_by_number("AG")
    car_wash2 = service.get_car_wash(1)
    assert car_wash2.get_cars() == [car1.get_id()]
    service.remove_from_car_wash(car_wash1.get_id(), car1.get_id())
    car_wash2 = service.get_car_wash(1)
    assert car_wash2.get_cars() == []
    file2 = open("test_car_wash.txt", "w")
    file.truncate(0)
    file2.truncate(0)
    file.close()
    try:
        service.test_input("2", 12)
        assert True
    except ValidationError:
        assert False
コード例 #11
0
def test_load():
    car_repo = FileCarRepo("test_car.txt")
    car_wash_repo = FileCarWashRepo("test_car_wash.txt")
    car = Car(1, "AG 67 DYC", "Radu")
    car_wash = CarWash(1, "La Bob")
    car_wash.add_car(1)
    car_wash.add_car(2)
    car_repo.store(car)
    car_wash.add_car(car.get_id())
    car_wash_repo.store(car_wash)
    test_car_repo = FileCarRepo("test_car.txt")
    test_car_wash_repo = FileCarWashRepo("test_car_wash.txt")
    assert test_car_repo.get(1) == car
    assert test_car_wash_repo.get(1) == car_wash
    file1 = open("test_car.txt", "w")
    file2 = open("test_car_wash.txt", "w")
    file1.truncate(0)
    file2.truncate(0)
    file1.close()
    file2.close()
コード例 #12
0
ファイル: test_car_wash.py プロジェクト: radu9917/Car_Wash
def test_car_wash_setters():
    car_wash = CarWash(1, "BOB")
    car_wash.set_id(2)
    car_wash.set_name("IAN")
    assert car_wash.get_id() == 2
    assert car_wash.get_name() == "IAN"
コード例 #13
0
def test_validation():
    validator = Validator.get_instance()
    car1 = Car(1, "ag 12 BOB", "Dan")
    car3 = Car(":", "A", "Ian")
    car4 = Car(4, "A", "Ian")
    car5 = Car(2, "12 12 BAG", "Dan")
    car6 = Car(2, "AG ASD BUD", "Dan")
    car7 = Car(2, "AG 12 IMD", "dan")
    car8 = Car(
        2, "AG 12 IMD",
        "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    )
    car9 = Car(2, "AG 12 1234", "Ion")
    try:
        validator.validate_car(car1)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car4)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car3)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car5)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car6)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car7)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car8)
        assert False
    except ValidationError:
        assert True
    try:
        validator.validate_car(car9)
        assert False
    except ValidationError:
        assert True

    car_wash1 = CarWash(1, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    car_wash2 = CarWash(";", "La Geani")

    try:
        validator.validate_car_wash(car_wash1)
        assert False
    except ValidationError:
        assert True

    try:
        validator.validate_car_wash(car_wash2)
        assert False
    except ValidationError:
        assert True
    car_list = RepoCar()
    car_list.store(car1)

    try:
        validator.id_find(car_list.get_all(), 6)
        assert False
    except ValidationError:
        assert True

    car2 = Car(2, "AG 67 :AD", "Iulian")
    car_list.store(car2)

    try:
        validator.id_check(car_list.get_all(), 2)
        assert False
    except ValidationError:
        assert True

    try:
        validator.option_check("8", 2)
        assert False
    except ValidationError:
        assert True