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


Python Podcast.group_with方法代码示例

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


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

示例1: PodcastGroupTests

# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import group_with [as 别名]
class PodcastGroupTests(unittest.TestCase):
    def test_group(self):
        self.podcast1 = Podcast(urls=["http://example1.com"])
        self.podcast1.save()

        self.podcast2 = Podcast(urls=["http://example2.com"])
        self.podcast2.save()

        group = self.podcast1.group_with(self.podcast2, "My Group", "p1", "p2")

        self.assertIn(self.podcast1, group.podcasts)
        self.assertIn(self.podcast2, group.podcasts)
        self.assertEquals(len(group.podcasts), 2)
        self.assertEquals(group.title, "My Group")
        self.assertEquals(self.podcast1.group_member_name, "p1")
        self.assertEquals(self.podcast2.group_member_name, "p2")

        # add to group
        self.podcast3 = Podcast(urls=["http://example3.com"])
        self.podcast3.save()

        group = self.podcast1.group_with(self.podcast3, "My Group", "p1", "p3")

        self.assertIn(self.podcast3, group.podcasts)
        self.assertEquals(self.podcast3.group_member_name, "p3")

        # add group to podcast
        self.podcast4 = Podcast(urls=["http://example4.com"])
        self.podcast4.save()

        group = self.podcast4.group_with(self.podcast1, "My Group", "p4", "p1")

        self.assertIn(self.podcast4, group.podcasts)
        self.assertEquals(self.podcast4.group_member_name, "p4")
开发者ID:Mic92,项目名称:mygpo,代码行数:36,代码来源:tests.py

示例2: MergeGroupTests

# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import group_with [as 别名]
class MergeGroupTests(TestCase):
    """ Tests merging of two podcasts, one of which is part of a group """

    def setUp(self):
        self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
        self.podcast2 = Podcast(urls=['http://test.org/podcast/'])
        self.podcast3 = Podcast(urls=['http://test.org/feed/'])
        self.podcast1.save()
        self.podcast2.save()
        self.podcast3.save()

        self.episode1 = Episode(podcast=self.podcast1.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode2 = Episode(podcast=self.podcast2.get_id(),
                urls = ['http://example.com/episode1.mp3'])
        self.episode3 = Episode(podcast=self.podcast3.get_id(),
                urls = ['http://example.com/media.mp3'])


        self.episode1.save()
        self.episode2.save()
        self.episode3.save()

        self.podcast2.group_with(self.podcast3, 'My Group', 'Feed1', 'Feed2')

        self.user = User(username='test-merge-group')
        self.user.email = '[email protected]'
        self.user.set_password('secret!')
        self.user.save()


    def test_merge_podcasts(self):

        podcast1 = podcast_by_id(self.podcast1.get_id())
        podcast2 = podcast_by_id(self.podcast2.get_id())
        podcast3 = podcast_by_id(self.podcast3.get_id())

        # assert that the podcasts are actually grouped
        self.assertEqual(podcast2._id, podcast3._id)
        self.assertNotEqual(podcast2.get_id(), podcast2._id)
        self.assertNotEqual(podcast3.get_id(), podcast3._id)

        # Create additional data that will be merged
        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, self.episode2)

        action1 = EpisodeAction(action='play',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))
        action2 = EpisodeAction(action='download',
                timestamp=datetime.utcnow(),
                upload_timestamp=get_timestamp(datetime.utcnow()))

        add_episode_actions(state1, [action1])
        add_episode_actions(state2, [action2])

        # copy of the object
        episode2 = episode_by_id(self.episode2._id)

        # decide which episodes to merge
        groups = [(0, [self.episode1, self.episode2])]
        counter = Counter()

        pm = PodcastMerger([podcast2, podcast1], counter, groups)
        pm.merge()

        state1 = episode_state_for_user_episode(self.user, self.episode1)
        state2 = episode_state_for_user_episode(self.user, episode2)

        self.assertIn(action1, state1.actions)
        self.assertIn(action2, state1.actions)
        self.assertEqual(state2._id, None)

        episode1 = episode_by_id(self.episode1._id)

        # episode2 has been merged into episode1, so it must contain its
        # merged _id
        self.assertEqual(episode1.merged_ids, [episode2._id])



    def tearDown(self):
        self.podcast2.delete()
        self.episode1.delete()

        #self.podcast2.delete()
        #self.episode2.delete()

        self.user.delete()
开发者ID:fk-lx,项目名称:mygpo,代码行数:91,代码来源:tests.py


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