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 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())
Example #3
0
def getBooks():
    bookController = BookController()
    return jsonify(bookController.getBooks())