def test_rules_in_config(self): config = DotDict() config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config['TestRuleTestLaughable.laughable'] = 'wilma' config['TestRuleTestDangerous.dangerous'] = 'dwight' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'TestRuleTestLaughable', TestRuleTestLaughable, 'TestRuleTestLaughable' ), ( 'TestRuleTestDangerous', TestRuleTestDangerous, 'TestRuleTestDangerous' ) ] trs = transform_rules.TransformRuleSystem(config) ok_(isinstance(trs.rules[0], TestRuleTestLaughable)) ok_(isinstance(trs.rules[1], TestRuleTestDangerous)) ok_(trs.rules[0].predicate(None)) ok_(trs.rules[1].action(None))
def test_rules_close(self): config = DotDict() config.logger = Mock().s config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config['TestRuleTestLaughable.laughable'] = 'wilma' config['TestRuleTestDangerous.dangerous'] = 'dwight' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'TestRuleTestLaughable', TestRuleTestLaughable, 'TestRuleTestLaughable' ), ( 'TestRuleTestDangerous', TestRuleTestDangerous, 'TestRuleTestDangerous' ) ] trs = transform_rules.TransformRuleSystem(config) trs.close() eq_(trs.rules[0].close_counter, 1) eq_(trs.rules[1].close_counter, 1)
def test_rules_close_bubble_close_errors(self): config = DotDict() config.logger = Mock() config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'TestRuleTestBrokenCloseMethod', TestRuleTestBrokenCloseMethod, 'TestRuleTestBrokenCloseMethod' ), ] trs = transform_rules.TransformRuleSystem(config) assert_raises( AttributeError, trs.close ) assert len(config.logger.debug.mock_calls) == 1 config.logger.debug.assert_any_call( 'trying to close %s', 'collector.unittest.lib.test_transform_rules.' 'TestRuleTestBrokenCloseMethod' )
def setup_config(self, prefix=None): config = DotDict() config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ('RuleTestLaughable', StatsdRuleBenchmarkWrapper, 'RuleTestLaughable'), ('RuleTestDangerous', StatsdRuleBenchmarkWrapper, 'RuleTestDangerous') ] config.RuleTestLaughable = DotDict() config.RuleTestLaughable.laughable = 'wilma' config.RuleTestLaughable.statsd_class = StatsClient config.RuleTestLaughable.statsd_host = 'some_statsd_host' config.RuleTestLaughable.statsd_port = 3333 config.RuleTestLaughable.statsd_prefix = prefix if prefix else '' config.RuleTestLaughable.wrapped_object_class = RuleTestLaughable config.RuleTestLaughable.active_list = 'act' config.RuleTestDangerous = DotDict() config.RuleTestDangerous.dangerous = 'dwight' config.RuleTestDangerous.statsd_class = StatsClient config.RuleTestDangerous.statsd_host = 'some_statsd_host' config.RuleTestDangerous.statsd_port = 3333 config.RuleTestDangerous.statsd_prefix = prefix if prefix else '' config.RuleTestDangerous.wrapped_object_class = RuleTestDangerous config.RuleTestDangerous.active_list = 'act' return config
def test_rules_close_if_close_method_available(self): config = DotDict() config.logger = Mock() config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ('RuleTestNoCloseMethod', RuleTestNoCloseMethod, 'RuleTestNoCloseMethod'), ('RuleTestDangerous', RuleTestDangerous, 'RuleTestDangerous') ] trs = transform_rules.TransformRuleSystem(config) trs.close() assert len(config.logger.debug.mock_calls) == 3 config.logger.debug.assert_any_call( 'trying to close %s', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestNoCloseMethod') config.logger.debug.assert_any_call( 'trying to close %s', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestDangerous') config.logger.debug.assert_any_call( '%s has no close', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestNoCloseMethod')
def test_rules_close(self): config = DotDict() config.logger = Mock().s config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config['RuleTestLaughable.laughable'] = 'wilma' config['RuleTestDangerous.dangerous'] = 'dwight' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'RuleTestLaughable', RuleTestLaughable, 'RuleTestLaughable' ), ( 'RuleTestDangerous', RuleTestDangerous, 'RuleTestDangerous' ) ] trs = transform_rules.TransformRuleSystem(config) trs.close() assert trs.rules[0].close_counter == 1 assert trs.rules[1].close_counter == 1
def test_rules_in_config(self): config = DotDict() config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config['RuleTestLaughable.laughable'] = 'wilma' config['RuleTestDangerous.dangerous'] = 'dwight' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'RuleTestLaughable', RuleTestLaughable, 'RuleTestLaughable' ), ( 'RuleTestDangerous', RuleTestDangerous, 'RuleTestDangerous' ) ] trs = transform_rules.TransformRuleSystem(config) assert isinstance(trs.rules[0], RuleTestLaughable) assert isinstance(trs.rules[1], RuleTestDangerous) assert trs.rules[0].predicate(None) assert trs.rules[1].action(None)
def test_rules_close_if_close_method_available(self): config = DotDict() config.logger = Mock() config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'RuleTestNoCloseMethod', RuleTestNoCloseMethod, 'RuleTestNoCloseMethod' ), ( 'RuleTestDangerous', RuleTestDangerous, 'RuleTestDangerous' ) ] trs = transform_rules.TransformRuleSystem(config) trs.close() assert len(config.logger.debug.mock_calls) == 3 config.logger.debug.assert_any_call( 'trying to close %s', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestNoCloseMethod' ) config.logger.debug.assert_any_call( 'trying to close %s', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestDangerous' )
def _add_argument_from_configman_option(self, qualified_name, option): opt_name = qualified_name kwargs = DotDict() if option.is_argument: # is positional argument option_name = opt_name else: option_name = '--%s' % opt_name kwargs.dest = opt_name if option.short_form: option_short_form = '-%s' % option.short_form args = (option_name, option_short_form) else: args = (option_name,) if option.from_string_converter in (bool, boolean_converter): kwargs.action = 'store_true' else: kwargs.action = 'store' kwargs.default = argparse.SUPPRESS kwargs.help = option.doc new_arguments = DotDict() new_arguments.args = args new_arguments.kwargs = kwargs new_arguments.qualified_name = qualified_name if ( isinstance(option.default, collections.Sequence) and not isinstance(option.default, (six.binary_type, six.text_type)) ): if option.is_argument: kwargs.nargs = len(option.default) else: kwargs.nargs = "+" if qualified_name.startswith('admin'): self.admin_arguments.append(new_arguments) else: self.arguments_for_building_argparse.append(new_arguments)
def _add_argument_from_configman_option(self, qualified_name, option): opt_name = qualified_name kwargs = DotDict() if option.is_argument: # is positional argument option_name = opt_name else: option_name = '--%s' % opt_name kwargs.dest = opt_name if option.short_form: option_short_form = '-%s' % option.short_form args = (option_name, option_short_form) else: args = (option_name, ) if option.from_string_converter in (bool, boolean_converter): kwargs.action = 'store_true' else: kwargs.action = 'store' kwargs.default = argparse.SUPPRESS kwargs.help = option.doc new_arguments = DotDict() new_arguments.args = args new_arguments.kwargs = kwargs new_arguments.qualified_name = qualified_name if (isinstance(option.default, collections.Sequence) and not isinstance(option.default, (six.binary_type, six.text_type))): if option.is_argument: kwargs.nargs = len(option.default) else: kwargs.nargs = "+" if qualified_name.startswith('admin'): self.admin_arguments.append(new_arguments) else: self.arguments_for_building_argparse.append(new_arguments)
def test_rules_close_bubble_close_errors(self): config = DotDict() config.logger = Mock() config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ('RuleTestBrokenCloseMethod', RuleTestBrokenCloseMethod, 'RuleTestBrokenCloseMethod'), ] trs = transform_rules.TransformRuleSystem(config) assert_raises(AttributeError, trs.close) assert len(config.logger.debug.mock_calls) == 1 config.logger.debug.assert_any_call( 'trying to close %s', 'socorro.unittest.lib.test_transform_rules.' 'RuleTestBrokenCloseMethod')
def setup_config(self, prefix=None): config = DotDict() config.chatty_rules = False config.chatty = False config.tag = 'test.rule' config.action = 'apply_all_rules' config.rules_list = DotDict() config.rules_list.class_list = [ ( 'TestRuleTestLaughable', StatsdRuleBenchmarkWrapper, 'TestRuleTestLaughable' ), ( 'TestRuleTestDangerous', StatsdRuleBenchmarkWrapper, 'TestRuleTestDangerous' ) ] config.TestRuleTestLaughable = DotDict() config.TestRuleTestLaughable.laughable = 'wilma' config.TestRuleTestLaughable.statsd_class = StatsClient config.TestRuleTestLaughable.statsd_host = 'some_statsd_host' config.TestRuleTestLaughable.statsd_port = 3333 config.TestRuleTestLaughable.statsd_prefix = prefix if prefix else '' config.TestRuleTestLaughable.wrapped_object_class = TestRuleTestLaughable config.TestRuleTestLaughable.active_list = 'act' config.TestRuleTestDangerous = DotDict() config.TestRuleTestDangerous.dangerous = 'dwight' config.TestRuleTestDangerous.statsd_class = StatsClient config.TestRuleTestDangerous.statsd_host = 'some_statsd_host' config.TestRuleTestDangerous.statsd_port = 3333 config.TestRuleTestDangerous.statsd_prefix = prefix if prefix else '' config.TestRuleTestDangerous.wrapped_object_class = TestRuleTestDangerous config.TestRuleTestDangerous.active_list = 'act' return config