def testRentalRepository(): rentalRepo = Repository() book1 = Book(0, "The Q", "Albert", "Heinrich") book2 = Book(1, "The D", "Elbert", "Reinsich") client1 = Client(0, "Mihai", 1854987548795) client2 = Client(1, "Alex", 1987548759658) rentalRepo.addElement(Rental(1, book1, 0)) rentalRepo.addElement(Rental(0, book2, 1)) # _find(_id) returns the Rental from the repository # that has the client Id equal to _id assert rentalRepo._find(0).getRentedBook() == book1 assert rentalRepo._find(1).getId() == 1 assert rentalRepo._find(1).getRentedBook() == book2 assert rentalRepo._find(0).getId() == 0 # findId() function for Repository class assert rentalRepo.findId(12) == False assert rentalRepo.findId(0) == True # elementFromId() assert rentalRepo.elementFromId(0).getRentedBook() == book1 rentalRepo.addElement(Rental(1, book2, 2)) print ("Rental repository tests ran successfully!")
def testRentalRepository(self): rentalRepo = Repository() book1 = Book(0, "The Q", "Albert", "Heinrich") book2 = Book(1, "The D", "Elbert", "Reinsich") client1 = Client(0, "Mihai", 1854987548795) client2 = Client(1, "Alex", 1987548759658) rentalRepo.addElement(Rental(1, book1, 0)) rentalRepo.addElement(Rental(0, book2, 1)) # _find(_id) returns the Rental from the repository # that has the client Id equal to _id self.assertEqual( rentalRepo._find(0).getRentedBook() , book1 ) self.assertEqual( rentalRepo._find(1).getId() , 1 ) self.assertEqual( rentalRepo._find(1).getRentedBook() , book2 ) self.assertEqual( rentalRepo._find(0).getId() , 0 ) # findId() function for Repository class self.assertEqual( rentalRepo.findId(12) , False ) self.assertEqual( rentalRepo.findId(0) , True ) # elementFromId() self.assertEqual( rentalRepo.elementFromId(0).getRentedBook() , book1 ) rentalRepo.addElement(Rental(1, book2, 2))
def testRentalRepository(): rentalRepo = Repository() book1 = Book(0, "The Q", "Albert", "Heinrich") book2 = Book(1, "The D", "Elbert", "Reinsich") client1 = Client(0, "Mihai", 1854987548795) client2 = Client(1, "Alex", 1987548759658) rentalRepo.addElement(Rental(1, book1, 0)) rentalRepo.addElement(Rental(0, book2, 1)) # _find(_id) returns the Rental from the repository # that has the client Id equal to _id assert rentalRepo._find(0).getRentedBook() == book1 assert rentalRepo._find(1).getId() == 1 assert rentalRepo._find(1).getRentedBook() == book2 assert rentalRepo._find(0).getId() == 0 # findId() function for Repository class assert rentalRepo.findId(12) == False assert rentalRepo.findId(0) == True # elementFromId() assert rentalRepo.elementFromId(0).getRentedBook() == book1 rentalRepo.addElement(Rental(1, book2, 2)) print("Rental repository tests ran successfully!")
def testRentalRepository(self): rentalRepo = Repository() book1 = Book(0, "The Q", "Albert", "Heinrich") book2 = Book(1, "The D", "Elbert", "Reinsich") client1 = Client(0, "Mihai", 1854987548795) client2 = Client(1, "Alex", 1987548759658) rentalRepo.addElement(Rental(1, book1, 0)) rentalRepo.addElement(Rental(0, book2, 1)) # _find(_id) returns the Rental from the repository # that has the client Id equal to _id self.assertEqual(rentalRepo._find(0).getRentedBook(), book1) self.assertEqual(rentalRepo._find(1).getId(), 1) self.assertEqual(rentalRepo._find(1).getRentedBook(), book2) self.assertEqual(rentalRepo._find(0).getId(), 0) # findId() function for Repository class self.assertEqual(rentalRepo.findId(12), False) self.assertEqual(rentalRepo.findId(0), True) # elementFromId() self.assertEqual(rentalRepo.elementFromId(0).getRentedBook(), book1) rentalRepo.addElement(Rental(1, book2, 2))
def testClientRepository(self): repo = Repository() c1 = Client(1, "Alice", 6548987854215) c2 = Client(2, "Vlad", 1944444444444) self.assertEqual( len(repo) , 0 ) repo.addElement(c1) self.assertEqual( len(repo) , 1 ) repo.addElement(c2) self.assertEqual( len(repo) , 2 )
def testClientRepository(self): repo = Repository() c1 = Client(1, "Alice", 6548987854215) c2 = Client(2, "Vlad", 1944444444444) self.assertEqual(len(repo), 0) repo.addElement(c1) self.assertEqual(len(repo), 1) repo.addElement(c2) self.assertEqual(len(repo), 2)
def testClientRepository(): repo = Repository() c1 = Client(1, "Alice", 6548987854215) c2 = Client(2, "Vlad", 1944444444444) assert len(repo) == 0 repo.addElement(c1) assert len(repo) == 1 repo.addElement(c2) assert len(repo) == 2 print("ClientRepository tests ran successfully!")
def testClientRepository(): repo = Repository() c1 = Client(1, "Alice", 6548987854215) c2 = Client(2, "Vlad", 1944444444444) assert len(repo) == 0 repo.addElement(c1) assert len(repo) == 1 repo.addElement(c2) assert len(repo) == 2 print ("ClientRepository tests ran successfully!")
def testRental(self): repo = Repository() book1 = Book(1, "ala", "mala", "dala") rentList = Repository() rentList.addElement(Rental(2, book1, 0)) lis1 = rentList.getElementList() self.assertEqual( len(lis1) , 1 ) rentList.addElement(Rental(2, book1, 1)) lis1 = rentList.getElementList() self.assertEqual( len(lis1) , 2 ) self.assertEqual( lis1[0].getRenterId() , 2 ) self.assertEqual( lis1[0].getRentedBook() , book1 ) self.assertEqual( lis1[0].getId() , 0 )
def testRental(self): repo = Repository() book1 = Book(1, "ala", "mala", "dala") rentList = Repository() rentList.addElement(Rental(2, book1, 0)) lis1 = rentList.getElementList() self.assertEqual(len(lis1), 1) rentList.addElement(Rental(2, book1, 1)) lis1 = rentList.getElementList() self.assertEqual(len(lis1), 2) self.assertEqual(lis1[0].getRenterId(), 2) self.assertEqual(lis1[0].getRentedBook(), book1) self.assertEqual(lis1[0].getId(), 0)
def testBookRepository(self): repo = Repository() book1 = Book(1, "ala", "mala", "dala") repo.addElement(book1) self.assertEqual( len(repo) , 1 ) try: if repo.addElement(book1) != False: self.assertEqual( False ) except BookException: pass book2 = Book(2, "ala", "mala", "dala") repo.addElement(book2) self.assertEqual( len(repo) , 2 )
def testBookRepository(self): repo = Repository() book1 = Book(1, "ala", "mala", "dala") repo.addElement(book1) self.assertEqual(len(repo), 1) try: if repo.addElement(book1) != False: self.assertEqual(False) except BookException: pass book2 = Book(2, "ala", "mala", "dala") repo.addElement(book2) self.assertEqual(len(repo), 2)
def testRental(): repo = Repository() book1 = Book(1, "ala", "mala", "dala") rentList = Repository() rentList.addElement(Rental(2, book1, 0)) lis1 = rentList.getElementList() assert len(lis1) == 1 rentList.addElement(Rental(2, book1, 1)) lis1 = rentList.getElementList() assert len(lis1) == 2 assert lis1[0].getRenterId() == 2 assert lis1[0].getRentedBook() == book1 assert lis1[0].getId() == 0 print ("Rental tests ran successfully!")
def testRental(): repo = Repository() book1 = Book(1, "ala", "mala", "dala") rentList = Repository() rentList.addElement(Rental(2, book1, 0)) lis1 = rentList.getElementList() assert len(lis1) == 1 rentList.addElement(Rental(2, book1, 1)) lis1 = rentList.getElementList() assert len(lis1) == 2 assert lis1[0].getRenterId() == 2 assert lis1[0].getRentedBook() == book1 assert lis1[0].getId() == 0 print("Rental tests ran successfully!")
def testBookRepository(): repo = Repository() book1 = Book(1, "ala", "mala", "dala") repo.addElement(book1) assert len(repo) == 1 try: if repo.addElement(book1) != False: assert False except BookException: pass book2 = Book(2, "ala", "mala", "dala") repo.addElement(book2) assert len(repo) == 2 print ("BookRepository tests ran successfully!")
def testBookRepository(): repo = Repository() book1 = Book(1, "ala", "mala", "dala") repo.addElement(book1) assert len(repo) == 1 try: if repo.addElement(book1) != False: assert False except BookException: pass book2 = Book(2, "ala", "mala", "dala") repo.addElement(book2) assert len(repo) == 2 print("BookRepository tests ran successfully!")
def main(): ''' This is the main() function and is the first thing that is ran by the program. It contains all the objects necessary for execution and everything related to the UI. ''' # repositories must be initialized with a string containing the type of the repository in order to use files clientRepository = Repository("Client") bookRepository = Repository("Book") rentalRepository = Repository("Rental") clientController = ClientController(clientRepository) bookController = BookController(bookRepository) rentalController = RentalController(rentalRepository, clientController, bookController) keepAlive = True while keepAlive: userInput = input("Please choose the mode (memory/file). Insert 'x' to quit: ") if userInput == 'x': return elif userInput == 'memory': clientRepository.addElement(Client(0, 'Mircea', 1962353535353)) clientRepository.addElement(Client(1, 'Dorin', 1962353535354)) clientRepository.addElement(Client(3, 'Marius', 1962353335353)) clientRepository.addElement(Client(6, 'Dacia', 1962353444353)) bookRepository.addElement(Book(0, "Dorin Mateiu", "Viata pe un Stalp", "Mihaila")) bookRepository.addElement(Book(1, "Salutare", "Lume", "Viata")) bookRepository.addElement(Book(2, "Inca", "O Carte", "Buna")) ui_object = UserInterface(clientController, bookController, rentalController) ui_object.launchMainMenu() keepAlive = False elif userInput == 'file': print ("Available files: ") files = listdir('resources') for i in files: if i[-4:] == '.txt': print (i) print() print ("Please choose the file you want to load.", "If that file does not exist it will be created.") print ("Insert 'x' at any time to quit.") chosenFile = input("Please insert file name: ") if chosenFile == 'x': continue alreadyExists = False existingFile = None for i in files: if i[:-4] == chosenFile: alreadyExists = True existingFile = i if alreadyExists == True: print ("File found! Type again to load: ") confirmInput = input() if confirmInput == 'x': continue if confirmInput == chosenFile: # file was found and will be loaded if '.txt' in chosenFile: chosenFile = chosenFile[:-4] filePath = 'resources/' + chosenFile + '.txt' ui_object = UserInterface(clientController, bookController, rentalController, filePath) ui_object.launchMainMenu() else: print ("Returning...") continue else: print ("Create file? Type again to confirm: ") confirmInput = input() if confirmInput == 'x': continue if confirmInput == chosenFile: filePath = 'resources/' + chosenFile + '.txt' ui_object = UserInterface(clientController, bookController, rentalController, None) ui_object.launchMainMenu(filePath) else: print ("Returning...") continue keepAlive = False else: print ("Error! Please insert 'file' or 'memory' ")
def main(): ''' This is the main() function and is the first thing that is ran by the program. It contains all the objects necessary for execution and everything related to the UI. ''' # repositories must be initialized with a string containing the type of the repository in order to use files clientRepository = Repository("Client") bookRepository = Repository("Book") rentalRepository = Repository("Rental") clientController = ClientController(clientRepository) bookController = BookController(bookRepository) rentalController = RentalController(rentalRepository, clientController, bookController) keepAlive = True while keepAlive: userInput = input( "Please choose the mode (memory/file). Insert 'x' to quit: ") if userInput == 'x': return elif userInput == 'memory': clientRepository.addElement(Client(0, 'Mircea', 1962353535353)) clientRepository.addElement(Client(1, 'Dorin', 1962353535354)) clientRepository.addElement(Client(3, 'Marius', 1962353335353)) clientRepository.addElement(Client(6, 'Dacia', 1962353444353)) bookRepository.addElement( Book(0, "Dorin Mateiu", "Viata pe un Stalp", "Mihaila")) bookRepository.addElement(Book(1, "Salutare", "Lume", "Viata")) bookRepository.addElement(Book(2, "Inca", "O Carte", "Buna")) ui_object = UserInterface(clientController, bookController, rentalController) ui_object.launchMainMenu() keepAlive = False elif userInput == 'file': print("Available files: ") files = listdir('resources') for i in files: if i[-4:] == '.txt': print(i) print() print("Please choose the file you want to load.", "If that file does not exist it will be created.") print("Insert 'x' at any time to quit.") chosenFile = input("Please insert file name: ") if chosenFile == 'x': continue alreadyExists = False existingFile = None for i in files: if i[:-4] == chosenFile: alreadyExists = True existingFile = i if alreadyExists == True: print("File found! Type again to load: ") confirmInput = input() if confirmInput == 'x': continue if confirmInput == chosenFile: # file was found and will be loaded if '.txt' in chosenFile: chosenFile = chosenFile[:-4] filePath = 'resources/' + chosenFile + '.txt' ui_object = UserInterface(clientController, bookController, rentalController, filePath) ui_object.launchMainMenu() else: print("Returning...") continue else: print("Create file? Type again to confirm: ") confirmInput = input() if confirmInput == 'x': continue if confirmInput == chosenFile: filePath = 'resources/' + chosenFile + '.txt' ui_object = UserInterface(clientController, bookController, rentalController, None) ui_object.launchMainMenu(filePath) else: print("Returning...") continue keepAlive = False else: print("Error! Please insert 'file' or 'memory' ")