def create(self,i,y,p,f): if f=="Diesel": if p and len(i.strip())>0: c=Car(i,y,p) self.__repo.cr_ap_diesel(c) else: input("Invalid Data! Press any key...") elif f=="Gas": if p and len(i.strip())>0: c=Car(i,y,p) self.__repo.cr_ap_gas(c) else: input("Invalid Data!Press any key...") elif f=="Electric": if p and len(i.strip())>0: c=Car(i,y,p) self.__repo.cr_ap_electric(c) else: input("Invalid Data!Press any key...") else: input("Invalid Type of Fuel!Press any key...")
def test_car_eq(): car1 = Car(1, "AG 67 BUN", "Dan") car2 = Car(2, "AG 67 BUN", "Dan") car3 = Car(1, "AG 77 BUN", "Dan") car4 = Car(1, "AG 67 BUN", "Ian") assert not car1 == car2 assert not car1 == car3 assert not car1 == car4
def start(self): c1=Car("C1",2007,700) c2=Car("C2",2011,900) c3=Car("C3",2000,9600) self.__repo.cr_ap_diesel(c1) self.__repo.cr_ap_gas(c2) self.__repo.cr_ap_electric(c3)
def car_repo_test(): car_list = RepoCar() car1 = Car(1, "AG 46 IMD", "Ion") car_list.store(car1) assert car_list.get_all() is not None car2 = Car(2, "B 314 ZDA", "Miron") car_list.modify(1, car2) assert car_list.get_all()[0] == car2 car_list.store(car1) car_list.delete(2) assert car_list.get_all() == [car1] assert car_list.get(2) == car1
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
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)
def test_car_getters(): car = Car(1, "BOB", "Jhon") assert str(car.get_id()).isdecimal() assert car.get_owner().isalpha() assert car.get_number().isalpha() assert car.get_id() == 1 assert car.get_number() == "BOB" assert car.get_owner() == "Jhon"
def test_car_setters(): car = Car(1, "BOB", "Jhon") car.set_owner("IAN") car.set_number("NIG") car.set_id(2) assert car.get_id() == 2 assert car.get_owner() == "IAN" assert car.get_number() == "NIG"
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()]
def __load_from_file(self): file = open(self.__file_name, "r") json_file = json.loads(file.read()) if "car" in json_file: for index in json_file["car"]: id_car = index["id"] number = index["number"] name = index["owner"] self._list.append(Car(id_car, number, name)) file.close()
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
def test_set(self): car = Car() car.set_fuel("C1") car.set_price(780) car.set_year(2007) self.assertEqual(car.get_fuel(), "C1") self.assertEqual(car.get_year(), 2007) self.assertEqual(car.get_price(), 780)
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)
def __load_from_file(self): file = open(self.__file_name, "r") lines = file.readlines() for line in lines: obj = line.split(",") index = int(obj[0]) number = obj[1] name = obj[2].strip("\n") self._list.append(Car(index, number, name)) file.close()
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
def create_car(self): nr = int(input("How many cars do you want to make?")) while nr > 0: print("Create car :") index = input("Give car index:") number = input("Give car number:") owner = input("Give car owner:") try: self.__service.create_car(Car(index, number, owner)) 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)
def modify_car(self): correct = False while not correct: index = int(input("What car do you want to change?")) number = input("Give car number") owner = input("Give car owner") car = Car(index, number, owner) try: self.__service.modify_car(index, car) print(font_colors.OKGREEN + "Car successfully modified" + font_colors.ENDC) correct = True except ValidationError as exp: print(font_colors.FAIL + "An error has occured: " + str(exp) + font_colors.ENDC)
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()
def update_car(self, car_owner, car_number, car_id): new_car = Car(owner=car_owner, number=car_number) Service.modify_car(car_id, new_car)
def test_car_str(): car1 = Car(1, "AG 67 BUN", "Dan") car2 = Car(1, "AG 67 BUN", "Dan") assert str(car1) == str(car2)
def test_create(self): car = Car("C1", 2007, 780) self.assertEqual(car.get_fuel(), "C1") self.assertEqual(car.get_year(), 2007) self.assertEqual(car.get_price(), 780)
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
def create_car(self, car_owner, car_number): car = Car(owner=car_owner, number=car_number) Service.create_car(car)