Exemplo n.º 1
0
    def test_configures_custom_log_file(self, path_exists_mock, logging_mock, filesystem_mock):
        path_exists_mock.return_value = True

        log_file_path = "bar.log"
        with Application(APPLICATION_NAME, log_file_path=log_file_path):
            pass

        file_path = os.path.join(get_log_directory(), log_file_path)
        self.__assert_logging_setup_with_file(file_path, filesystem_mock, logging_mock)
Exemplo n.º 2
0
    def test_configures_default_log_file(self, path_exists_mock, logging_mock, filesystem_mock):
        path_exists_mock.return_value = True

        with Application(APPLICATION_NAME):
            pass

        file_path = os.path.join(get_log_directory(), APPLICATION_NAME + ".log")
        self.__assert_logging_setup_with_file(file_path, filesystem_mock, logging_mock)

        path_exists_mock.assert_called_once_with(constants.LOGGING_CONFIG_FILE_NAME)
Exemplo n.º 3
0
    def __init__(self, name, version=None, log_file_path=None):
        self.name = str(name)
        self.__log_file_path = log_file_path or (self.name + '.log')
        if not os.path.isabs(self.__log_file_path):
            self.__log_file_path = os.path.join(
                get_log_directory(),
                self.__log_file_path
            )

        self.version = version or __version__
    def test_log_file_is_created(self):
        with Application(APPLICATION_NAME):
            pass

        log_file_path = os.path.join(get_log_directory(),
                                     APPLICATION_NAME + '.log')
        self.assertTrue(os.path.exists(log_file_path),
                        'Expected log file does not exist')
        self.assertTrue(
            os.path.getsize(log_file_path) > 0, 'Log file is empty')
    def test_configures_custom_log_file(self, path_exists_mock, logging_mock,
                                        filesystem_mock):
        path_exists_mock.return_value = True

        log_file_path = 'bar.log'
        with Application(APPLICATION_NAME, log_file_path=log_file_path):
            pass

        file_path = os.path.join(get_log_directory(), log_file_path)
        self.__assert_logging_setup_with_file(file_path, filesystem_mock,
                                              logging_mock)
    def test_configures_default_log_file(self, path_exists_mock, logging_mock,
                                         filesystem_mock):
        path_exists_mock.return_value = True

        with Application(APPLICATION_NAME):
            pass

        file_path = os.path.join(get_log_directory(),
                                 APPLICATION_NAME + '.log')
        self.__assert_logging_setup_with_file(file_path, filesystem_mock,
                                              logging_mock)

        path_exists_mock.assert_called_once_with(
            constants.LOGGING_CONFIG_FILE_NAME)
Exemplo n.º 7
0
    def test_collect_logs(self, mkdirs_mock, copy_mock, tarfile_open_mock,
                          get_files_mock, server_log_mock, launcher_log_mock):
        downloaded_logs_loc = path.join(TMP_PRESTO_DEBUG, "logs")

        collect.logs()

        mkdirs_mock.assert_called_with(downloaded_logs_loc)
        copy_mock.assert_called_with(
            path.join(get_log_directory(), PRESTOADMIN_LOG_NAME),
            downloaded_logs_loc)

        tarfile_open_mock.assert_called_with(OUTPUT_FILENAME_FOR_LOGS, 'w:gz')
        tar = tarfile_open_mock.return_value
        tar.add.assert_called_with(downloaded_logs_loc,
                                   arcname=path.basename(downloaded_logs_loc))
Exemplo n.º 8
0
    def test_log_file_is_created(self):
        with Application(APPLICATION_NAME):
            pass

        log_file_path = os.path.join(
            get_log_directory(),
            APPLICATION_NAME + '.log'
        )
        self.assertTrue(
            os.path.exists(log_file_path),
            'Expected log file does not exist'
        )
        self.assertTrue(
            os.path.getsize(log_file_path) > 0,
            'Log file is empty'
        )
