def test_youtube_do_not_download_non_videos(self): broadcast = utils.random_string() google_key = utils.random_string() manager = YoutubeManager(logging, None, google_key) url = urls.youtube_channel_get(broadcast, google_key) httpretty.register_uri(httpretty.GET, url, body=json.dumps(youtube_one_item_not_video.DATA), content_type='application/json') with mock.patch('youtube_dl.YoutubeDL', side_effect=test_utils.youtube_mock): episodes = manager.broadcast_update(broadcast) self.assert_length(episodes, 0)
def test_audio_tags_delete_args_not_there(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : utils.random_string(), 'artist' : utils.random_string(), 'album_artist' : utils.random_string(), } metadata.tags_update(temp, **args) metadata.tags_delete(temp, 'foo') new_tags = metadata.tags_show(temp) self.assertEqual(args, new_tags)
def test_delete_file_not_exists(self): with test_utils.temp_client(logging_level=logging.WARNING) as client_args: client = client_args.pop("podcast_client") random_name = utils.random_string(prefix="/tmp/") self.assertFalse(os.path.isfile(random_name)) client._remove_file(random_name) # pylint:disable=protected-access self.assertFalse(os.path.isfile(random_name))
def test_rss_feed_non_200(self): url = 'http://example1.%s.com' % utils.random_string() manager = RSSManager(logging, None, None) httpretty.register_uri(httpretty.GET, url, body=history_on_fire.DATA, status=400) with self.assertRaises(HathorException) as error: manager.broadcast_update(url) self.check_error_message('Getting invalid status code:400 for rss feed', error)
def test_rss_feed(self): url = 'http://example.%s.com' % utils.random_string() manager = RSSManager(logging, None, None) httpretty.register_uri(httpretty.GET, url, body=history_on_fire.DATA) episodes = manager.broadcast_update(url) self.assert_length(episodes, 12) for ep in episodes: self.assert_dictionary(ep)
def test_podcast_dir_given(self): with test_utils.temp_dir(delete=False) as dir_temp: with test_utils.temp_client(podcast_directory=dir_temp) as client_args: client = client_args.pop("podcast_client") pod_id = client.podcast_create("rss", "1234", utils.random_string()) podcast = client.podcast_show(pod_id) self.assertTrue(podcast[0]["file_location"].startswith(dir_temp)) os.rmdir(podcast[0]["file_location"]) client.podcast_delete(pod_id)
def test_audio_tags_reset_mp4(self): with test_utils.temp_audio_file(open_data=False, suffix='.mp4') as temp: args = { 'title' : utils.random_string(), } metadata.tags_update(temp, **args) metadata.tags_delete(temp, 'foo', 'bar') new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, args)
def test_audio_tags_none_isnt_set(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : None, } metadata.tags_update(temp, **args) new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, {'title' : args['title']})
def temp_podcast(pod_client, broadcast_url=False, delete=True, **kwargs): archive_type = kwargs.pop('archive_type', 'rss') podcast_name = kwargs.pop('podcast_name', utils.random_string()) broadcast_id = kwargs.pop('broadcast_id', None) if broadcast_id is None: if broadcast_url: broadcast_id = 'http://example.%s.com' % utils.random_string() else: broadcast_id = utils.random_string() with temp_dir() as temp: result = pod_client.podcast_create(archive_type, broadcast_id, podcast_name, file_location=temp, **kwargs) try: yield pod_client.podcast_show(result)[0] finally: if delete: pod_client.podcast_delete(result)
def temp_client(database_file=None, soundcloud_client_id=True, google_api_key=True, logging_level=logging.DEBUG, log_file=None, podcast_directory=None): soundcloud = None google = None if soundcloud_client_id: soundcloud = utils.random_string() if google: google = utils.random_string() pod_client = client.HathorClient(podcast_directory=podcast_directory, logging_file=log_file, logging_file_level=logging_level, database_file=database_file, soundcloud_client_id=soundcloud, google_api_key=google, console_logging=False) try: yield { 'podcast_client' : pod_client, 'soundcloud_client_id' : soundcloud_client_id, 'google_api_key' : google_api_key, } finally: pass
def temp_dir(name=None, delete=True): if name is None: name = utils.random_string(prefix='/tmp/') name = os.path.abspath(name) try: os.makedirs(name) yield name finally: if delete: try: os.rmdir(name) except OSError as exc: if exc.errno == os.errno.ENOENT: pass else: raise
def test_audio_tags(self): with test_utils.temp_audio_file(open_data=False) as temp: args = { 'title' : utils.random_string(), 'album' : utils.random_string(), 'performer' : utils.random_string(), 'track_number' : '1/2', 'disc_number' : '1/1', 'genre' : utils.random_string(), 'date' : '2015', 'copyright' : utils.random_string(), 'album_artist' : utils.random_string(), } metadata.tags_update(temp, **args) new_tags = metadata.tags_show(temp) self.assertEqual(args, new_tags) for key in args: metadata.tags_delete(temp, key) new_tags = metadata.tags_show(temp) self.assertEqual(new_tags, {})