當前位置: 首頁>>代碼示例>>Python>>正文


Python User.username方法代碼示例

本文整理匯總了Python中mygpo.users.models.User.username方法的典型用法代碼示例。如果您正苦於以下問題:Python User.username方法的具體用法?Python User.username怎麽用?Python User.username使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mygpo.users.models.User的用法示例。


在下文中一共展示了User.username方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_merge

# 需要導入模塊: from mygpo.users.models import User [as 別名]
# 或者: from mygpo.users.models.User import username [as 別名]
    def test_merge(self):

        p1 = Podcast()
        p1.urls = ['http://example.com/podcast1.rss']
        p1.save()

        p2 = Podcast()
        p2.urls = ['http://example.com/podcast2.rss']
        p2.save()


        e1 = Episode()
        e1.title = 'Episode 1'
        e1.podcast = p1.get_id()
        e1.urls = ['http://example.com/podcast1/e1.mp3']
        e1.save()

        e2 = Episode()
        e2.title = 'Episode 2'
        e2.podcast = p1.get_id()
        e2.urls = ['http://example.com/podcast1/e2.mp3']
        e2.save()

        e3 = Episode()
        e3.title = 'Episode 3'
        e3.podcast = p2.get_id()
        e3.urls = ['http://example.com/podcast2/e2.mp3']
        e3.save()

        e4 = Episode()
        e4.title = 'Episode 4'
        e4.podcast = p2.get_id()
        e4.urls = ['http://example.com/podcast2/e3.mp3']
        e4.save()

        user = User()
        user.username = 'user'
        user.email = '[email protected]'
        user.set_password('secret')

        device1 = Device()
        device1.uid = 'dev1'

        device2 = Device()
        device2.uid = 'dev2'

        user.devices.append(device1)
        user.devices.append(device2)
        user.save()


        p1.subscribe(user, device1)
        time.sleep(1)
        p1.unsubscribe(user, device1)
        time.sleep(1)
        p1.subscribe(user, device1)
        p2.subscribe(user, device2)

        s1 = e1.get_user_state(user)
        s1.add_actions([EpisodeAction(action='play')])
        s1.save()

        s3 = e3.get_user_state(user)
        s3.add_actions([EpisodeAction(action='play')])
        s3.save()

        # we need that for later
        e3_id = e3._id

        actions = Counter()

        # decide which episodes to merge
        groups = [(0, [e1]), (1, [e2, e3]), (2, [e4])]

        # carry out the merge
        pm = PodcastMerger([p1, p2], actions, groups)
        pm.merge()

        e1 = Episode.get(e1._id)
        es1 = e1.get_user_state(user)
        self.assertEqual(len(es1.actions), 1)

        # check if merged episode's id can still be accessed
        e3 = Episode.get(e3_id)
        es3 = e3.get_user_state(user)
        self.assertEqual(len(es3.actions), 1)

        p1 = Podcast.get(p1.get_id())
        ps1 = p1.get_user_state(user)
        self.assertEqual(len(ps1.get_subscribed_device_ids()), 2)

        self.assertEqual(len(list(p1.get_episodes())), 3)
開發者ID:Mic92,項目名稱:mygpo,代碼行數:94,代碼來源:tests.py


注:本文中的mygpo.users.models.User.username方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。