Пример #1
0
    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())
Пример #2
0
    def test_podcast_file_sync(self):
        # download only one podcast episode
        with utils.temp_podcast(self.client, archive_type='soundcloud', max_allowed=1) as podcast:
            url = urls.soundcloud_track_list(podcast['broadcast_id'],
                                             self.client.soundcloud_client_id)
            httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_one_track.DATA))
            self.client.episode_sync()

            episode_list = self.client.episode_list(only_files=False)
            with utils.temp_audio_file() as mp3_body:
                utils.mock_mp3_download(episode_list[0]['download_url'], mp3_body)
                self.client.podcast_file_sync()
                episode_list = self.client.episode_list()
                self.assert_not_none(episode_list[0]['file_path'])
                first_episode_date = episode_list[0]['date']
                # add an additional, newer podcast, make sure things are deleted
                url = urls.soundcloud_track_list(podcast['broadcast_id'],
                                                 self.client.soundcloud_client_id)
                httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_two_tracks.DATA))
                self.client.episode_sync()
                episode_list = self.client.episode_list(only_files=False)
                with utils.temp_audio_file() as mp3_body:
                    utils.mock_mp3_download(episode_list[1]['download_url'], mp3_body)
                    self.client.podcast_file_sync()

                    # make sure 2 episodes in db, but only 1 with a file path
                    episode_list = self.client.episode_list()
                    self.assert_not_none(episode_list[0]['file_path'])
                    all_episodes = self.client.episode_list(only_files=False)
                    self.assertNotEqual(len(episode_list), len(all_episodes))
                    second_episode_date = episode_list[0]['date']

                    self.assertTrue(datetime.strptime(second_episode_date, self.client.datetime_output_format) >
                                    datetime.strptime(first_episode_date, self.client.datetime_output_format))
Пример #3
0
    def test_podcast_location_update(self):
        # check fails with invalid data
        with self.assertRaises(HathorException) as error:
            self.client.podcast_update_file_location(1, 'foo')
        self.check_error_message('Podcast not found for ID:1', error)

        # check works with valid data
        with utils.temp_podcast(self.client, archive_type='rss', broadcast_url=True, max_allowed=2) 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 utils.temp_audio_file() as mp3_body:
                utils.mock_mp3_download(episode_list[0]['download_url'], mp3_body)
                self.client.episode_download(episode_list[0]['id'])
                old_episode = self.client.episode_show(episode_list[0]['id'])[0]
                with utils.temp_dir(delete=False) as temp:
                    self.client.podcast_update_file_location(podcast['id'], temp)
                    # make sure episode path changed
                    new_episode = self.client.episode_show(episode_list[0]['id'])[0]
                    self.assertTrue(new_episode['file_path'].startswith(temp))
                    self.assertNotEqual(old_episode['file_path'], new_episode['file_path'])
                    # make sure podcast path changed
                    new_podcast = self.client.podcast_show(podcast['id'])[0]
                    self.assertNotEqual(podcast['file_location'], new_podcast['file_location'])
Пример #4
0
 def test_podcast_file_sync_no_automatic_episode_download(self):
     # make sure no max allowed downloads all possible podcasts
     with utils.temp_podcast(self.client, archive_type='soundcloud', max_allowed=None, automatic_download=False) as podcast:
         url = urls.soundcloud_track_list(podcast['broadcast_id'],
                                          self.client.soundcloud_client_id)
         httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_one_track_only_page.DATA))
         self.client.episode_sync()
         episode_list = self.client.episode_list(only_files=False)
         with utils.temp_audio_file() as mp3_body:
             utils.mock_mp3_download(episode_list[0]['download_url'], mp3_body)
             self.client.podcast_file_sync()
             episode_list = self.client.episode_list()
             self.assert_length(episode_list, 0)
Пример #5
0
    def test_episode_delete(self):
        with test_utils.temp_podcast(self.client, archive_type="rss", broadcast_url=True) 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() as mp3_body:
                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"])
                self.client.episode_delete(episode_list[0]["id"])

            # make sure actually deleted
            self.assert_length(self.client.episode_list(), 0)
Пример #6
0
 def test_episode_download_curl(self):
     # curl download used for rss and soundcloud
     with test_utils.temp_podcast(self.client, archive_type="rss", broadcast_url=True) 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() as mp3_body:
             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)
Пример #7
0
 def test_podcast_dont_delete_episode_files(self):
     with utils.temp_podcast(self.client, archive_type='soundcloud', max_allowed=1) as podcast:
         url = urls.soundcloud_track_list(podcast['broadcast_id'],
                                          self.client.soundcloud_client_id)
         httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_one_track.DATA))
         self.client.episode_sync()
         episode_list = self.client.episode_list(only_files=False)
         with utils.temp_audio_file() as mp3_body:
             utils.mock_mp3_download(episode_list[0]['download_url'], mp3_body)
             self.client.podcast_file_sync()
             episode_list = self.client.episode_list()
             # delete and make sure file is still there
             self.client.podcast_delete(podcast['id'], delete_files=False)
             self.assertTrue(len(os.listdir(podcast['file_location'])) > 0)
             os.remove(episode_list[0]['file_path'])
             os.rmdir(podcast['file_location'])
