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 testRemoveBook(self): book1 = Book(1, "Title", "Description", "Author") book2 = Book(2, "Title1", "Description1", "Author1") book3 = Book(3, "Title2", "Description2", "Author2") repo = Repository() functions = BookController(repo, Statistics(repo)) functions.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor()) functions.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor()) functions.addBook(book3.getId(), book3.getTitle(), book3.getDescription(), book3.getAuthor()) msg1 = functions.removeBook(1) self.assertTrue(len(msg1) == 0) self.assertTrue(functions.getBooks()[0].getId() == book2.getId()) self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle()) self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription()) self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor()) msg2 = functions.removeBook(1) self.assertTrue(msg2 == "The provided ID does not exist") self.assertTrue(functions.getBooks()[0].getId() == book2.getId()) self.assertTrue(functions.getBooks()[0].getTitle() == book2.getTitle()) self.assertTrue(functions.getBooks()[0].getDescription() == book2.getDescription()) self.assertTrue(functions.getBooks()[0].getAuthor() == book2.getAuthor())
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 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 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 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 testAddBook(self): book1 = Book(1, "Title", "Description", "Author") book2 = Book(2, "Title1", "Description1", "Author1") book3 = Book(1, "Title2", "Description2", "Author2") repo = Repository() functions = BookController(repo, Statistics(repo)) msg1 = functions.addBook(book1.getId(), book1.getTitle(), book1.getDescription(), book1.getAuthor()) self.assertTrue(msg1 == "") self.assertTrue(functions.getBooks()[0].getId() == book1.getId()) self.assertTrue(functions.getBooks()[0].getTitle() == book1.getTitle()) self.assertTrue(functions.getBooks()[0].getDescription() == book1.getDescription()) self.assertTrue(functions.getBooks()[0].getAuthor() == book1.getAuthor()) msg2 = functions.addBook(book2.getId(), book2.getTitle(), book2.getDescription(), book2.getAuthor()) self.assertTrue(msg2 == "") self.assertTrue(functions.getBooks()[1].getId() == book2.getId()) self.assertTrue(functions.getBooks()[1].getTitle() == book2.getTitle()) self.assertTrue(functions.getBooks()[1].getDescription() == book2.getDescription()) self.assertTrue(functions.getBooks()[1].getAuthor() == book2.getAuthor()) msg3 = functions.addBook(book3.getId(), book3.getTitle(), book3.getDescription(), book3.getAuthor()) self.assertTrue(msg3 == "Cannot add an existing element") self.assertTrue(functions.getBooks()[1].getId() == book2.getId()) self.assertTrue(functions.getBooks()[1].getTitle() == book2.getTitle()) self.assertTrue(functions.getBooks()[1].getDescription() == book2.getDescription()) self.assertTrue(functions.getBooks()[1].getAuthor() == book2.getAuthor()) self.assertTrue(functions.getBooks()[0].getId() == book1.getId()) self.assertTrue(functions.getBooks()[0].getTitle() == book1.getTitle()) self.assertTrue(functions.getBooks()[0].getDescription() == book1.getDescription()) self.assertTrue(functions.getBooks()[0].getAuthor() == book1.getAuthor())