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 setUp(self): self.repo = Repository() self.brepo = Repository() self.crepo = Repository() self.Ucontroller = UndoController() self.book = Book(21, 'titlu', 'descriere', 'author') self.book2 = Book(22, 'titlu2', 'descriere2', 'author') self.brepo.add(self.book) self.brepo.add(self.book2) self.client = Client(23, 'alex') self.client2 = Client(24, 'ana') self.client3 = Client(29, 'ana') self.crepo.add(self.client) self.crepo.add(self.client2) self.rental = Rental(21236, 21, 24, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental2 = Rental(21238, 22, 24, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental3 = Rental(21238, 23, 24, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental4 = Rental(21238, 21, 29, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental5 = Rental(21231, 21, 23, date(2017, 11, 5), date(2017, 10, 6), None) self.controller = RentalController(self.repo, self.brepo, self.crepo, self.Ucontroller) self.ceva = LateRentalCount(12, 32) self.altceva = BookRentalCount(12, 23) self.nu = AuthorRentalCount('da', 23) self.da = ClientRentalCount(32, 12)
def setUp(self): self.client = Client(23, 'alex') self.client2 = Client(12, 'diana') self.book = Book(21, 'titlu', 'descriere', 'author') self.book2 = Book(22, 'titlu2', 'descriere2', 'author2') self.rental = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental2 = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5))
def setUp(self): self.validator = Validator() self.book = Book(12, '', '', '') self.book2 = Book(22, 'da', 'desc', 'aut') self.client = Client(13, '') self.client2 = Client(14, 'da')
def setUp(self): self.repo = Repository() self.rentalRepo = Repository() self.Ucontroller = UndoController() self.book = Book(21, 'titlu', 'descriere', 'author') self.book2 = Book(22, 'titlu2', 'descriere2', 'author2') self.controller = BookController(self.repo, self.Ucontroller, self.rentalRepo)
def testBook(): try: book1 = Book(1, "a", "b", "c") assert book1.getId() == 1 assert book1.getTitle() == "a" assert book1.getDescription() == "b" assert book1.getAuthor() == "c" except: assert False try: book1 = Book("D", "d", "d", "d") print(book1) assert False except BookException: pass try: book1 = Book(1, "a", "b", "c") book1.setTitle(3) assert False except: pass print("Book tests ran successfully!")
def testDomainBook(self): book = Book(1, "Title", "Description", "Author") self.assertTrue(book.getTitle() == "Title") self.assertTrue(book.getDescription() == "Description") self.assertTrue(book.getAuthor() == "Author") self.assertTrue(book.getId() == 1) self.assertTrue(book.isRented() != True) self.assertTrue(not (book == 1)) book.setRented(True) self.assertTrue(book.isRented())
def test_add(self): ''' testing the add function of both client repo and book repo + rent repo also testing return function for rent ''' book1 = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe") self._book_repo.add(book1) listBooks = self._book_repo.getAll() assert len(listBooks) == 1 assert listBooks[0].get_title() == "Persona 3" assert listBooks[0].get_author() == "Shuji Sogabe" assert listBooks[0].get_desc() == "3rd entry in the series" assert listBooks[0].get_id() == 0 client1 = Client(1, "Scott Fitzgerald") self._client_repo.add(client1) listClients = self._client_repo.getAll() assert len(listClients) == 1 assert listClients[0].get_name() == "Scott Fitzgerald" self._rental_repo.rent_book(client1, book1, datetime(2018, 11, 3)) listRent = self._rental_repo.getAll() assert len(listRent) == 1 assert listRent[0].get_clientID() == 1 assert listRent[0].get_bookID() == 0 assert listRent[0].get_rentalID() == 0 assert str(listRent[0].get_rented_date()) == "2018-11-03 00:00:00" assert str(listRent[0].get_due_date()) == "2018-11-17 00:00:00" assert str(listRent[0].get_return_date()) == "None" self._rental_repo.return_book(client1, book1, datetime(2018, 12, 3)) assert str(listRent[0].get_return_date()) == "2018-12-03 00:00:00"
def __loadFromFile(self, type): """ :param sample: Element :return: None :raises RepositoryException when the file cannot be read for some reason """ try: f = open(self.__fileName, "r") line = f.readline().strip() while line != "": attrs = line.split(",") if type == Book: book = Book(int(attrs[0]), attrs[1], attrs[2], attrs[3]) self.__repo.add(book) line = f.readline().strip() if type == Client: client = Client(int(attrs[0]), attrs[1]) self.__repo.add(client) line = f.readline().strip() if type == Rental: rental = Rental( int(attrs[0]), int(attrs[1]), int(attrs[2]), createDateFromString(self.__reverseDate(attrs[3])), createDateFromString(self.__reverseDate(attrs[4])), createDateFromString(self.__reverseDate(attrs[5]))) self.__repo.add(rental) line = f.readline().strip() except IOError: raise RepositoryException() finally: f.close()
def test_add(self): ''' tests the add function for client and book controller and rent function for rental service also the return function for rental service ''' book = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe") self._controller.add_book(book) listBooks = self._controller._book_repo.getAll() assert len(listBooks) == 1 assert listBooks[0].get_title() == "Persona 3" assert listBooks[0].get_author() == "Shuji Sogabe" assert listBooks[0].get_desc() == "3rd entry in the series" assert listBooks[0].get_id() == 0 client1 = Client(1, "Scott Fitzgerald") self._controller.add_client(client1) listClients = self._controller._client_repo.getAll() assert len(listClients) == 1 assert listClients[0].get_name() == "Scott Fitzgerald" self._service.rent(book, client1, datetime(2018, 11, 3)) listRent = self._service._rent_repo.getAll() assert len(listRent) == 2 assert listRent[0].get_clientID() == 1 assert listRent[0].get_bookID() == 0 assert listRent[0].get_rentalID() == 0 assert str(listRent[0].get_rented_date()) == "2018-11-03 00:00:00" assert str(listRent[0].get_due_date()) == "2018-11-17 00:00:00" assert str(listRent[0].get_return_date()) == "None" self._service.return_book(book, client1, datetime(2018, 12, 3)) listRent = self._service._rent_repo.getAll() assert str(listRent[0].get_return_date()) == "2018-12-03 00:00:00"
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(): 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 testBookController(self): repo = Repository() controller = BookController(repo) undoController = Undo() controller.addUndoController(undoController) self.assertEqual(controller.addBook(Book(1, "ala", "mala", "dala")), True) self.assertNotEqual(controller.searchById(1), False) found = controller.searchById(1) self.assertEqual(found, Book(1, "ala", "mala", "dala")) self.assertEqual(controller.searchByTitle("ala"), Book(1, "ala", "mala", "dala")) self.assertNotEqual( controller.modifyBookAuthor(Book(1, "ala", "mala", "dala"), "Mercan"), False) self.assertEqual( controller.modifyBookTitle(Book(1, "ala", "mala", "Mercan"), "Newt"), True) self.assertEqual(controller.findExistingId(1), True) self.assertEqual( controller.removeElement(Book(1, "Newt", "mala", "Mercan")), True) self.assertEqual(controller.searchById(1), False) self.assertEqual(controller.checkIdExists(1), False)
def create(self, bookID, title, description, author): newbook = Book(bookID, title, description, author) bookList = self.__repository.getAll() for book in bookList: if book.getBookID == bookID: raise ValueError("The ID must be unique!") redo = FunctionCall(self.create, bookID, title, description, author) undo = FunctionCall(self.remove, bookID) oper = Operation(undo, redo) self.__UndoController.add(oper) self.__repository.addBook(newbook) return newbook
def updateBook(self, id, newTitle, newDesc, newAuthor): """ :param id: int :param newTitle: string :param newDesc: string :param newAuthor: string :return: None """ try: self.__bookRepo.removeById(id) updatedBook = Book(id, newTitle, newDesc, newAuthor) self.__bookRepo.add(updatedBook) except RepositoryException as re: pass
def both(self, ID, title, desc, author): try: self.__Ucontroller.newOperation() self.__Bcontroller.addBook( Book.create_book(int(ID.get()), title.get(), desc.get(), author.get())) messagebox.showinfo("INFO", "BOOK ADDED") except Exception as exc: print(str(exc)) window = Toplevel(self.master) window.pack_propagate(0) v = StringVar() v.set(str(exc)) label = Label(window, textvariable=v) label.pack()
def populateBookRepository(self): """ Populate the repo with some random entities :return: None """ for i in range(100): id = random.randint(1, 100) title = "Title" + str(random.randint(1, 100)) desc = "Description" + str(random.randint(1, 100)) author = "Author" + str(random.randint(1, 100)) if not self.__bookRepo.existsById(id): book = Book(id, title, desc, author) self.addBook(id, title, desc, author)
def testSearchAvailable(self): ''' tests search function for client/book and available function for rentals ''' book = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe") self._controller.add_book(book) client = Client(1, "Scott Fitzgerald") self._controller.add_client(client) self._service.rent(book, client, datetime(2018, 11, 3)) assert self._controller.parse_search_word("pErSoNa") == "persona" assert self._controller.parse_search_word(5) == 5 assert self._service.available_book(book, datetime(2018, 11, 3), datetime(2018, 12, 3)) == False self._service.return_book(book, client, datetime(2018, 12, 3)) assert self._service.available_book(book, datetime(2019, 12, 4), datetime(2019, 12, 23)) == False
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 put(self, index): for i in range(index): isbn = self.book_info["items"][i]["volumeInfo"].get( "industryIdentifiers") if isbn is not None and "ISBN" in isbn[0]["type"]: isbn = isbn[0]["identifier"] else: continue title = self.book_info["items"][i]["volumeInfo"].get("title") image_link = self.book_info["items"][i]["volumeInfo"].get( "imageLinks").get("thumbnail", "") try: self.books.append( Book(title=title, isbn=isbn, image_link=image_link)) except ValidationError as e: print(f"[ERROR]{e}")
def testBook(self): try: book1 = Book(1, "a", "b", "c") self.assertEqual(book1.getId(), 1) self.assertEqual(book1.getTitle(), "a") self.assertEqual( book1.getDescription() , "b") self.assertEqual( book1.getAuthor() , "c") except: self.assertEqual( False ) try: book1 = Book("D", "d", "d", "d") self.assertEqual( False ) except BookException: pass try: book1 = Book(1, "a", "b", "c") book1.setTitle(3) self.assertEqual( False ) except: pass
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 modifyBookAuthor(self, bookElement, newAuthor): ''' Searches repository for corresponding bookElement and replaces its author. This is done by first removing the entry from the repository, constructing a new one and adding it. Input: self - object defined by this class bookElement - Book type object newAuthor - string Output: True/False ''' if self._repo.findId(bookElement.getId()) == False: return False newBook = Book(bookElement.getId(), bookElement.getTitle(), bookElement.getDescription(), newAuthor) self._repo.removeElement(bookElement) self._repo.addElement(newBook) newOperation = ModifyOperation(self._repo, bookElement, newBook) self._undoController._addOperation(newOperation) return True
def addBook(self, id, title, description, author): """ :param id: int :param title: string :param description: string :param author: string :return: a string of errors if any """ errorString = "" errorString += self.__validator.validateNewBook( id, title, description, author) if len(errorString) != 0: return errorString book = Book(id, title, description, author) try: self.__bookRepo.add(book) except RepositoryException as re: return str(re) return ""
def testBookController(): repo = Repository() controller = BookController(repo) undoController = Undo() controller.addUndoController(undoController) assert controller.addBook(Book(1, "ala", "mala", "dala")) == True assert controller.searchById(1) != False found = controller.searchById(1) assert found == Book(1, "ala", "mala", "dala") assert controller.searchByTitle("ala") == Book(1, "ala", "mala", "dala") assert controller.modifyBookAuthor(Book(1, "ala", "mala", "dala"), "Mercan") != False assert controller.modifyBookTitle(Book(1, "ala", "mala", "Mercan"), "Newt") == True assert controller.findExistingId(1) == True assert controller.removeElement(Book(1, "Newt", "mala", "Mercan")) == True assert controller.searchById(1) == False assert controller.checkIdExists(1) == False print ("BookController tests ran successfully!")
def testRepositoryBooks(self): repoBooks = Repository() repoText = CSVRepository("bookRepo.csv", Book(1, "e", "s", "w")) repoBinary = PickleRepository("binaryBookRepo.pickle") repoCustom = CustomRepository(Book) book = Book(1, "Title", "Description", "Author") book1 = Book(2, "Title1", "Description1", "Author1") self.assertEqual(repoBooks.size(), 0) self.assertEqual(repoBinary.size(), 0) self.assertEqual(repoText.size(), 0) self.assertEqual(repoCustom.size(), 0) repoBooks.add(book) repoBooks.add(book1) repoText.add(book) repoText.add(book1) repoBinary.add(book) repoBinary.add(book1) repoCustom.add(book) repoCustom.add(book1) self.assertTrue(repoBooks.existsById(1)) self.assertTrue(repoBooks.size() == 2) self.assertTrue(repoBooks.getById(1) == book) self.assertTrue(repoBooks.existsById(2)) self.assertTrue(repoBooks.getById(2) == book1) self.assertTrue(repoText.existsById(1)) self.assertTrue(repoText.size() == 2) self.assertTrue(repoText.getById(1) == book) self.assertTrue(repoText.existsById(2)) self.assertTrue(repoText.getById(2) == book1) self.assertTrue(repoBinary.existsById(1)) self.assertTrue(repoBinary.size() == 2) self.assertTrue(repoBinary.getById(1) == book) self.assertTrue(repoBinary.existsById(2)) self.assertTrue(repoBinary.getById(2) == book1) self.assertTrue(repoCustom.existsById(1)) self.assertTrue(repoCustom.size() == 2) self.assertTrue(repoCustom.getById(1) == book) self.assertTrue(repoCustom.existsById(2)) self.assertTrue(repoCustom.getById(2) == book1) repoBooks.removeById(1) repoBooks.remove(book1) repoText.removeById(1) repoText.remove(book1) repoBinary.removeById(1) repoBinary.remove(book1) repoCustom.removeById(1) repoCustom.remove(book1) self.assertTrue(repoBooks.size() == 0) self.assertTrue(repoBooks.existsById(1) == False) self.assertTrue(repoText.size() == 0) self.assertTrue(repoText.existsById(1) == False) self.assertTrue(repoBinary.size() == 0) self.assertTrue(repoBinary.existsById(1) == False) self.assertTrue(repoCustom.size() == 0) self.assertTrue(repoCustom.existsById(1) == False) repoBooks.add(book) repoBooks.update(Book(1, "Updated Title", "Updated Desc", "Updated Author")) repoText.add(book) repoText.update(Book(1, "Updated Title", "Updated Desc", "Updated Author")) repoBinary.add(book) repoBinary.update(Book(1, "Updated Title", "Updated Desc", "Updated Author")) repoCustom.add(book) repoCustom.update(Book(1, "Updated Title", "Updated Desc", "Updated Author")) self.assertTrue(repoBooks.findById(1) == 0) self.assertTrue(repoText.findById(1) == 0) self.assertTrue(repoBinary.findById(1) == 0) self.assertTrue(repoCustom.findById(1) == 0) self.assertTrue(repoBooks.getById(1).getTitle() == "Updated Title") self.assertTrue(repoText.getById(1).getTitle() == "Updated Title") self.assertTrue(repoBinary.getById(1).getTitle() == "Updated Title") self.assertTrue(repoCustom.getById(1).getTitle() == "Updated Title") self.assertTrue(repoBooks.getById(1).getDescription() == "Updated Desc") self.assertTrue(repoText.getById(1).getDescription() == "Updated Desc") self.assertTrue(repoBinary.getById(1).getDescription() == "Updated Desc") self.assertTrue(repoCustom.getById(1).getDescription() == "Updated Desc") self.assertTrue(repoBooks.getById(1).getAuthor() == "Updated Author") self.assertTrue(repoText.getById(1).getAuthor() == "Updated Author") self.assertTrue(repoBinary.getById(1).getAuthor() == "Updated Author") self.assertTrue(repoCustom.getById(1).getAuthor() == "Updated Author") self.assertTrue(str(repoBooks.getById(1)) == "BOOK ID: " + str(repoBooks.getById(1).getId()) + "| Title: " + \ repoBooks.getById(1).getTitle() + "| Description: " + \ repoBooks.getById(1).getDescription() + \ "| Author: " + repoBooks.getById(1).getAuthor()) self.assertTrue(str(repoText.getById(1)) == "BOOK ID: " + str(repoText.getById(1).getId()) + "| Title: " + \ repoText.getById(1).getTitle() + "| Description: " + \ repoText.getById(1).getDescription() + \ "| Author: " + repoText.getById(1).getAuthor()) self.assertTrue(str(repoBinary.getById(1)) == "BOOK ID: " + str(repoBinary.getById(1).getId()) + "| Title: " + \ repoBinary.getById(1).getTitle() + "| Description: " + \ repoBinary.getById(1).getDescription() + \ "| Author: " + repoBinary.getById(1).getAuthor()) self.assertTrue(str(repoCustom.getById(1)) == "BOOK ID: " + str(repoCustom.getById(1).getId()) + "| Title: " + \ repoCustom.getById(1).getTitle() + "| Description: " + \ repoCustom.getById(1).getDescription() + \ "| Author: " + repoCustom.getById(1).getAuthor())
def testRentBook(self): client1 = Client(1, "Name1") client2 = Client(2, "Name2") book1 = Book(1, "Title", "Description", "Author") book2 = Book(2, "Title1", "Description1", "Author1") clientRepo = Repository() bookRepo = Repository() functions = ClientController(clientRepo, Statistics(clientRepo)) functiom = BookController(bookRepo, Statistics(bookRepo)) functions.addClient(client2.getId(), client2.getName()) functions.addClient(client1.getId(), client1.getName()) functiom.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor()) functiom.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor()) rentalRepo = Repository() functionsr = RentalController(bookRepo, clientRepo, rentalRepo, Statistics(rentalRepo)) msg1 = functionsr.rentBook(book1.getId(), client1.getId(), createDateFromString("23.11.2017"), "30.11.2017") self.assertTrue(len(msg1) == 0) self.assertTrue(functionsr.getRentals()[0].getBookId() == book1.getId()) self.assertTrue(functionsr.getRentals()[0].getClientId() == client1.getId()) msg2 = functionsr.rentBook(book2.getId, client2.getId(), createDateFromString("20.11.2017"), "19.11.2017") self.assertTrue(msg2 == "Inconsistent dates")
def read_book(): bookID = UI.readInt("Enter book ID: ") title = input("Enter title: ") author = input("Enter author: ") desc = input("Enter description: ") return Book(bookID, title, desc, author)
def test_delete(self): ''' testing the delete function of client, book and rental repositories also tests find functions for books/ clients ''' book1 = Book(0, "Persona 3", "3rd entry in the series", "Shuji Sogabe") self._book_repo.add(book1) book2 = Book(1, "Persona 5", "5th entry in the series", "Atlus") self._book_repo.add(book2) self._book_repo.remove(book1) listBooks = self._book_repo.getAll() assert len(listBooks) == 1 assert listBooks[0].get_title() == "Persona 5" assert listBooks[0].get_author() == "Atlus" assert listBooks[0].get_desc() == "5th entry in the series" assert listBooks[0].get_id() == 1 try: self._book_repo.remove(Book(34, "til", "de", "dw")) assert True except IndexError: pass except ValueError: pass assert self._book_repo.find(book1) == False assert self._book_repo.find(book2) == True assert self._book_repo.find_by_id(book2.get_id()) == book2 client1 = Client(1, "Scott Fitzgerald") client2 = Client(2, "Shuji Sogabe") self._client_repo.add(client1) self._client_repo.add(client2) self._client_repo.remove(client1) listClients = self._client_repo.getAll() assert len(listClients) == 1 assert listClients[0].get_name() == "Shuji Sogabe" assert listClients[0].get_id() == 2 try: self._client_repo.remove(Client(34, "til")) assert True except IndexError: pass except ValueError: pass assert self._client_repo.find(client1) == False assert self._client_repo.find(client2) == True assert self._client_repo.find(Client(1, "Shuji Sogabe")) == False assert self._client_repo.find_by_id(client2.get_id()) == client2 self._rental_repo.rent_book(client1, book1, datetime(2018, 11, 3)) self._rental_repo.rent_book(client2, book1, datetime(2018, 12, 3)) self._rental_repo.delete(self._rental_repo.getAll()[1]) listRent = self._rental_repo.getAll() assert len(listRent) == 1 assert listRent[0].get_clientID() == 1 assert listRent[0].get_bookID() == 0 assert listRent[0].get_rentalID() == 0 assert str(listRent[0].get_rented_date()) == "2018-11-03 00:00:00" assert str(listRent[0].get_due_date()) == "2018-11-17 00:00:00" assert str(listRent[0].get_return_date()) == "None" try: self._rental_repo.rent_book(client2, book1, datetime(2018, 12, 7)) assert True except IndexError: pass except ValueError: pass
class TestDomain(unittest.TestCase): def setUp(self): self.client = Client(23, 'alex') self.client2 = Client(12, 'diana') self.book = Book(21, 'titlu', 'descriere', 'author') self.book2 = Book(22, 'titlu2', 'descriere2', 'author2') self.rental = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) self.rental2 = Rental(21236, 21, 23, date(2017, 11, 5), date(2017, 12, 6), date(2017, 12, 5)) def tearDown(self): pass def test_create_Client(self): # CLIENTS TESTS self.assertEqual(23, self.client.getID()) self.assertEqual('alex', self.client.getName()) self.client.setName('da') self.assertEqual('da', self.client.getName()) self.assertFalse(self.client == self.client2) self.assertEqual(str(self.client), '023. da\n') self.assertEqual(self.client.create_client(23, 'alex'), self.client) def test_create_book(self): self.assertEqual(21, self.book.getID()) self.assertEqual('titlu', self.book.getTitle()) self.assertEqual('descriere', self.book.getDescription()) self.assertEqual('author', self.book.getAuthor()) self.assertEqual(True, self.book.get_available()) self.book.setTitle('lol') self.assertEqual('lol', self.book.getTitle()) self.book.setAuthor('da') self.assertEqual('da', self.book.getAuthor()) self.book.setDescription('da') self.assertEqual('da', self.book.getDescription()) self.assertEqual(str(self.book), '021. lol by da\n->da\nStatus: Available\n') self.book.set_available(False) self.assertEqual(False, self.book.get_available()) self.assertEqual(str(self.book), '021. lol by da\n->da\nStatus: Unavailable\n') self.assertNotEqual(self.book, self.book2) self.assertEqual(self.book.create_book(21, 'titlu', 'descriere', 'author'), self.book) def test_create_rental(self): self.assertEqual(21236, self.rental.getID()) self.assertEqual(21, self.rental.getBookID()) self.assertEqual(23, self.rental.getClientID()) self.assertEqual(date(2017, 12, 6), self.rental.getDueDate()) self.assertEqual(date(2017, 11, 5), self.rental.getRentedDate()) self.assertEqual(date(2017, 12, 5), self.rental.getReturnedDate()) self.assertEqual('Rental 21236: book: 21 rented by client 23 on 05.11.2017 and is due by 06.12.2017', str(self.rental)) self.rental.setBookID(21) self.rental.setClientID(23) self.rental.setReturnedDate(date(2017, 12, 12)) self.rental.setDueDate(date(2017, 11, 21)) self.rental.setRentedDate(date(2017, 9, 23)) self.assertEqual(len(self.rental), 80) self.rental.setReturnedDate(None) self.assertEqual(len(self.rental), 0) self.assertEqual(self.rental.getDelay(), (date.today()-self.rental.getDueDate()).days) self.assertEqual(self.rental, self.rental2) self.rental.setReturnedDate(date(2017, 12, 12)) self.assertEqual(self.rental.create_rental(21, 23, 12, 5).getBookID(), 21) self.assertEqual(self.rental.printReturned(self.rental), 'Rental 21236: book: 21 rented by client 23 on 23.09.2017 was returned on 12.12.2017')
def test_domains(self): ''' tests the implicit functions of book, client and rent domains ''' book1 = Book(1, "Persona 3", "3rd entry in the series", "Shuji Sogabe") book2 = Book(2, "Persona 5", "5th entry in the series", "Atlus") assert book1.get_id() == 1 assert book2.get_title() == "Persona 5" assert book1.get_desc() == "3rd entry in the series" assert book2.get_author() == "Atlus" assert Book.__str__( book1 ) == "Persona 3 by Shuji Sogabe described as '3rd entry in the series' with id 1" try: Book("Five", 5, 324, "Name") assert False except ValueError: pass book1.set_id(8) book1.set_author("banana") book1.set_title("coconut") book1.set_desc("fruits") assert book1.get_id() == 8 assert book1.get_desc() == "fruits" assert book1.get_author() == "banana" assert book1.get_title() == "coconut" client1 = Client(1, "Scott Fitzgerald") client2 = Client(2, "Shuji Sogabe") assert client1.get_id() == 1 assert client2.get_name() == "Shuji Sogabe" assert Client.__str__(client1) == "Scott Fitzgerald with id 1" try: Client("Five", "Name") assert False except ValueError: pass client1.set_id(8) client1.set_name("banana") assert client1.get_id() == 8 assert client1.get_name() == "banana" rent = Rental(12, 23, 34, datetime(2018, 2, 2), datetime(2018, 2, 16), datetime(2018, 2, 10)) assert rent.get_bookID() == 23 assert rent.get_clientID() == 12 assert rent.get_rentalID() == 34 assert str(rent.get_due_date()) == "2018-02-16 00:00:00" assert str(rent.get_return_date()) == "2018-02-10 00:00:00" assert str(rent.get_rented_date()) == "2018-02-02 00:00:00" rent.set_bookID(23) rent.set_clientID(9) rent.set_rentalID(10) rent.set_rented_date(datetime(2018, 11, 3)) rent.set_return_date(datetime(2018, 8, 31)) rent.set_due_date(datetime(2018, 2, 8)) assert rent.get_bookID() == 23 assert rent.get_clientID() == 9 assert rent.get_rentalID() == 10 assert str(rent.get_due_date()) == "2018-02-08 00:00:00" assert str(rent.get_return_date()) == "2018-08-31 00:00:00" assert str(rent.get_rented_date()) == "2018-11-03 00:00:00"