Пример #8
0
 def test_podcast_file_sync_exclude(self):
     # create two podcasts, exclude one, make sure only that pod was updated
     with utils.temp_podcast(self.client, archive_type='soundcloud', max_allowed=1) as podcast1:
         url = urls.soundcloud_track_list(podcast1['broadcast_id'],
                                          self.client.soundcloud_client_id)
         httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_one_track.DATA))
         self.client.episode_sync()
         episode_list = self.client.episode_list(only_files=False)
         with utils.temp_audio_file() as mp3_body:
             utils.mock_mp3_download(episode_list[0]['download_url'], mp3_body)
             with utils.temp_podcast(self.client) as podcast2:
                 self.client.podcast_file_sync(exclude_podcasts=[podcast2['id']], )
                 episode_list = self.client.episode_list()
                 self.assertTrue(len(episode_list) > 0)
                 for episode in episode_list:
                     self.assertEqual(podcast1['id'], episode['podcast_id'])
Пример #9
0
 def test_episode_delete_file(self):
     # check works with valid input
     with test_utils.temp_podcast(self.client, archive_type="rss", broadcast_url=True) 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() as mp3_body:
             test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body)
             self.client.episode_download(episode_list[0]["id"])
             # make sure file exists
             episode = self.client.episode_show(episode_list[0]["id"])[0]
             self.assert_not_none(episode["file_path"])
             # delete episode file, but not episode
             self.client.episode_delete_file(episode_list[0]["id"])
             episode = self.client.episode_show(episode_list[0]["id"])[0]
             self.assert_none(episode["file_path"])
             self.assert_none(episode["file_size"])
Пример #10
0
 def test_episode_download_remove_commercial(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() as mp3_body:
             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)
Пример #11
0
    def test_podcast_database_cleanup(self):
        # download only one podcast episode
        with test_utils.temp_podcast(self.client, archive_type="soundcloud", max_allowed=1) as podcast:
            url = urls.soundcloud_track_list(podcast["broadcast_id"], self.client.soundcloud_client_id)
            httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_two_tracks.DATA))

            self.client.episode_sync(max_episode_sync=0)
            episode_list = self.client.episode_list(only_files=False)
            with test_utils.temp_audio_file() as mp3_body:
                test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body)
                self.client.podcast_file_sync()
                episode_list = self.client.episode_list()
                self.assert_not_none(episode_list[0]["file_path"])
                all_episodes = self.client.episode_list(only_files=False)
                self.assertTrue(len(all_episodes) > 1)

                self.client.database_cleanup()
                all_episodes = self.client.episode_list(only_files=False)
                self.assert_length(all_episodes, 1)
Пример #12
0
    def test_episode_show(self):
        # check works with valid data
        with test_utils.temp_podcast(self.client, archive_type="rss", broadcast_url=True) 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)
            self.assert_not_length(episode_list, 0)

            with test_utils.temp_audio_file() as mp3_body:
                test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body)
                self.client.episode_download(episode_list[0]["id"])

            # works as single
            episode = self.client.episode_show(episode_list[0]["id"])[0]
            self.assert_dictionary(episode)
            # works as list
            episode = self.client.episode_show([episode_list[0]["id"]])[0]
            self.assert_dictionary(episode)
Пример #13
0
    def test_episode_prevent_deletion(self):
        # download only one podcast episode
        with test_utils.temp_podcast(self.client, archive_type="soundcloud", max_allowed=1) as podcast:
            url = urls.soundcloud_track_list(podcast["broadcast_id"], self.client.soundcloud_client_id)
            httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_one_track.DATA))
            self.client.episode_sync()
            episode_list = self.client.episode_list(only_files=False)
            with test_utils.temp_audio_file() as mp3_body:
                test_utils.mock_mp3_download(episode_list[0]["download_url"], mp3_body)
                self.client.podcast_file_sync()
                # mark episode to prevent deletion
                self.client.episode_update(episode_list[0]["id"], prevent_delete=True)

                # add an additional, newer podcast, make sure prevented deletion episode stays
                url = urls.soundcloud_track_list(podcast["broadcast_id"], self.client.soundcloud_client_id)
                httpretty.register_uri(httpretty.GET, url, body=json.dumps(soundcloud_three_tracks.DATA))
                self.client.episode_sync(max_episode_sync=0)
                episode_list = self.client.episode_list(only_files=False)

                test_utils.mock_mp3_download(episode_list[1]["download_url"], mp3_body)
                test_utils.mock_mp3_download(episode_list[2]["download_url"], mp3_body)
                self.client.podcast_file_sync()

                episode_list = self.client.episode_list()
                ep_ids = [i["id"] for i in episode_list]

                self.assertTrue(2 in ep_ids)
                self.assertTrue(1 in ep_ids)
                self.assertTrue(3 not in ep_ids)