本文整理汇总了Python中models.Playlist.add_new_playlist方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.add_new_playlist方法的具体用法?Python Playlist.add_new_playlist怎么用?Python Playlist.add_new_playlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Playlist
的用法示例。
在下文中一共展示了Playlist.add_new_playlist方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_playlist
# 需要导入模块: from models import Playlist [as 别名]
# 或者: from models.Playlist import add_new_playlist [as 别名]
def create_playlist(self, request):
""" Creates a playlist for the user """
# TODO: Max amount of playlists at 20 for a user
user = Account.find_by_id(request.userid)
if user is None:
print "User not found"
return PlaylistResponse(errmsg="User ID not found")
new_pl = Playlist.add_new_playlist(user.key, request.name)
return PlaylistResponse(pid=new_pl.key.id())
示例2: test_playlist
# 需要导入模块: from models import Playlist [as 别名]
# 或者: from models.Playlist import add_new_playlist [as 别名]
def test_playlist(self):
owner=Account(username='Mr. Magoo', email='[email protected]').put()
pl = []
pl.append(Playlist(owner=owner, name='MM\'s awesome playlist'))
pl[0].put()
self.assertEqual(1, len(Playlist.query().fetch(2)))
# test find by id
found = Playlist.find_by_id(pl[0].key.id())
self.assertEqual(pl[0], found, 'Failed to find playlist based on id')
# test add new playlist
pl.append(Playlist.add_new_playlist(owner,
'A great playlist'))
self.assertEqual(2, len(Playlist.query().fetch(3)))
# test find by owner
pl.append(Playlist(owner=owner, name='MM\'s other awesome playlist'))
pl[2].put()
self.assertEqual(3, len(Playlist.query().fetch(4)))
pl_sorted = sorted(pl, key=lambda Playlist: Playlist.name)
found_pl = Playlist.find_by_owner(owner).fetch(3)
for i in range(len(found_pl)):
self.assertEqual(pl_sorted[i], found_pl[i])
# test add song
request = PlaylistRequest(pl_sorted[0].key.id(),
'1892300kdkeo',
'Space Oddity')
Playlist.add_song(request)
self.assertEqual(1, len(pl_sorted[0].songs), 'add_song failed to add song')
self.assertEqual('1892300kdkeo', pl_sorted[0].songs[0].spotify_id)
self.assertEqual('Space Oddity', pl_sorted[0].songs[0].name)
self.assertEqual(0, pl_sorted[0].songs[0].vote_count)
# Upvote a song
new_request = PlaylistRequest(pl_sorted[0].key.id(),
'asdlfjsadlfkj',
'What A Wonderful World')
Playlist.add_song(new_request)
songs = Song.find_by_playlist(pl_sorted[0].key)
self.assertEqual(2, len(songs.fetch(4)), 'Failed to find songs by playlist id')
song_entity = songs.get()
Song.upvote(song_entity.key.id())
self.assertEqual(1, song_entity.vote_count, song_entity)
songs_on_pl = pl_sorted[0].songs
self.assertEqual(1, songs_on_pl[0].vote_count, songs_on_pl)
song_entity = songs.fetch(2)[1]
Song.upvote(song_entity.key.id())
Song.upvote(song_entity.key.id())
songs = Song.find_by_playlist(pl_sorted[0].key).fetch(2)
self.assertEqual('What A Wonderful World', songs[0].name, song_entity)
self.assertEqual(2, songs[0].vote_count, song_entity)
# downvote
self.assertEqual(2, song_entity.vote_count)
Song.downvote(song_entity.key.id())
self.assertEqual(1, song_entity.vote_count)