def test_audio_picture_extract_data(self): # test picture update and extract and data is same with test_utils.temp_audio_file(open_data=False) as temp_audio: # test with jpg with test_utils.temp_image_file() as temp_pic: with open(temp_pic, 'rb') as reader: temp_pic_data = reader.read() metadata.picture_update(temp_audio, temp_pic) with utils.temp_file(suffix='.jpg') as new_temp_pic: metadata.picture_extract(temp_audio, new_temp_pic) with open(new_temp_pic, 'rb') as reader: new_temp_data = reader.read() self.assertEqual(new_temp_data, temp_pic_data) # test with png with test_utils.temp_image_file(suffix='.png') as temp_pic: with open(temp_pic, 'rb') as reader: temp_pic_data = reader.read() metadata.picture_update(temp_audio, temp_pic) with utils.temp_file(suffix='.png') as new_temp_pic: metadata.picture_extract(temp_audio, new_temp_pic) with open(new_temp_pic, 'rb') as reader: new_temp_data = reader.read() self.assertEqual(new_temp_data, temp_pic_data)
def test_audio_picture_update_invalid_type(self): # foo is a bad file to load from with utils.temp_file(suffix='.foo') as test_file: with test_utils.temp_audio_file(open_data=False) as temp_audio: with self.assertRaises(AudioFileException) as error: metadata.picture_update(temp_audio, test_file) self.check_error_message('Unsupported image type:%s' % test_file, error) # test the ones that work with test_utils.temp_image_file(suffix='.jpg') as test_file: with test_utils.temp_audio_file(open_data=False) as temp_audio: metadata.picture_update(temp_audio, test_file) with test_utils.temp_image_file(suffix='.png') as test_file: with test_utils.temp_audio_file(open_data=False) as temp_audio: metadata.picture_update(temp_audio, test_file)
def test_episode_download_remove_commercial_with_picture(self): # curl download used for rss and soundcloud pod_args = {"archive_type": "rss", "max_allowed": 1, "remove_commercials": True} with test_utils.temp_podcast(self.client, broadcast_url=True, **pod_args) as podcast: httpretty.register_uri(httpretty.GET, podcast["broadcast_id"], body=history_on_fire.DATA) self.client.episode_sync() episode_list = self.client.episode_list(only_files=False) with test_utils.temp_audio_file(open_data=False) as mp3_file: with test_utils.temp_image_file() as image_file: metadata.picture_update(mp3_file, image_file) with open(mp3_file, "r") as f: mp3_body = f.read() test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body) self.client.episode_download(episode_list[0]["id"]) episode = self.client.episode_show(episode_list[0]["id"])[0] self.assert_not_none(episode["file_path"]) # make sure episode list shows episode with only_files=True episode_list = self.client.episode_list() self.assert_length(episode_list, 1) self.assert_not_none(episode_list[0]["file_size"]) self.assertTrue(episode_list[0]["file_size"] > 0) # make sure image file is right with utils.temp_file(suffix=".jpg") as temper: metadata.picture_extract(episode_list[0]["file_path"], temper) with open(temper, "r") as f: with open(image_file, "r") as ff: self.assertEqual(f.read(), ff.read())
def test_audio_picture_extract_name_overriden(self): with test_utils.temp_audio_file(open_data=False) as temp_audio: # give it a bad ending, should be overriden with .jpg with test_utils.temp_image_file() as temp_pic: metadata.picture_update(temp_audio, temp_pic) with utils.temp_file(suffix='.foo') as new_temp_pic: output = metadata.picture_extract(temp_audio, new_temp_pic) actual_path = output['output_path'] self.assertNotEqual(actual_path, new_temp_pic) self.assertTrue(actual_path.endswith('.jpg')) # make sure file gets deleted os.remove('%s.jpg' % new_temp_pic) # give it a bad ending, should be overriden with .png with test_utils.temp_image_file(suffix='.png') as temp_pic: metadata.picture_update(temp_audio, temp_pic) with utils.temp_file(suffix='.foo') as new_temp_pic: output = metadata.picture_extract(temp_audio, new_temp_pic) actual_path = output['output_path'] self.assertNotEqual(actual_path, new_temp_pic) self.assertTrue(actual_path.endswith('.png')) # make sure file gets deleted os.remove('%s.png' % new_temp_pic)