Esempio n. 1
0
 def test_user_file_broken(self, mocked__logging, mocked___LOGGER,
                           mocked__try_reading,
                           _loaded_configuration_paths):
     # etc file ok, user file broken
     mocked__fileConfig = mocked__logging.config.fileConfig
     mocked__fileConfig.side_effect = [None, ValueError]
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.etc_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertEqual(mocked__fileConfig.call_args_list, [
         call(self.etc_path, disable_existing_loggers=False),
         call(self.user_path, disable_existing_loggers=False)
     ])
     # and when repeated...
     mocked__try_reading.reset_mock()
     mocked__fileConfig.reset_mock()
     mocked__fileConfig.side_effect = ValueError
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.etc_path})
     self.assertEqual(mocked__try_reading.call_args_list,
                      [call(self.user_path)])
     self.assertEqual(
         mocked__fileConfig.call_args_list,
         [call(self.user_path, disable_existing_loggers=False)])
Esempio n. 2
0
 def test_etc_file_broken(self, mocked__logging, mocked___LOGGER,
                          mocked__try_reading, _loaded_configuration_paths):
     # etc file broken, user file ok
     mocked__fileConfig = mocked__logging.config.fileConfig
     mocked__fileConfig.side_effect = [ValueError, None]
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertFalse(_loaded_configuration_paths)
     self.assertEqual(mocked__try_reading.call_args_list,
                      [call(self.etc_path)])
     self.assertEqual(mocked__fileConfig.call_args_list,
                      [call(self.etc_path, disable_existing_loggers=False)])
     self.assertIs(mocked__logging.config.eval,
                   _security_logging_config_monkeypatched_eval)
     # and when repeated...
     mocked__try_reading.reset_mock()
     mocked__fileConfig.reset_mock()
     mocked__fileConfig.side_effect = ValueError
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertFalse(_loaded_configuration_paths)
     self.assertEqual(mocked__try_reading.call_args_list,
                      [call(self.etc_path)])
     self.assertEqual(mocked__fileConfig.call_args_list,
                      [call(self.etc_path, disable_existing_loggers=False)])
Esempio n. 3
0
 def test_first_without_suffixes_then_with(self, mocked__logging,
                                           mocked___LOGGER,
                                           mocked__try_reading,
                                           _loaded_configuration_paths):
     mocked__fileConfig = mocked__logging.config.fileConfig
     # first without suffixes...
     configure_logging()
     self.assertEqual(_loaded_configuration_paths,
                      {self.etc_path, self.user_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertEqual(mocked__fileConfig.call_args_list, [
         call(self.etc_path, disable_existing_loggers=False),
         call(self.user_path, disable_existing_loggers=False)
     ])
     # and then repeated with suffixes...
     mocked__fileConfig.reset_mock()
     mocked__try_reading.reset_mock()
     configure_logging('mysuffix')
     self.assertEqual(
         _loaded_configuration_paths, {
             self.etc_path, self.user_path, self.etc_path_suffixed,
             self.user_path_suffixed
         })
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path_suffixed),
          call(self.user_path_suffixed)])
     self.assertEqual(mocked__fileConfig.call_args_list, [
         call(self.etc_path_suffixed, disable_existing_loggers=False),
         call(self.user_path_suffixed, disable_existing_loggers=False)
     ])
Esempio n. 4
0
 def test_user_file_only(self, mocked__logging, mocked___LOGGER,
                         mocked__try_reading, _loaded_configuration_paths):
     # error for etc path, ok for user path
     mocked__try_reading.side_effect = [OSError, None]
     mocked__fileConfig = mocked__logging.config.fileConfig
     configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.user_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertEqual(
         mocked__fileConfig.call_args_list,
         [call(self.user_path, disable_existing_loggers=False)])
     self.assertIs(mocked__logging.config.eval,
                   _security_logging_config_monkeypatched_eval)
     # and when repeated...
     mocked__fileConfig.reset_mock()
     mocked__try_reading.reset_mock()
     mocked__try_reading.side_effect = OSError
     configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.user_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         # only etc path tried again:
         [call(self.etc_path)])
     self.assertFalse(mocked__fileConfig.called)
