def test_read_config_file(self):
        a_configuration = configuration.Configuration()

        rule_handler_section = rule_handler.RuleHandlerConfigModel()
        a_configuration.add_section(rule_handler_section)

        a_rule_set_section_handler = rule_handler.RuleSetSectionHandler()
        a_configuration.register_section_handler(p_section_handler=a_rule_set_section_handler)

        filename = os.path.join(os.path.dirname(__file__), "resources/ruleset_handler.test.config")
        a_configuration.read_config_file(p_filename=filename)

        ruleset_configs = a_rule_set_section_handler.rule_set_configs

        self.assertIsNotNone(ruleset_configs)

        self.assertEqual(len(ruleset_configs), 2)

        self.assertIn("user1", ruleset_configs)
        self.assertIn("user2", ruleset_configs)

        ruleset_user1 = ruleset_configs["user1"]
        self.assertEqual(len(ruleset_user1), 1)
        ruleset_user2 = ruleset_configs["user2"]
        self.assertEqual(len(ruleset_user2), 4)

        self.assertIsNotNone(a_configuration)
    def create_dummy_rule_handler(p_persistence, p_create_complex_handlers=True):
        default_context_rule_handler = simple_context_rule_handlers.DefaultContextRuleHandler()
        rulehandler_config = rule_handler.RuleHandlerConfigModel()

        a_rule_handler = rule_handler.RuleHandler(p_config=rulehandler_config, p_persistence=p_persistence)
        a_rule_handler.register_context_rule_handler(p_context_rule_handler=default_context_rule_handler,
                                                     p_default=True)
        if p_create_complex_handlers:
            weekend_context_rule_handler = simple_context_rule_handlers.WeekplanContextRuleHandler()
            vacation_context_rule_handler = german_vacation_context_rule_handler.GermanVacationContextRuleHandler()
            a_rule_handler.register_context_rule_handler(p_context_rule_handler=weekend_context_rule_handler)
            a_rule_handler.register_context_rule_handler(p_context_rule_handler=vacation_context_rule_handler)

        return a_rule_handler
Example #3
0
    def load_configuration(self, p_configuration):

        app_control_section = app_control.AppControlConfigModel()
        p_configuration.add_section(app_control_section)

        audio_handler_section = audio_handler.AudioHandlerConfigModel()
        p_configuration.add_section(audio_handler_section)

        popup_handler_section = popup_handler.PopupHandlerConfigModel()
        p_configuration.add_section(popup_handler_section)

        persistence_section = persistence.PersistenceConfigModel()
        p_configuration.add_section(persistence_section)

        rule_handler_section = rule_handler.RuleHandlerConfigModel()
        p_configuration.add_section(rule_handler_section)

        self._rule_set_section_handler = rule_handler.RuleSetSectionHandler()
        p_configuration.register_section_handler(
            p_section_handler=self._rule_set_section_handler)

        client_process_handler_section = client_process_handler.ClientProcessHandlerConfigModel(
        )
        p_configuration.add_section(client_process_handler_section)

        client_device_handler_section = client_device_handler.ClientDeviceHandlerConfigModel(
        )
        p_configuration.add_section(client_device_handler_section)

        self._client_device_section_handler = client_device_handler.ClientDeviceSectionHandler(
        )
        p_configuration.register_section_handler(
            p_section_handler=self._client_device_section_handler)

        status_server_section = status_server.StatusServerConfigModel()
        p_configuration.add_section(status_server_section)

        master_connector_section = master_connector.MasterConnectorConfigModel(
        )
        p_configuration.add_section(master_connector_section)

        self.app_config = AppConfigModel()
        p_configuration.add_section(self.app_config)

        return super(App,
                     self).load_configuration(p_configuration=p_configuration)
    def create_dummy_rule_handler(p_ruleset_configs):

        default_context_rule_handler = simple_context_rule_handlers.DefaultContextRuleHandler(
        )
        weekend_context_rule_handler = simple_context_rule_handlers.WeekdayContextRuleHandler(
        )
        vacation_context_rule_handler = german_vacation_context_rule_handler.GermanVacationContextRuleHandler(
        )
        rulehandler_config = rule_handler.RuleHandlerConfigModel()

        a_rule_handler = rule_handler.RuleHandler(
            p_config=rulehandler_config, p_rule_set_configs=p_ruleset_configs)
        a_rule_handler.register_context_rule_handler(
            p_context_rule_handler=default_context_rule_handler,
            p_default=True)
        a_rule_handler.register_context_rule_handler(
            p_context_rule_handler=weekend_context_rule_handler)
        a_rule_handler.register_context_rule_handler(
            p_context_rule_handler=vacation_context_rule_handler)

        return a_rule_handler
Example #5
0
    def prepare_configuration(self, p_configuration):

        app_control_section = app_control.AppControlConfigModel()
        p_configuration.add_section(app_control_section)

        audio_handler_section = audio_handler.AudioHandlerConfigModel()
        audio_handler_section.spool_dir = os.path.join("/var/spool",
                                                       constants.DIR_NAME)
        p_configuration.add_section(audio_handler_section)

        popup_handler_section = popup_handler.PopupHandlerConfigModel()
        p_configuration.add_section(popup_handler_section)

        persistence_section = persistence.PersistenceConfigModel()
        persistence_section.sqlite_dir = os.path.join("/var/spool",
                                                      constants.DIR_NAME)
        p_configuration.add_section(persistence_section)

        rule_handler_section = rule_handler.RuleHandlerConfigModel()
        p_configuration.add_section(rule_handler_section)

        self._rule_set_section_handler = rule_handler.RuleSetSectionHandler()
        p_configuration.register_section_handler(
            p_section_handler=self._rule_set_section_handler)

        client_process_handler_section = client_process_handler.ClientProcessHandlerConfigModel(
        )
        p_configuration.add_section(client_process_handler_section)

        client_device_handler_section = client_device_handler.ClientDeviceHandlerConfigModel(
        )
        p_configuration.add_section(client_device_handler_section)

        self._client_device_section_handler = client_device_handler.ClientDeviceSectionHandler(
        )
        p_configuration.register_section_handler(
            p_section_handler=self._client_device_section_handler)

        status_server_section = status_server.StatusServerConfigModel()
        p_configuration.add_section(status_server_section)

        master_connector_section = master_connector.MasterConnectorConfigModel(
        )
        p_configuration.add_section(master_connector_section)

        prometheus_client_section = prometheus.PrometheusClientConfigModel()
        p_configuration.add_section(prometheus_client_section)

        self.app_config = AppConfigModel()
        p_configuration.add_section(self.app_config)

        user_handler_section = unix_user_handler.BaseUserHandlerConfigModel()
        p_configuration.add_section(user_handler_section)

        self._login_mapping_section_handler = login_mapping.LoginMappingSectionHandler(
        )
        p_configuration.register_section_handler(
            p_section_handler=self._login_mapping_section_handler)

        return super(
            App, self).prepare_configuration(p_configuration=p_configuration)