def __init__(self, filename): """ Constructor method Opens the file and loads the entries in memory filename is a string, the path to the file used for storage O(n) """ ClientList.__init__(self) self.__filename = filename try: self.__clientFile = open(filename, "r") except IOError: # File does not exist. Create it. self.__clientFile = open(filename, "w") self.__clientFile.close() self.__clientFile = open(filename, "r") line = "Nonempty String" while line != "": line = self.__clientFile.readline() if line == "" or line == "\n": break details = line.split("|") client = Client(details[0], details[1]) if details[2] != "": borrowedBooks = details[2].split(";") for borrowedBook in borrowedBooks: if borrowedBook != "": bookDetails = borrowedBook.split() book = Book(bookDetails[0], bookDetails[1], bookDetails[2]) client.addBorrowedBook(book) client.setActivity(int(details[3])) self.clientList.append(client) self.__clientFile.close()
''' Created on Nov 1, 2012 @author: Mihai Costea ''' from blackBox import blackBoxTest_updateBook from controller.Controller import LibraryController from controller.tests import test_controller from repository.RepositoryInFiles import BookListInFile, ClientListInFile from repository.Storage import BookList, ClientList from ui.Console import Console if __name__ == '__main__': #bookList = BookList() #clientList = ClientList() bookList = BookListInFile("books.dat") clientList = ClientListInFile("clients.dat") testBookList = BookList() testClientList = ClientList() test_controller(testBookList, testClientList) blackBoxTest_updateBook() libraryController = LibraryController(bookList, clientList) console = Console(libraryController)
def test_ClientList(): clientList = ClientList() clientList.addNewClient("name", "1910207205571") assert clientList.numberOfClients() == 1 assert clientList.lastAddedClient().getName() == "name" assert clientList.lastAddedClient().getCnp() == "1910207205571" clientList.addNewClient("New Name", "1910207205111") clientList.updateClient("name", "1910207205571", "a", "1111111111111") assert clientList.lastAddedClient().getName() == "New Name" assert clientList.lastAddedClient().getCnp() == "1910207205111" clientList.removeClient("New Name", "1910207205111") assert clientList.numberOfClients() == 1 assert clientList.lastAddedClient().getName() == "a" assert clientList.lastAddedClient().getCnp() == "1111111111111"