def test_update_from_other_podcast(self): updated_feed_dict = copy.deepcopy(self.feed_dict) updated_feed_dict['episodes'].append({'listened': False, 'media_path': None, 'media_url': 'http://localhost/ep4.mp3', 'published': 'Fri, 27 Jun 2008 07:00:00 GMT', 'title': 'Tail'}) podcast = Podcast.from_dict(self.feed_dict) other = Podcast.from_dict(updated_feed_dict) new_episode_count = podcast.update_from_podcast(other) self.assertEqual(len(podcast.episodes), 4) self.assertEqual(new_episode_count, 1) other.url = 'http://otherhost/feed.xml' with self.assertRaises(Exception): podcast.update_from_podcast(other)
def test_save_and_restore(self): horse_podcast = Podcast.from_dict(self.feed_dict) with tempfile.NamedTemporaryFile(suffix='.json') as f: tmp = f.name horse_podcast.save_to_file(tmp) restored_podcast = Podcast.from_file(tmp) os.unlink(tmp) self.assertEqual(horse_podcast.url, restored_podcast.url) self.assertEqual(len(horse_podcast.episodes), len(restored_podcast.episodes))
def import_podcasts(self, args): log.debug('import_podcasts(filter=%s, input_path=%s)' % (args.filter, args.path)) with get_fh_or(sys.stdin, args.path, 'r') as f: data = json.load(f) for podcast_dict in data: try: p = Podcast.from_dict(podcast_dict) log.debug('import_podcasts: examining: %s' % p.title) path = self.get_podcast_path(p) if os.path.exists(path): raise(Exception('already exists: %s for %s' % (path, p.title))) p.path = path if p.matches_filter(args.filter): log.debug('import_podcasts: Podcast matches filter, saving... %s' % p.title) p.save() except Exception as e: log.warning('import_podcasts: exception while importing podcast: %s' % e)
def test_feed_from_dict(self): horse_podcast = Podcast.from_dict(self.feed_dict) self.assertEqual(len(horse_podcast.episodes), 3) self.assertEqual(horse_podcast.title, 'My Lovely Horse')