Exemplo n.º 1
0
    def test_apply_empty_override(self):
        a_config_model = rule_handler.RuleSetConfigModel()

        a_config_model.min_break = "1m"
        a_config_model.min_time_of_day = "12:34"
        a_config_model.max_time_of_day = "23:45"
        a_config_model.max_time_per_day = "1h"
        a_config_model.free_play = True

        a_config_override_model = rule_handler.RuleSetConfigModel()

        new_rule_set = rule_handler.apply_override(
            p_rule_set=a_config_model, p_rule_override=a_config_override_model)

        self.assertEqual(new_rule_set.min_time_of_day_class, "")
        self.assertEqual(new_rule_set.max_time_of_day_class, "")
        self.assertEqual(new_rule_set.max_time_per_day_class, "")
        self.assertEqual(new_rule_set.min_break_class, "")
        self.assertEqual(new_rule_set.free_play_class, "")

        self.assertEqual(new_rule_set.min_time_of_day, "12:34")
        self.assertEqual(new_rule_set.max_time_of_day, "23:45")
        self.assertEqual(new_rule_set.max_time_per_day, "1h")
        self.assertEqual(new_rule_set.min_break, "1m")
        self.assertEqual(new_rule_set.free_play, True)
    def create_dummy_ruleset_configs(p_create_complex_configs=True):

        # TODO: Migrate test instances of ruleset configurations to database entries of ruleset
        configs = []

        # DEFAULT
        default_config = TestRuleHandler.create_dummy_ruleset_config()

        configs.append(default_config)

        if p_create_complex_configs:
            # VACATION
            vacation_config = rule_handler.RuleSetConfigModel()
            vacation_config.username = TEST_USER
            vacation_config.priority = 2
            vacation_config.context = german_vacation_context_rule_handler.CALENDAR_CONTEXT_RULE_HANDLER_NAME
            vacation_config.context_details = "Nordrhein-Westfalen"

            configs.append(vacation_config)

            # WEEKEND
            weekend_config = rule_handler.RuleSetConfigModel()
            weekend_config.username = TEST_USER
            weekend_config.priority = 3
            weekend_config.context = simple_context_rule_handlers.WEEKPLAN_CONTEXT_RULE_HANDLER_NAME
            weekend_config.context_details = simple_context_rule_handlers.WEEKPLAN_PREDEFINED_DETAILS["weekend"]

            configs.append(weekend_config)

        return {TEST_USER: configs}
Exemplo n.º 3
0
    def test_apply_override(self):
        a_config_model = rule_handler.RuleSetConfigModel()
        a_config_override_model = rule_handler.RuleSetConfigModel()

        a_config_override_model.min_time_of_day = "1"
        a_config_override_model.max_time_of_day = "2"
        a_config_override_model.max_time_per_day = "3"
        a_config_override_model.min_break = "4"
        a_config_override_model.free_play = "Y"

        new_rule_set = rule_handler.apply_override(
            p_rule_set=a_config_model, p_rule_override=a_config_override_model)

        self.assertEqual(new_rule_set.min_time_of_day_class,
                         rule_handler.CSS_CLASS_EMPHASIZE_RULE_OVERRIDE)
        self.assertEqual(new_rule_set.max_time_of_day_class,
                         rule_handler.CSS_CLASS_EMPHASIZE_RULE_OVERRIDE)
        self.assertEqual(new_rule_set.max_time_per_day_class,
                         rule_handler.CSS_CLASS_EMPHASIZE_RULE_OVERRIDE)
        self.assertEqual(new_rule_set.min_break_class,
                         rule_handler.CSS_CLASS_EMPHASIZE_RULE_OVERRIDE)
        self.assertEqual(new_rule_set.free_play_class,
                         rule_handler.CSS_CLASS_EMPHASIZE_RULE_OVERRIDE)

        self.assertEqual(new_rule_set.min_time_of_day, "1")
        self.assertEqual(new_rule_set.max_time_of_day, "2")
        self.assertEqual(new_rule_set.max_time_per_day, "3")
        self.assertEqual(new_rule_set.min_break, "4")
        self.assertEqual(new_rule_set.free_play, True)
