def test_find_category(self):
     """ Find a Category by ID """
     Category(name="Dog").save()
     cat = Category(name="Cat")
     cat.save()
     category = Category.find(cat.id)
     self.assertIsNot(category, None)
     self.assertEqual(category.id, cat.id)
     self.assertEqual(category.name, "Cat")
Пример #2
0
def append_categories_to_book(book, categories):
    if not categories:
        return

    if book.id:
        book.categories = []
        book.save()

    for category_id in categories:
        category = Category.find(category_id)
        if category:
            book.categories.append(category)
 def test_category_not_found(self):
     """ Test for a Category that doesn't exist """
     Category(name="Dog").save()
     category = Category.find(99999)
     self.assertIs(category, None)
 def test_find_with_no_categories(self):
     """ Find a Category with no Categorys """
     category = Category.find(1)
     self.assertIs(category, None)