def test_JsonRepo(self): self.test_FileRepo() c = Rental(4, 4, 4, "2017-12-10", "2017-12-20", "2017-12-14") self.jsonRepo.createItem(c) self.assertEqual(self.jsonRepo.getItemById(4), c) self.jsonRepo.updateItemById( 4, Rental(4, 4, 4, "2017-12-12", "2017-12-22", "2017-12-24")) self.jsonRepo.deleteItemById(4) self.assertEqual(self.jsonRepo.getItemById(4), False)
def setUp(self): self.Rental = Rental('1', '2', '3', '2017-10-23', '2018-10-23', -1) self.repo = Repository('testRentals', 'testRentals') self.movieRepo = Repository('testMovies', 'TestClients') self.clientRepo = Repository('testClients', 'TestClients') self.controller = RentalController(self.repo, self.movieRepo, self.clientRepo)
def get_rental_list(self): if self.__rentals == []: with open("./data/rentals.csv", "r", encoding="utf-8") as rental_file: rental_reader = csv.reader(rental_file) for line in rental_reader: order_num = line[0] name = line[1] ssn = line[2] car_id = line[3] insurance = line[4] start_date = line[5] end_date = line[6] total_price = line[7] status = line[8] payment = line[9] additional_driver_name = line[10] additional_driver_ssn = line[11] additional_driver_car_id = line[12] new_rental = Rental( order_num, name, ssn, car_id, insurance, start_date, end_date, total_price, status, payment, [ additional_driver_name, additional_driver_ssn, additional_driver_car_id ]) self.__rentals.append(new_rental) return self.__rentals
def __readAllFromFile(self): ''' we read all reantals from the file :return: ''' try: with open(self.__fileName, "r") as file: lines = file.readlines() for line in lines: if line != "": words = line.strip().split(",") if len(words) == 6: rental_id = int(words[0].strip()) book_id = int(words[1].strip()) client_id = int(words[2].strip()) rented_date = self.__computeDateFromFile( words[3].strip()) due_date = self.__computeDateFromFile( words[4].strip()) returned_date = self.__computeDateFromFile( words[5].strip()) rental = Rental(rental_id, book_id, client_id, rented_date, due_date, returned_date) RepoData.add(self, rental) except FileNotFoundError: print("Inexistent file : " + self.__fileName)
def confirm_order(self, rental, payment, start, end, additional_driver, total_price): order_num = rental.get_order_num() name = rental.get_name() ssn = rental.get_ssn() car = rental.get_car_id() insurance = rental.get_insurance() additional_driver_name = additional_driver[0] additional_driver_ssn = additional_driver[1] additional_driver_drivers_license = additional_driver[2] new_rental = Rental(order_num, name, ssn, car, insurance, start, end, total_price, "Closed", payment, [ additional_driver_name, additional_driver_ssn, additional_driver_drivers_license ]) rental_list = self.__rental_repo.get_rental_list() for index, old_rental in enumerate(rental_list): if old_rental.get_order_num() == new_rental.get_order_num(): rental_list.pop(index) rental_list.insert(index, new_rental) self.__rental_repo.change_rental_list(rental_list)
def __init__(self, isCreating): Rental.__init__(self, '', '', '', '', '', '') BaseWidget.__init__(self, 'Rental') self.__isCreating = isCreating self._idField = ControlText("Id") self._clientIdField = ControlText("Client Id") self._movieIdField = ControlText("Movie Id") self._dueDateField = ControlText("Due Date") self._rentedDateField = ControlText("Rented Date") self._returnedDateField = ControlText("Returned Date") self._buttonField = ControlButton('Rent a new Movie') self._buttonField.value = self._updateAction self._rentedDateField.enabled = False self._returnedDateField.enabled = False self._label = ControlLabel("") if not isCreating: self._idField.enabled = False self._clientIdField.enabled = False self._movieIdField.enabled = False self._dueDateField.enabled = False self._returnedDateField.enabled = False self._rentedDateField.enabled = False self._buttonField.value = self.returnMovie self._buttonField.name = "Return movie"
def test_RentalSetters(self): r = Rental(1, 2, 3, "2017-10-20", "2017-11-20", "2018-01-20") r.id = 4 r.movieId = 5 r.clientId = 6 r.returnedDate = "2017-12-20" r.dueDate = "2017-12-20" r.rentedDate = "2017-08-09" a = r.dueDate a = r.returnedDate self.assertNotEqual( r, Rental(4, 5, 6, "2017-12-20", "2017-12-20", "2017-08-09")) repo = Repository("testRentalsRental", "test") movieRepo = Repository("testRentalsMovie", "tes2") mc = MovieController(movieRepo) clientRepo = Repository("testRentalsClients", "test3") cc = ClientController(clientRepo) controller = RentalController(repo, cc, mc) self.assertEqual(controller.lateRentals(), []) self.assertEqual(controller.allRentedMovies(), mc.getAllMovies()) s = mc.getAllMovies() self.assertEqual(controller.mostRentedMoviesByNumber(), controller.mostRentedMoviesByNumber()) self.assertEqual(controller.mostRentedMoviesByDays(), controller.mostRentedMoviesByDays()) self.assertRaises(ValueError, controller.updateClientIdFromRental, "s", "2") self.assertRaises(ValueError, controller.updateClientIdFromRental, "2", "s") controller.removeAllAppOfClient("1") controller.removeAllAppOfMovie("1") controller.updateMovieIdFromRental("1", "1") controller.updateClientIdFromRental("1", "1") self.assertRaises(ValueError, controller.updateClientIdFromRental, "2", "s") self.assertRaises(ValueError, controller.updateClientIdFromRental, "s", "2")
def test_getRentalById2(self): f = open("testRentalsRental", 'w') f.write("2, 2, 2, 2017-11-20, 2019-11-20, -1") f.close() f = open("testRentalsMovie", 'w') f.write("2, title, sdfs, action") f.close() f = open("testRentalsClients", 'w') f.write("2, title") f.close() repo = Repository("testRentalsRental", "test") movieRepo = Repository("testRentalsMovie", "tes2") mc = MovieController(movieRepo) clientRepo = Repository("testRentalsClients", "test3") cc = ClientController(clientRepo) controller = RentalController(repo, cc, mc) rental = Rental("2", "2", "2", "2017-11-20", "2019-11-20", "-1") self.assertEqual(controller.getRentalById(2), rental)
def createRental(self, rental_id, book_id, client_id): book_repo = self.__bookService.getAllBooks() client_repo = self.__clientService.getAllClients() # we create a new client in order to see if client_id valid or not client = Client(client_id, 'None') self.__valid.checkClientExistence(client, client_repo) # we create a new book in order to see if the book_is valid or not book = Book(book_id, 'None', 'None', 'None', None) self.__valid.checkBookExistenceAndAvailability(book, book_repo) # need to check the book if it is available current_date = datetime.now() current_day = current_date.day # int current_month = current_date.month # int current_year = current_date.year # int rented_date = date(current_year, current_month, current_day) #rented_date = [] # rented_date will be a list #rented_date.append(current_day) #rented_date.append(current_month) #rented_date.append(current_year) # we need to create the due date due_date_p = current_date + timedelta(days=14) due_date_day = due_date_p.day # int due_date_month = due_date_p.month # int due_date_year = due_date_p.year # int due_date = date(due_date_year, due_date_month, due_date_day) #due_date = [] # due_date will be a list #due_date.append(due_date_day) #due_date.append(due_date_month #due_date.append(due_date_year) returned_date = 0 rental = Rental(rental_id, book_id, client_id, rented_date, due_date, returned_date) return rental
def updateRental(self, rentalId, newRentalId, movieId, clientId, rentedDate, dueDate, returnedDate): ''' A function that updates a movie's all fields and also provides data validation :param rentalId: integer :param newRentalId: integer :param movieId: integer :param clientId: integer :param rentedDate: string of format YYYY-MM-DD :param dueDate: string of format YYYY-MM-DD :param returnedDate: string of format YYYY-MM-DD :return: True if the rental was updated, False otherwise ''' RentalValidator.validate(newRentalId, movieId, clientId, rentedDate, dueDate, returnedDate) item = self.getItemById(int(rentalId)) checkForId = self.getItemById(newRentalId) if checkForId is not False and newRentalId.strip() != rentalId.strip(): raise ValueError("Error:\n The given id is already taken") if item is not False: item = Rental(newRentalId, movieId, clientId, rentedDate, dueDate, returnedDate) return self.updateItemById(int(rentalId), item)
def addRental(self, rentalId, movieId, clientId, rentedDate, dueDate, returnedDate): ''' A function that validates and adds a rental to the repository :param rentalId: integer :param movieId: integer :param clientId: integer :param rentedDate: string of format YYYY-MM-DD :param dueDate: string of format YYYY-MM-DD :param returnedDate: string of format YYYY-MM-DD :return: True if the item was added, False otherwise ''' if RentalValidator.validate(rentalId, movieId, clientId, rentedDate, dueDate, returnedDate): rentalId = int(rentalId) movieId = int(movieId) clientId = int(clientId) rental = Rental(rentalId, movieId, clientId, rentedDate, dueDate, returnedDate) if self.getItemById(int(rentalId)) is not False: raise ValueError("Error:\n The given id is already taken") self.addItem(rental) return True
def print_order_confirmation(self, customer, car, insurance, payment, start, end, additional_driver): delta = end - start days = int(delta.days) start_date = "{}/{}/{}".format(str(start.day), str(start.month), str(start.year)) end_date = "{}/{}/{}".format(str(end.day), str(end.month), str(end.year)) order_number = self.get_order_number() name = customer.get_name() ssn = customer.get_ssn() home_address = customer.get_home_address() email = customer.get_email() phone = customer.get_phone_num() if additional_driver != "Empty": additional_driver_name = "{} {}".format(additional_driver[0], additional_driver[1]) additional_driver_ssn = additional_driver[2] additional_driver_driv_license = additional_driver[3] car_make = car.get_make() car_model = car.get_model() car_plate = car.get_car_id() car_price_per_day = car.get_price() car_price = car_price_per_day * days car_price_w_vat = car_price * 1.24 car_string = "{} {} ({})".format(car_make, car_model, car_plate) car_class = car.get_car_class() insurance_list = self.get_insurance_info(car_class, insurance) insurance_cost_per_day = insurance_list[0] insurance_cost = insurance_cost_per_day * days insurance_cost_w_vat = insurance_cost * 1.24 insurance_name = insurance_list[1] insurance_info = insurance_list[2] total_price = car_price + insurance_cost vat = total_price * 0.24 total_price_w_vat = total_price * 1.24 print("{:<165}".format(order_number)) print("{:<165}{:<20}".format(name, "HSST Rental Company")) print("{:<165}{:<20}".format(ssn, "SSN: 040499-2059")) print("{:<165}{:<20}".format(home_address, "Hvergiland 88")) print("{:<165}{:<20}".format(email, "*****@*****.**")) print("{:<165}{:<20}".format(phone, "Phone: 642-1000")) print("\n\n") print("{:<20}{:<55}{:<20}{:<20}{:<20}{:<30}{:<20}".format( "Item", "Description", "Start Date", "Return Date", "Price per day", "Total Price no VAT", "Total Price with VAT")) print("{:<20}{:<55}{:<20}{:<20}{:<20}{:<30}{:<20}".format( "Car Rental", car_string, start_date, end_date, str(car_price_per_day) + " kr", str(car_price) + " kr", str(int(car_price_w_vat)) + " kr")) print("{:<20}{:<55}{:<20}{:<20}{:<20}{:<30}{:<20}".format( "Insurance", insurance_name, "", "", str(insurance_cost_per_day) + " kr", str(insurance_cost) + " kr", str(int(insurance_cost_w_vat)) + " kr")) for info in insurance_info: print("{:<20}-{:<45}".format("", info)) print("\n") #Additional driver here if additional_driver != "Empty": print("{:<20}{:<45}".format("Additional Driver", additional_driver_name)) print("{:<20}SSN: {:<45}".format("", additional_driver_ssn)) print("{:<20}Drivers License: {:<45}".format( "", additional_driver_driv_license)) print("\n\n") print("{:.<100}{:.>85}".format("Total Price no VAT ", str(int(total_price)) + " kr")) print("{:.<100}{:.>85}".format("VAT ", str(int(vat)) + " kr")) print("{:.<100}{:.>85}".format("Total Price with VAT ", str(int(total_price_w_vat)) + " kr")) print("\n\n") print("Payment: {}".format(payment)) confirm = input("Confirm order(Y/N):").upper() if confirm == "Y": if additional_driver == "Empty": rental = Rental(order_number, name, ssn, car_plate, insurance, start, end, str(int(total_price_w_vat)), "Open", payment) self.__rental_repo.add_rental(rental) else: rental = Rental( order_number, name, ssn, car_plate, insurance, start, end, str(int(total_price_w_vat)), "Open", payment, [ additional_driver_name, additional_driver_ssn, additional_driver_driv_license ]) self.__rental_repo.add_rental(rental) self.__car_repo.change_car_status(car.get_car_id()) clear()
def searchRentalById(self, rental_id): rental = Rental(rental_id, None, None, None, None, None) self.__valid.checkRentalExistence(rental, self.__rentalRepo.getAll()) for i in self.__rentalRepo.getAll(): if i.get_rental_id() == rental_id: return i