本文整理汇总了Python中tests.models.Band.from_serializable_data方法的典型用法代码示例。如果您正苦于以下问题:Python Band.from_serializable_data方法的具体用法?Python Band.from_serializable_data怎么用?Python Band.from_serializable_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.models.Band
的用法示例。
在下文中一共展示了Band.from_serializable_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deserialize
# 需要导入模块: from tests.models import Band [as 别名]
# 或者: from tests.models.Band import from_serializable_data [as 别名]
def test_deserialize(self):
beatles = Band.from_serializable_data({
'pk': 9,
'albums': [],
'name': 'The Beatles',
'members': [
{'pk': None, 'name': 'John Lennon', 'band': None},
{'pk': None, 'name': 'Paul McCartney', 'band': None},
]
})
self.assertEqual(9, beatles.id)
self.assertEqual('The Beatles', beatles.name)
self.assertEqual(2, beatles.members.count())
self.assertEqual(BandMember, beatles.members.all()[0].__class__)
authors = {}
categories = {}
for ii in range(1, 6):
authors[ii] = Author.objects.create(name="Author " + str(ii))
categories[ii] = Category.objects.create(name="Category " + str(ii))
article = Article.from_serializable_data({
'pk': 1,
'title': 'Article Title 1',
'authors': [authors[1].pk, authors[2].pk],
'categories': [categories[2].pk, categories[3].pk, categories[4].pk]
})
self.assertEqual(article.id, 1)
self.assertEqual(article.title, 'Article Title 1')
self.assertEqual(article.authors.count(), 2)
self.assertEqual([author.name for author in article.authors.all()],
['Author 1', 'Author 2'])
self.assertEqual(article.categories.count(), 3)
示例2: test_deserialize
# 需要导入模块: from tests.models import Band [as 别名]
# 或者: from tests.models.Band import from_serializable_data [as 别名]
def test_deserialize(self):
beatles = Band.from_serializable_data({
'pk': 9,
'albums': [],
'name': 'The Beatles',
'members': [
{'pk': None, 'name': 'John Lennon', 'band': None},
{'pk': None, 'name': 'Paul McCartney', 'band': None},
]
})
self.assertEqual(9, beatles.id)
self.assertEqual('The Beatles', beatles.name)
self.assertEqual(2, beatles.members.count())
self.assertEqual(BandMember, beatles.members.all()[0].__class__)