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


Python PlaylistTrack.key方法代码示例

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


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

示例1: test_cannot_delete_someone_elses_track

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
    def test_cannot_delete_someone_elses_track(self):
        other_user = User(email="[email protected]")
        other_user.roles.append(auth.roles.DJ)
        other_user.put()
        time.sleep(0.4)

        other_track = PlaylistTrack(
                    playlist=self.playlist,
                    selector=other_user,
                    freeform_artist_name="Peaches",
                    freeform_track_title="Rock Show",)
        other_track.put()

        with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url):
            resp = self.client.get(reverse('playlists_delete_event',
                                            args=[other_track.key()]))

        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))

        # should be no change:
        context = resp.context[0]
        tracks = [t.artist_name for t in context['playlist_events']]
        self.assertEquals(tracks, ["Peaches", "Steely Dan"])
开发者ID:CDMirel,项目名称:chirpradio,代码行数:27,代码来源:test_views.py

示例2: test_different_tracks

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
 def test_different_tracks(self):
     self.count()
     new_trk = PlaylistTrack(
         playlist=self.track.playlist,
         selector=self.track.selector,
         freeform_artist_name='Prince',
         freeform_album_title='Purple Rain',
         freeform_track_title='When Doves Cry')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     track_ids = [str(w.key()) for w in PlayCount.all()]
     assert track_ids[0] != track_ids[1], (
         'Different artist/albums cannot have the same key')
开发者ID:CDMirel,项目名称:chirpradio,代码行数:16,代码来源:test_views.py

示例3: test_count_different_track

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
 def test_count_different_track(self):
     self.count()
     # Copy the same artist/track into a new track.
     new_trk = PlaylistTrack(
         playlist=self.track.playlist,
         selector=self.track.selector,
         freeform_artist_name=self.track.freeform_artist_name,
         freeform_album_title=self.track.freeform_album_title,
         freeform_track_title='Another track from the album')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     eq_(count.artist_name, self.track.freeform_artist_name)
     eq_(count.album_title, self.track.freeform_album_title)
     eq_(count.label, self.track.label)
     eq_(count.play_count, 2)
开发者ID:CDMirel,项目名称:chirpradio,代码行数:18,代码来源:test_views.py

示例4: test_freeform_compilation

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
 def test_freeform_compilation(self):
     stevie, talking_book, tracks = create_stevie_wonder_album_data()
     talking_book.is_compilation = True
     talking_book.put()
     for artist, track in (('Stevie Wonder', 'Superstition'),
                           ('Stevie Wonder', 'Big Brother')):
         new_trk = PlaylistTrack(
             playlist=self.track.playlist,
             selector=self.track.selector,
             freeform_album_title='Talking Book',
             freeform_artist_name=artist,
             freeform_track_title=track,
             freeform_label='...')
         new_trk.put()
         self.count(track_key=new_trk.key())
     res = self.snapshot()
     eq_(res.status_code, 200)
     snap = PlayCountSnapshot.all()[0]
     eq_(snap.play_count, 2)
     eq_(snap.artist_name, 'Various')
     eq_(snap.album_title, 'Talking Book')
开发者ID:CDMirel,项目名称:chirpradio,代码行数:23,代码来源:test_views.py

示例5: TestLive365PlaylistTasks

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
class TestLive365PlaylistTasks(TaskTest, TestCase):

    def test_create_not_latin_chars(self):

        def inspect_request(r):
            # NOTE: due to URL fetching, you can only raise
            # AssertionError here
            self.assertEqual(r.get_full_url(), 'http://__dummylive365service__/cgi-bin/add_song.cgi')
            qs = dict(cgi.parse_qsl(r.data))
            self.assertEqual(qs['member_name'], "dummy_member")
            self.assertEqual(qs['password'], "dummy_password")
            self.assertEqual(qs['seconds'], '30')
            # c should be replaced because latin-1 can't encode that and Live365 likes latin-1
            self.assertEqual(qs['title'], 'Ivan Krsti song')
            self.assertEqual(qs['album'], 'Ivan Krsti album')
            self.assertEqual(qs['artist'], 'Ivan Krsti')
            return True

        fake_urlopen = (fudge.Fake('urlopen', expect_call=True)
                                .with_args(arg.passes_test(inspect_request)))

        fake_response = (fake_urlopen
                                .returns_fake()
                                .has_attr(code='200')
                                .provides('read')
                                .returns("<service response>"))

        with fudge.patched_context(playlists.tasks.urllib2, "urlopen", fake_urlopen):
            resp = self.client.post(reverse('playlists.send_track_to_live365'), {
                'id': self.track.key()
            })

        fudge.verify()

    def test_create_latin_chars(self):

        self.playlist = ChirpBroadcast()
        selector = self.get_selector()
        self.track = PlaylistTrack(
                    playlist=self.playlist,
                    selector=selector,
                    freeform_artist_name=u'Bj\xf6rk',
                    freeform_album_title=u'Bj\xf6rk album',
                    freeform_track_title=u'Bj\xf6rk song')
        self.track.put()

        def inspect_request(r):
            # NOTE: due to URL fetching, you can only raise
            # AssertionError here
            self.assertEqual(r.get_full_url(), 'http://__dummylive365service__/cgi-bin/add_song.cgi')
            qs = dict(cgi.parse_qsl(r.data))
            self.assertEqual(qs['member_name'], "dummy_member")
            self.assertEqual(qs['password'], "dummy_password")
            self.assertEqual(qs['seconds'], '30')
            # c should be replaced because latin-1 can't encode that and Live365 likes latin-1
            self.assertEqual(qs['title'], 'Bj\xf6rk song')
            self.assertEqual(qs['album'], 'Bj\xf6rk album')
            self.assertEqual(qs['artist'], 'Bj\xf6rk')
            return True

        fake_urlopen = (fudge.Fake('urlopen', expect_call=True)
                                .with_args(arg.passes_test(inspect_request)))

        fake_response = (fake_urlopen
                                .returns_fake()
                                .has_attr(code='200')
                                .provides('read')
                                .returns("<service response>"))

        with fudge.patched_context(playlists.tasks.urllib2, "urlopen", fake_urlopen):
            resp = self.client.post(reverse('playlists.send_track_to_live365'), {
                'id': self.track.key()
            })

        fudge.verify()

    def test_create_ascii_chars(self):

        self.playlist = ChirpBroadcast()
        selector = self.get_selector()
        self.track = PlaylistTrack(
                    playlist=self.playlist,
                    selector=selector,
                    freeform_artist_name=u'artist',
                    freeform_album_title=u'album',
                    freeform_track_title=u'song')
        self.track.put()

        def inspect_request(r):
            # NOTE: due to URL fetching, you can only raise
            # AssertionError here
            self.assertEqual(r.get_full_url(), 'http://__dummylive365service__/cgi-bin/add_song.cgi')
            qs = dict(cgi.parse_qsl(r.data))
            self.assertEqual(qs['member_name'], "dummy_member")
            self.assertEqual(qs['password'], "dummy_password")
            self.assertEqual(qs['seconds'], '30')
            # c should be replaced because latin-1 can't encode that and Live365 likes latin-1
            self.assertEqual(qs['title'], 'song')
            self.assertEqual(qs['album'], 'album')
            self.assertEqual(qs['artist'], 'artist')
