Exemple #1
0
    def test_check_user_input(self):
        # make sure only takes in single int or list of ints
        with test_utils.temp_client() as client_args:
            client = client_args.pop("podcast_client")
            inc, exc = client._check_includers(2, 3)  # pylint:disable=protected-access
            self.assertEqual(inc, [2])
            self.assertEqual(exc, [3])

            inc, exc = client._check_includers([2, 5], [3, 6])  # pylint:disable=protected-access
            self.assertEqual(inc, [2, 5])
            self.assertEqual(exc, [3, 6])

            inc, exc = client._check_includers([2, 5], 6)  # pylint:disable=protected-access
            self.assertEqual(inc, [2, 5])
            self.assertEqual(exc, [6])

            # make sure breaks with invalid args
            with self.assertRaises(HathorException) as error:
                client._check_includers("foo", 2)  # pylint:disable=protected-access
            self.check_error_message("Input must be int type, foo given", error)

            with self.assertRaises(HathorException) as error:
                client._check_includers(3, True)  # pylint:disable=protected-access
            self.check_error_message("Input must be int type, True given", error)

            with self.assertRaises(HathorException) as error:
                client._check_includers(3, [True])  # pylint:disable=protected-access
            self.check_error_message("Input must be int type, True given", error)

            with self.assertRaises(HathorException) as error:
                client._check_includers(["foo", 2, 3], 3)  # pylint:disable=protected-access
            self.check_error_message("Input must be int type, foo given", error)
Exemple #2
0
 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))
Exemple #3
0
 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)
Exemple #4
0
    def test_no_api_tokens_warning(self):
        commands = []

        def mock_logging(*_, **__):
            return MockLogging(commands)

        with mock.patch("hathor.client.setup_logger", side_effect=mock_logging):
            with test_utils.temp_client(soundcloud_client_id=False, google_api_key=False):
                pass
        self.assertTrue("No soundcloud client id given, will not be able to access soundcloud api" in commands)
        self.assertTrue("No google api key given, will not be to able to access google api" in commands)
Exemple #5
0
 def run(self, result=None):
     with utils.temp_client() as client_args:
         self.client = client_args.pop('podcast_client') #pylint:disable=attribute-defined-outside-init
         super(TestPodcast, self).run(result)
Exemple #6
0
 def test_delete_file(self):
     with test_utils.temp_client(logging_level=logging.WARNING) as client_args:
         client = client_args.pop("podcast_client")
         with utils.temp_file() as temp_file:
             client._remove_file(temp_file)  # pylint:disable=protected-access
             self.assertFalse(os.path.isfile(temp_file))
Exemple #7
0
 def test_logger_file(self):
     with utils.temp_file() as log_file:
         with test_utils.temp_client(log_file=log_file):
             with open(log_file, "r") as file_read:
                 data = file_read.read()
                 self.assertTrue(len(data) > 0)
Exemple #8
0
 def test_database_file(self):
     with utils.temp_file() as temp_file:
         with test_utils.temp_client(database_file=temp_file) as client_args:
             client = client_args.pop("podcast_client")
             self.assert_not_none(client.podcast_list())
Exemple #9
0
 def test_logger_level(self):
     with test_utils.temp_client(logging_level=logging.WARNING) as client_args:
         client = client_args.pop("podcast_client")
         level = client.logger.getEffectiveLevel()
         self.assertEqual(level, 30)