def calc_similar_podcasts(podcast, num=20): """ calculates and returns a list of podcasts that seem to be similar to the given one. Probably an expensive operation """ users = subscribed_users(podcast) podcasts = Counter() for user_id in users: user_subscriptions = subscribed_podcast_ids_by_user_id(user_id) user_counter = Counter(user_subscriptions) podcasts.update(user_counter) return podcasts.most_common(num)
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))