示例#1
0
    def testSearchCategoryByName(self):
        category_one = Category(name='One')
        category_two = Category(name='Two')
        db.session.add_all([category_one, category_two])
        db.session.commit()
        book_one = Book(name='New World Order', category=category_one)
        book_two = Book(name='Things Fall Apart', category=category_two)
        book_three = Book(name='Pinkberry', category=category_two)
        book_four = Book(name='New Scopes', category=category_two)
        db.session.add_all([book_one, book_two, book_three, book_four])
        db.session.commit()

        self.assertEqual(len(category_one.books.all()), 1)
        self.assertEqual(len(category_two.books.all()), 3)
        self.assertEqual(len(Book.findByCategoryName(category_two.name)), 3)
        self.assertIsNone(Book.findByCategoryName('New Category'))