Esempio n. 5
0
 def test_no_file(self, mocked__logging, mocked___LOGGER,
                  mocked__try_reading, _loaded_configuration_paths):
     mocked__try_reading.side_effect = OSError
     mocked__fileConfig = mocked__logging.config.fileConfig
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertFalse(_loaded_configuration_paths)
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertFalse(mocked__fileConfig.called),
     # and when repeated...
     mocked__try_reading.reset_mock()
     with self.assertRaises(RuntimeError):
         configure_logging()
     self.assertFalse(_loaded_configuration_paths)
     self.assertEqual(
         mocked__try_reading.call_args_list,
         # both paths tried again:
         [call(self.etc_path), call(self.user_path)])
     self.assertFalse(mocked__fileConfig.called)
Esempio n. 6
0
 def test_both_files_exist(self, mocked__logging, mocked___LOGGER,
                           mocked__try_reading,
                           _loaded_configuration_paths):
     mocked__fileConfig = mocked__logging.config.fileConfig
     configure_logging()
     self.assertEqual(_loaded_configuration_paths,
                      {self.etc_path, self.user_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertEqual(mocked__fileConfig.call_args_list, [
         call(self.etc_path, disable_existing_loggers=False),
         call(self.user_path, disable_existing_loggers=False)
     ])
     # and when repeated...
     mocked__fileConfig.reset_mock()
     mocked__try_reading.reset_mock()
     configure_logging()
     self.assertEqual(_loaded_configuration_paths,
                      {self.etc_path, self.user_path})
     self.assertFalse(mocked__try_reading.called)
     self.assertFalse(mocked__fileConfig.called)
Esempio n. 7
0
 def test_etc_file_only(self, mocked__logging, mocked___LOGGER,
                        mocked__try_reading, _loaded_configuration_paths):
     # ok for etc path, error for user path
     mocked__try_reading.side_effect = [None, OSError]
     mocked__fileConfig = mocked__logging.config.fileConfig
     configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.etc_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path), call(self.user_path)])
     self.assertEqual(mocked__fileConfig.call_args_list,
                      [call(self.etc_path, disable_existing_loggers=False)])
     # and when repeated...
     mocked__fileConfig.reset_mock()
     mocked__try_reading.reset_mock()
     mocked__try_reading.side_effect = OSError
     configure_logging()
     self.assertEqual(_loaded_configuration_paths, {self.etc_path})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         # only user path tried again for:
         [call(self.user_path)])
     self.assertFalse(mocked__fileConfig.called)
Esempio n. 8
0
 def test_with_suffixes(self, mocked__logging, mocked___LOGGER,
                        mocked__try_reading, _loaded_configuration_paths):
     mocked__fileConfig = mocked__logging.config.fileConfig
     configure_logging('mysuffix')
     self.assertEqual(_loaded_configuration_paths,
                      {self.etc_path_suffixed, self.user_path_suffixed})
     self.assertEqual(
         mocked__try_reading.call_args_list,
         [call(self.etc_path_suffixed),
          call(self.user_path_suffixed)])
     self.assertEqual(mocked__fileConfig.call_args_list, [
         call(self.etc_path_suffixed, disable_existing_loggers=False),
         call(self.user_path_suffixed, disable_existing_loggers=False)
     ])
     self.assertIs(mocked__logging.config.eval,
                   _security_logging_config_monkeypatched_eval)
     # and when repeated...
     mocked__fileConfig.reset_mock()
     mocked__try_reading.reset_mock()
     configure_logging('mysuffix')
     self.assertEqual(_loaded_configuration_paths,
                      {self.etc_path_suffixed, self.user_path_suffixed})
     self.assertFalse(mocked__try_reading.called)
     self.assertFalse(mocked__fileConfig.called)