def testSearchDescription(self): self._ctrl.book_ctrl_add(book("1", "HP", "Best", "JkR")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self.assertRaises(Exception, self._ctrl.book_SearchByDescription, "7aa234sa")
def testSearchTitle(self): self._ctrl.book_ctrl_add( book("6", "Don Quixote", "Classic", "Cervantes")) self._ctrl.book_ctrl_add( book("9", "The great Gatsby", "Movie", "Fitzgerald")) self.assertRaises(Exception, self._ctrl.book_SearchByTitle, "zzz") self.assertRaises(Exception, self._ctrl.book_SearchByTitle, "7aa234sa")
def testAdd(self): book1 = book("3", "HitchHiker", "Voted", "Douglas Adams") self._ctrl.book_ctrl_add(book1) self.assertRaises(ValueError, self._ctrl.book_ctrl_add, book("3", "HitchHiker", "Voted", "Douglas Adams")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self.assertEqual(len(self._ctrl._Books_repo._bookList), 2)
def testSearchAuthor(self): self._ctrl.book_ctrl_add(book("1", "HP", "Best", "JkR")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self.assertEqual( self._ctrl.book_SearchByAuthor("Jkr")[0].getbookId(), "1") self.assertRaises(Exception, self._ctrl.book_SearchByAuthor, "7asa")
def testFind(self): self._ctrl.book_ctrl_add(book("1", "HP", "Best", "JkR")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self.assertEqual(self._ctrl.book_isBookId("1"), True) self.assertEqual(self._ctrl.book_isBookId("2"), True) self.assertRaises(Exception, self._ctrl.book_isBookId, "5") self.assertRaises(Exception, self._ctrl.book_isBookId, "ad")
def testUpdate(self): self._ctrl.book_ctrl_add(book("1", "HP", "Best", "JkR")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self._ctrl.book_ctrl_update("1", ["Harry", "JKK", "J"]) self.assertEqual(self._ctrl.book_SearchById("1").gettitle(), "Harry") self.assertEqual(self._ctrl.book_SearchById("1").getauthor(), "J") self._ctrl.book_ctrl_update("2", ["", "j", ""]) self.assertEqual( self._ctrl.book_SearchById("2").getauthor(), "Douglas Adams") self.assertRaises(Exception, self._ctrl.book_ctrl_update, "7", [])
def testRemove(self): self._ctrl.book_ctrl_add(book("1", "HP", "Best", "JkR")) self._ctrl.book_ctrl_add( book("2", "HitchHiker", "Voted", "Douglas Adams")) self._ctrl.book_ctrl_add(book("3", "py", "as", "andrei")) self._ctrl.book_ctrl_add(book("4", "Anna", "drama", "T")) self._ctrl.book_ctrl_add( book("5", "Pride and Prejudice", "Russian", "D")) self.assertEqual(len(self._ctrl._Books_repo._bookList), 5) self._ctrl.book_ctrl_remove('2') self._ctrl.book_ctrl_remove('3') self.assertEqual(len(self._ctrl._Books_repo._bookList), 3) self.assertRaises(Exception, self._ctrl.book_ctrl_remove, '2') self.assertRaises(Exception, self._ctrl.book_ctrl_remove, '7')
def get_book(): try: bookId = input("Book Id: ") title = input("Book Title: ") description = input("Description: ") author = input("Author: ") except: print("Invalid data.") return book(bookId, title, description, author)
def testRepo(self): self.assertEqual(len(self._repo._bookList), 0) book1 = book("2","HitchHiker","Voted","Douglas Adams") self._repo.addBook(book1) self.assertEqual(len(self._repo._bookList), 1) self._repo.findBook(book1.getbookId()) self.assertEqual(self._repo.removeBook(book1.getbookId()), None) self.assertEqual(self._repo.findBookByAuthor(book1.getauthor()), []) #self.assertRaises(self._repo.removeBook("11"), book) self.assertEqual(len(self._repo._bookList), 0)
def loadFromFile(self): try: f = open(self._fileName, "r") line = f.readline().strip() while line != "": attrs = line.split(" ") book1 = book(attrs[0], attrs[1], attrs[2], attrs[3]) bookList.addBook(self, book1) line = f.readline().strip() except: raise Exception("Could not load from File!") finally: f.close()
def testCtrl(self): self.assertEqual(len(self._ctrl._Books_repo._bookList), 0) book1 = book("2", "HitchHiker", "Voted", "Douglas Adams") self._ctrl.book_ctrl_add(book1) self.assertEqual(len(self._ctrl._Books_repo._bookList), 1)
from Ctrl.UndoController import UndoController from Ctrl.ClientsControllerUNDO import ClientsControllerUndo from Ctrl.RentalsControllerUNDO import RentalsControllerUndo booksRepo = bookList() clientsRepo = clients() rentalsRepo = rentalList() booksFile = open("books.txt", 'r+') clientsFile = open("clients.txt", 'r+') rentalsFile = open("rentals.txt", 'r+') for i in range(1, 101): line = booksFile.readline() line = line.split(" ") booksRepo.addBook(book(line[0], line[1], line[2], line[3])) for i in range(1, 101): line = clientsFile.readline() line = line.split(" ") clientsRepo.addClient(client(line[0], line[1])) for i in range(1, 101): line = rentalsFile.readline() line = line.split(" ") #date 1 3-day-4-5-yr #date 2 6-7-8 date1 = datetime(int(line[5]), int(line[4]), int(line[3])) date2 = datetime(int(line[8]), int(line[7]), int(line[6])) newRental = rental(line[0], line[1], line[2], date1, date2)
from Repository.RentalsRepo import rentalList from menu.ui import ui from classes.books import book from classes.clients import client from classes.rental import rental from _datetime import datetime from Ctrl.BooksControllerUNDO import BooksControllerUndo from Ctrl.UndoController import UndoController from Ctrl.ClientsControllerUNDO import ClientsControllerUndo from Ctrl.RentalsControllerUNDO import RentalsControllerUndo booksRepo = bookList() clientsRepo = clients() rentalsRepo = rentalList() booksRepo.addBook(book("1", "HP", "Best", "JkR")) booksRepo.addBook(book("2", "HitchHiker", "Voted", "Douglas Adams")) booksRepo.addBook(book("3", "py", "as", "andrei")) booksRepo.addBook(book("4", "Anna", "drama", "T")) booksRepo.addBook(book("5", "Pride and Prejudice", "Russian", "D")) booksRepo.addBook(book("6", "Don Quixote", "Classic", "Cervantes")) booksRepo.addBook(book("7", "1984", "Dystopia", "Orwell")) booksRepo.addBook(book("8", "War and Peace", "Classic", "Tolstoy")) booksRepo.addBook(book("9", "The great Gatsby", "Movie", "Fitzgerald")) booksRepo.addBook(book("10", "Ulysses", "Greek", "James Joyce")) clientsRepo.addClient(client("11", "Lacy Soza")) clientsRepo.addClient(client("12", "Dorian Sivilis")) clientsRepo.addClient(client("13", "China Nissen")) clientsRepo.addClient(client("14", "Jessia Orlando")) clientsRepo.addClient(client("15", "Fredda Nalls"))