本文整理汇总了Python中models.Photo.parse方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.parse方法的具体用法?Python Photo.parse怎么用?Python Photo.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.parse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_parse_photo
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import parse [as 别名]
def test_parse_photo(self):
response = '''{"response":[{"pid":"146771291","aid":"100001227","owner_id":"6492",
"src":"http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg",
"src_big":"http://cs9231.vkontakte.ru/u06492/100001227/x_cd563004.jpg",
"src_small":"http://cs9231.vkontakte.ru/u06492/100001227/s_c3bba2a8.jpg",
"src_xbig":"http://cs9231.vkontakte.ru/u06492/100001227/y_62a74569.jpg",
"src_xxbig":"http://cs9231.vkontakte.ru/u06492/100001227/z_793e9682.jpg",
"text":"test","user_id":6492,"width":10,"height":10,
"created":"1298365200"},{"pid":"146772677","aid":"100001227","owner_id":-6492,
"src":"http://cs9231.vkontakte.ru/u06492/100001227/m_fd092958.jpg",
"src_big":"http://cs9231.vkontakte.ru/u06492/100001227/x_1f8ec9b8.jpg",
"src_small":"http://cs9231.vkontakte.ru/u06492/100001227/s_603d27ab.jpg",
"src_xbig":"http://cs9231.vkontakte.ru/u06492/100001227/y_6938f576.jpg",
"src_xxbig":"http://cs9231.vkontakte.ru/u06492/100001227/z_6a27e9fd.jpg",
"text":"test","user_id":6492,"width":10,"height":10,
"created":"1260887080"}]}
'''
instance = Photo()
owner = UserFactory.create(remote_id=6492)
album = AlbumFactory.create(remote_id='6492_100001227')
instance.parse(json.loads(response)['response'][0])
instance.save()
self.assertEqual(instance.remote_id, '6492_146771291')
self.assertEqual(instance.album, album)
self.assertEqual(instance.owner, owner)
self.assertEqual(instance.created, datetime(2011,2,22,9,0,0))
self.assertEqual(instance.src, 'http://cs9231.vkontakte.ru/u06492/100001227/m_7875d2fb.jpg')
self.assertEqual(instance.text, 'test')
self.assertEqual(instance.width, 10)
self.assertEqual(instance.height, 10)
instance = Photo()
group = GroupFactory.create(remote_id=6492)
album = AlbumFactory.create(remote_id='-6492_100001227')
instance.parse(json.loads(response)['response'][1])
instance.save()
self.assertEqual(instance.remote_id, '-6492_146772677')
self.assertEqual(instance.album, album)
self.assertEqual(instance.group, group)