本文整理汇总了Python中books.models.Book.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Book.delete方法的具体用法?Python Book.delete怎么用?Python Book.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类books.models.Book
的用法示例。
在下文中一共展示了Book.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BookTest
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import delete [as 别名]
class BookTest(TestCase):
def setUp(self):
self.author1 = AuthorFactory(name="Author 1")
self.author2 = AuthorFactory(name="Author 2")
self.book = Book(title="MyBook")
self.book.save()
self.book.authors.add(self.author1.pk, self.author2.pk)
def tearDown(self):
self.author1.delete()
self.author2.delete()
self.book.delete()
def test_can_list_authors(self):
self.assertEqual("Author 1, Author 2", self.book.list_authors())
def test_string_method(self):
self.assertEqual("MyBook by Author 1, Author 2", self.book.__str__())
def test_custom_save_method(self):
self.assertIsNone(self.book.date_reviewed)
self.book.review = "My Review"
self.book.save()
self.assertIsNotNone(self.book.date_reviewed)
示例2: BookTest
# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import delete [as 别名]
class BookTest(TestCase):
# Django requires an explicit setup() when running tests in PTVS
@classmethod
def setUpClass(cls):
django.setup()
super(BookTest, cls).setUpClass()
# setUp will run before each test
def setUp(self):
self.author1 = AuthorFactory(name="Author 1")
self.author2 = AuthorFactory(name="Author 2")
self.book = Book(title="MyBook")
self.book.save()
self.book.authors.add(self.author1.pk, self.author2.pk)
# tearDown will run after each test
def tearDown(self):
self.author1.delete()
self.author2.delete()
self.book.delete()
# UNIT TESTS
def test_can_list_authors(self):
self.assertEqual("Author 1, Author 2", self.book.list_authors())
def test_string_method(self):
self.assertEqual("MyBook by Author 1, Author 2", self.book.__str__())
def test_custom_save_method(self):
self.assertIsNone(self.book.date_reviewed)
self.book.review = "My review"
self.book.save()
self.assertIsNotNone(self.book.date_reviewed)