Exemplo n.º 4
0
    def test_post_process(self):
        a_config_model = rule_handler.RuleSetConfigModel()
        a_config_model.min_time_of_day = "21:00:00"
        a_config_model.max_time_of_day = "21:00:00"

        with self.assertRaises(
                configuration.ConfigurationException) as context:
            a_config_model.post_process()

        self.assertIn("must be later", str(context.exception))

        a_config_model = rule_handler.RuleSetConfigModel()
        a_config_model.min_time_of_day = "21:00:00"
        a_config_model.max_time_of_day = "20:59:00"

        with self.assertRaises(
                configuration.ConfigurationException) as context:
            a_config_model.post_process()

        self.assertIn("must be later", str(context.exception))

        a_config_model = rule_handler.RuleSetConfigModel()
        a_config_model.min_time_of_day = "21:00:00"
        a_config_model.max_time_of_day = "21:01:00"

        a_config_model.post_process()
    def create_dummy_ruleset_config():

        default_config = rule_handler.RuleSetConfigModel()
        default_config.username = TEST_USER
        default_config.context = simple_context_rule_handlers.DEFAULT_CONTEXT_RULE_HANDLER_NAME

        return default_config
    def test_regex(self):
        a_config_model = rule_handler.RuleSetConfigModel()
        a_config_model.process_name_pattern = "*"

        with self.assertRaises(configuration.ConfigurationException) as context:
            _a_pattern = a_config_model.regex_process_name_pattern

        self.assertIn("Invalid process REGEX", str(context.exception))
    def test_label(self):
        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)

        self.assertEqual(a_config_model.label, rule_handler.DEFAULT_RULESET_LABEL)

        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)
        a_config_model.context = LABEL_1
        self.assertEqual(a_config_model.label, LABEL_1)

        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)
        a_config_model.context_label = LABEL_1
        self.assertEqual(a_config_model.label, LABEL_1)

        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)
        a_config_model.context_details = LABEL_1
        self.assertEqual(a_config_model.label, LABEL_1)

        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)
        a_config_model.context_label = LABEL_1
        a_config_model.context_details = LABEL_2
        self.assertEqual(a_config_model.label, LABEL_1)

        a_config_model = rule_handler.RuleSetConfigModel()
        self.assertIsNotNone(a_config_model)
        a_config_model.context_details = LABEL_1
        a_config_model.context = LABEL_2
        self.assertEqual(a_config_model.label, LABEL_1)
    def create_dummy_ruleset_configs():
        # DEFAULT
        default_config = rule_handler.RuleSetConfigModel()
        default_config.username = TEST_USER
        default_config.context = simple_context_rule_handlers.DEFAULT_CONTEXT_RULE_HANDLER_NAME

        # VACATION
        vacation_config = rule_handler.RuleSetConfigModel()
        vacation_config.username = TEST_USER
        vacation_config.priority = 2
        vacation_config.context = german_vacation_context_rule_handler.CALENDAR_CONTEXT_RULE_HANDLER_NAME
        vacation_config.context_details = "Nordrhein-Westfalen"

        # WEEKEND
        weekend_config = rule_handler.RuleSetConfigModel()
        weekend_config.username = TEST_USER
        weekend_config.priority = 3
        weekend_config.context = simple_context_rule_handlers.WEEKDAY_CONTEXT_RULE_HANDLER_NAME
        weekend_config.context_details = simple_context_rule_handlers.WEEKDAY_PREDEFINED_DETAILS[
            "weekend"]

        return {TEST_USER: [default_config, weekend_config, vacation_config]}
 def test_init(self):
     a_config_model = rule_handler.RuleSetConfigModel()
     self.assertIsNotNone(a_config_model)
Exemplo n.º 10
0
 def test_str(self):
     config = rule_handler.RuleSetConfigModel()
     self._logger.info(str(config))
Exemplo n.º 11
0
                        p_login_uid_mapping_entry=LOGIN_UID_MAPPING_ENTRY)

PROCESS_REGEX_MAP_1 = {USER_1: re.compile(PROCESS_NAME_1)}

PINFO_1 = process_info.ProcessInfo(p_username=USER_1, p_processname=PROCESS_NAME_1,
                                   p_pid=PID_1, p_start_time=START_TIME_1)
PINFO_2 = process_info.ProcessInfo(p_username=USER_1, p_processname=PROCESS_NAME_1,
                                   p_pid=PID_1, p_start_time=START_TIME_1, p_end_time=END_TIME_1)

START_TIME_NOW = datetime.datetime.utcnow()
END_TIME_NOW = START_TIME_NOW + datetime.timedelta(minutes=5)

PINFO_3 = process_info.ProcessInfo(p_username=USER_1, p_processname=PROCESS_NAME_1,
                                   p_pid=PID_1, p_start_time=START_TIME_NOW, p_end_time=END_TIME_NOW)

RULESET_CONFIG_USER1_NO_RESTRICTIONS = rule_handler.RuleSetConfigModel()
RULESET_CONFIG_USER1_NO_RESTRICTIONS.username = USER_1
RULESET_CONFIG_USER1_NO_RESTRICTIONS.process_name_pattern = PROCESS_NAME_1

RULESET_CONFIGS_USER1_NO_RESTRICTIONS = [RULESET_CONFIG_USER1_NO_RESTRICTIONS]

RULESET_CONFIG_USER1_ALL_RESTRICTIONS = rule_handler.RuleSetConfigModel()
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.username = USER_1
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.process_name_pattern = PROCESS_NAME_1
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.min_time_of_day = "00:00"
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.max_time_of_day = "00:01"
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.max_activity_duration = "0s"
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.min_break = "5m"
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.max_time_per_day = "0s"
RULESET_CONFIG_USER1_ALL_RESTRICTIONS.post_process()