def setUp(self):
     self._mox = Mox()
     self._main_logger = self._mox.CreateMock(Logger)
     self._storage_logger = self._mox.CreateMock(Logger)
     source_filename = os.path.abspath("tests/functional_tests/test.conf")
     self._db_manager.__enter__()
     filters = [CommentFilter("#"), SpacesFilter()]
     standard_key_transformer = StandardKeyTransformer()
     ip_key_transformer = lambda key, value, state: "{category:s}.ip".format(category=state.state_id)
     handlers = [
         StandardConfigSectionHandler(),
         SimpleKeyValueHandler.create_with_known_key_predicate(
             "=", lambda key, state: state.state_id == "services", standard_key_transformer
         ),
         TransformKeyListHandler.create_with_known_key_predicate(
             "=", lambda key, state: state.state_id == "users", standard_key_transformer, transform_user_fun
         ),
         AggregateKeyValueHandler.create_with_known_key_list(
             "=", ["ip0", "ip1", "ip2", "ip3", "ip4"], ip_key_transformer, lambda old_value, item: old_value + 1, 0
         ),
         SimpleKeyValueHandler.create_with_known_key_list(
             "=", ["use_local_mail", "use_remote_mail", "use_jabber"], standard_key_transformer
         ),
         SingleKeyHandler.create_with_known_key_list(
             "=", ["use_local_mail", "use_remote_mail", "use_jabber"], standard_key_transformer, "0"
         ),
     ]
     self._collect_task = FileSourceCollectTask(
         "some_source",
         filters,
         handlers,
         OrderedDict(),
         source_filename,
         "utf8",
         self._db_manager.db_filename,
         self._main_logger,
     )
Ejemplo n.º 2
0
 def __init__(self, source_filename, db_file_path, logger):
     filters = [CommentFilter("#"), SpacesFilter()]
     standard_key_transformer = StandardKeyTransformer()
     ip_key_transformer = lambda key, state: "%(category)s.ip" % {"category": state.state_id}
     handlers = [
         StandardConfigSectionHandler(),
         SimpleKeyValueHandler.create_with_known_key_predicate(
             "=", lambda key, state: state.state_id == "services", standard_key_transformer
         ),
         TransformKeyValueHandler.create_with_known_key_predicate(
             "=", lambda key, state: state.state_id == "users", standard_key_transformer, transform_user_fun
         ),
         AggregateKeyValueHandler.create_with_known_key_list(
             "=", ["ip0", "ip1", "ip2", "ip3", "ip4"], ip_key_transformer, lambda old_value, item: old_value + 1, 0
         ),
     ]
     init_state = OrderedDict()
     encoding = "utf-8"
     self._collect_task = FileSourceCollectTask(
         self._source, filters, handlers, init_state, source_filename, encoding, db_file_path, logger
     )
 def __init__(self, key_value_delimiter, known_key_predicate, key_transformer, value):
     self._key_value_handler = SimpleKeyValueHandler.create_with_known_key_predicate(key_value_delimiter, known_key_predicate, key_transformer)
     self._single_key_handler = SingleKeyHandler.create_with_known_key_predicate(key_value_delimiter, known_key_predicate, key_transformer, value)
 def __init__(self, methodName='runTest'):
     super(TestSimpleKeyValueHandler, self).__init__(methodName)
     key_transformer = lambda key, value, state: key
     self._handler = SimpleKeyValueHandler.create_with_known_key_list('=', ['key13', 'key666'], key_transformer)