class TestBookController(unittest.TestCase): 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 test_something(self): self.Ucontroller.newOperation() self.controller.addBook(self.book) self.assertEqual(len(self.repo), 1) self.Ucontroller.newOperation() self.controller.removeBook(21) self.assertEqual(len(self.repo), 0) self.Ucontroller.newOperation() self.controller.addBook(self.book) self.Ucontroller.newOperation() self.controller.updateBook(self.book) self.Ucontroller.newOperation() self.controller.addBook(self.book2) self.assertEqual(len(self.controller.getAllBooks()), 2) self.assertEqual(self.controller.getBook(22), self.book2) self.assertRaises(ControllerException, self.controller.searchBook, 'nu') self.assertRaises(ControllerException, self.controller.searchBook, '') self.assertEqual(len(self.controller.searchBook('tit')), 2) self.Ucontroller.newOperation() self.controller.removeBook(22) self.assertEqual( str(self.controller), '021. titlu by author\n->descriere\nStatus: Available\n\n')
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())