本文整理汇总了Python中mygpo.core.models.Podcast.subscribe方法的典型用法代码示例。如果您正苦于以下问题:Python Podcast.subscribe方法的具体用法?Python Podcast.subscribe怎么用?Python Podcast.subscribe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mygpo.core.models.Podcast
的用法示例。
在下文中一共展示了Podcast.subscribe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UnsubscribeMergeTests
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import subscribe [as 别名]
class UnsubscribeMergeTests(TestCase):
""" Test if merged podcasts can be properly unsubscribed
TODO: this test fails intermittently """
P2_URL = 'http://test.org/podcast/'
def setUp(self):
self.podcast1 = Podcast(urls=['http://example.com/feed.rss'])
self.podcast2 = Podcast(urls=[self.P2_URL])
self.podcast1.save()
self.podcast2.save()
self.user = User(username='test-merge')
self.user.email = '[email protected]'
self.user.set_password('secret!')
self.user.save()
self.device = get_device(self.user, 'dev', '')
def test_merge_podcasts(self):
self.podcast2.subscribe(self.user, self.device)
# merge podcast2 into podcast1
pm = PodcastMerger([self.podcast1, self.podcast2], Counter(), [])
pm.merge()
# seems that setting delayed_commit = false in the CouchDB config, as
# well as a delay here fix the intermittent failures.
# TODO: further investiation needed
import time
time.sleep(2)
# get podcast for URL of podcast2 and unsubscribe from it
p = podcast_for_url(self.P2_URL)
p.unsubscribe(self.user, self.device)
subscriptions = subscribed_podcast_ids_by_user_id(self.user._id)
self.assertEqual(0, len(subscriptions))
def tearDown(self):
self.podcast1.delete()
self.user.delete()
示例2: test_merge
# 需要导入模块: from mygpo.core.models import Podcast [as 别名]
# 或者: from mygpo.core.models.Podcast import subscribe [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)