#.........这里部分代码省略.........
开发者ID:CDMirel,项目名称:chirpradio,代码行数:103,代码来源:test_views.py

示例6: TestDeleteTrackFromPlaylist

# 需要导入模块: from playlists.models import PlaylistTrack [as 别名]
# 或者: from playlists.models.PlaylistTrack import key [as 别名]
class TestDeleteTrackFromPlaylist(PlaylistViewsTest):

    def setUp(self):
        super(TestDeleteTrackFromPlaylist, self).setUp()
        self.playlist = ChirpBroadcast()
        selector = self.get_selector()
        self.track = PlaylistTrack(
                    playlist=self.playlist,
                    selector=selector,
                    freeform_artist_name="Steely Dan",
                    freeform_album_title="Aja",
                    freeform_track_title="Peg")
        self.track.put()

    def test_delete_known_track(self):
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Steely Dan")

        def inspect_request(r):
            self.assertEqual(r.get_full_url(),
                'http://testapi/playlist/delete/%s' % self.track.key())
            self.assertEqual(r.http_method, 'DELETE')
            return True

        fake_urlopen = (fudge.Fake('urlopen', expect_call=True)
                                .with_args(arg.passes_test(inspect_request)))

        fake_response = (fake_urlopen
                                .returns_fake()
                                .has_attr(code='200')
                                .provides('read')
                                .returns("<service response>"))

        with fudge.patched_context(playlists.tasks.urllib2, "urlopen", fake_urlopen):
            resp = self.client.get(reverse('playlists_delete_event',
                                            args=[self.track.key()]))

        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks, [])

    def test_delete_unknown_track(self):
        resp = self.client.get(reverse('playlists_landing_page'))
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Steely Dan")

        resp = self.client.get(reverse('playlists_delete_event',
                                        args=['<bogus-key>']))

        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))

        # should be no change:
        context = resp.context[0]
        tracks = [t for t in context['playlist_events']]
        self.assertEquals(tracks[0].artist_name, "Steely Dan")

    def test_cannot_delete_someone_elses_track(self):
        other_user = User(email="[email protected]")
        other_user.roles.append(auth.roles.DJ)
        other_user.put()
        time.sleep(0.4)

        other_track = PlaylistTrack(
                    playlist=self.playlist,
                    selector=other_user,
                    freeform_artist_name="Peaches",
                    freeform_track_title="Rock Show",)
        other_track.put()

        with fudge.patched_context(playlists.tasks, "_fetch_url", stub_fetch_url):
            resp = self.client.get(reverse('playlists_delete_event',
                                            args=[other_track.key()]))

        self.assertRedirects(resp, reverse('playlists_landing_page'))
        # simulate the redirect:
        resp = self.client.get(reverse('playlists_landing_page'))

        # should be no change:
        context = resp.context[0]
        tracks = [t.artist_name for t in context['playlist_events']]
        self.assertEquals(tracks, ["Peaches", "Steely Dan"])

    def test_delete_link_appears_for_current_user(self):
        resp = self.client.get(reverse('playlists_landing_page'))
        assert '[delete]' in resp.content

        for track in PlaylistTrack.all():
            track.delete()

        other_user = User(email="[email protected]")
        other_user.roles.append(auth.roles.DJ)
        other_user.put()
#.........这里部分代码省略.........
开发者ID:CDMirel,项目名称:chirpradio,代码行数:103,代码来源:test_views.py


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