Exemplo n.º 9
0
    def test_collect_logs(self, mkdirs_mock, copy_mock,
                          tarfile_open_mock, get_files_mock, server_log_mock,
                          launcher_log_mock):
        downloaded_logs_loc = path.join(TMP_PRESTO_DEBUG, "logs")

        collect.logs()

        mkdirs_mock.assert_called_with(downloaded_logs_loc)
        copy_mock.assert_called_with(path.join(get_log_directory(),
                                               PRESTOADMIN_LOG_NAME),
                                     downloaded_logs_loc)

        tarfile_open_mock.assert_called_with(OUTPUT_FILENAME_FOR_LOGS, 'w:bz2')
        tar = tarfile_open_mock.return_value
        tar.add.assert_called_with(downloaded_logs_loc,
                                   arcname=path.basename(downloaded_logs_loc))
Exemplo n.º 10
0
    def setUp(self):
        # put log files in a temporary dir
        self.__old_prestoadmin_log = get_log_directory()
        self.__temporary_dir_path = tempfile.mkdtemp(prefix='app-int-test-')
        os.environ[LOG_DIR_ENV_VARIABLE] = self.__temporary_dir_path

        # monkey patch in a fake logging config file
        self.__old_log_dirs = list(constants.LOGGING_CONFIG_FILE_DIRECTORIES)
        constants.LOGGING_CONFIG_FILE_DIRECTORIES.append(
            os.path.join(os.path.dirname(__file__), 'data'))

        # basicConfig is a noop if there are already handlers
        # present on the root logger, remove them all here
        self.__old_log_handlers = []
        for handler in logging.root.handlers:
            self.__old_log_handlers.append(handler)
            logging.root.removeHandler(handler)
Exemplo n.º 11
0
    def setUp(self):
        # put log files in a temporary dir
        self.__old_prestoadmin_log = get_log_directory()
        self.__temporary_dir_path = tempfile.mkdtemp(prefix='app-int-test-')
        os.environ[LOG_DIR_ENV_VARIABLE] = self.__temporary_dir_path

        # monkey patch in a fake logging config file
        self.__old_log_dirs = list(constants.LOGGING_CONFIG_FILE_DIRECTORIES)
        constants.LOGGING_CONFIG_FILE_DIRECTORIES.append(
            os.path.join(os.path.dirname(__file__), 'data')
        )

        # basicConfig is a noop if there are already handlers
        # present on the root logger, remove them all here
        self.__old_log_handlers = []
        for handler in logging.root.handlers:
            self.__old_log_handlers.append(handler)
            logging.root.removeHandler(handler)
Exemplo n.º 12
0
def copy_admin_log(log_folder):
    shutil.copy(os.path.join(get_log_directory(), PRESTOADMIN_LOG_NAME), log_folder)
 def test_get_configured_log_dir(self, get_mock):
     non_default_directory = '/not/the/default'
     get_mock.return_value = non_default_directory
     self.assertEqual(local_config_util.get_log_directory(),
                      non_default_directory)
 def test_get_default_log_dir(self, get_mock):
     get_mock.return_value = None
     self.assertEqual(local_config_util.get_log_directory(),
                      os.path.join(DEFAULT_LOCAL_CONF_DIR, 'log'))
Exemplo n.º 15
0
 def test_get_default_log_dir(self, get_mock):
     get_mock.return_value = None
     self.assertEqual(local_config_util.get_log_directory(), DEFAULT_PRESTOADMIN_LOG_DIR)
Exemplo n.º 16
0
 def test_get_default_log_dir(self, get_mock):
     get_mock.return_value = None
     self.assertEqual(local_config_util.get_log_directory(), os.path.join(DEFAULT_LOCAL_CONF_DIR, 'log'))
Exemplo n.º 17
0
def copy_admin_log(log_folder):
    shutil.copy(os.path.join(get_log_directory(), PRESTOADMIN_LOG_NAME), log_folder)
Exemplo n.º 18
0
 def test_get_configured_log_dir(self, get_mock):
     non_default_directory = '/not/the/default'
     get_mock.return_value = non_default_directory
     self.assertEqual(local_config_util.get_log_directory(), non_default_directory)