当前位置: 首页>>代码示例>>Python>>正文


Python Book.list_authors方法代码示例

本文整理汇总了Python中books.models.Book.list_authors方法的典型用法代码示例。如果您正苦于以下问题:Python Book.list_authors方法的具体用法?Python Book.list_authors怎么用?Python Book.list_authors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在books.models.Book的用法示例。


在下文中一共展示了Book.list_authors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: BookTest

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import list_authors [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)
开发者ID:IDdesigner,项目名称:readit,代码行数:27,代码来源:test_models.py

示例2: BookTest

# 需要导入模块: from books.models import Book [as 别名]
# 或者: from books.models.Book import list_authors [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)
开发者ID:madrus,项目名称:django-readit,代码行数:36,代码来源:test_models.py


注:本文中的books.models.Book.list_authors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。