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


Python Playlist.add_new_playlist方法代码示例

本文整理汇总了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())
开发者ID:chris-womack,项目名称:Party-Queue,代码行数:11,代码来源:party_queue_api.py

示例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)
开发者ID:chris-womack,项目名称:Party-Queue,代码行数:64,代码来源:models_test.py


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