How to use the spidermon.exceptions.InvalidRuleDefinition function in spidermon

To help you get started, we’ve selected a few spidermon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scrapinghub / spidermon / _tests / rules / test_managers.py View on Github external
def test_errors():
    with pytest.raises(InvalidRuleDefinition):
        RulesManager([()])

    with pytest.raises(InvalidRuleDefinition):
        RulesManager([None])

    with pytest.raises(InvalidRuleDefinition):
        RulesManager([10])

    with pytest.raises(InvalidRuleLevel):
        RulesManager([('rule', SimpleRule, 'WRONG LEVEL')])

    with pytest.raises(InvalidRuleDefinition):
        RulesManager([('rule', SimpleRule, settings.LEVEL_NORMAL, None)])
github scrapinghub / spidermon / _spidermon / rules / definitions.py View on Github external
def _get_rule(self, rule, test_case):
        if isinstance(rule, Rule):
            return rule
        elif hasattr(rule, '__call__'):
            if test_case:
                return TestCaseRule(rule, test_case)
            else:
                return CallableRule(rule)
        elif isinstance(rule, six.string_types):
            return PythonExpressionRule(rule)
        else:
            raise InvalidRuleDefinition('Wrong Rule definition, rules should be:\n'
                                        '- an instance of Rule/TestCase objects.\n'
github scrapinghub / spidermon / _spidermon / rules / managers.py View on Github external
def _add_definition_from_tuple(self, tuple_definition):
        level = None
        if len(tuple_definition) == 2:
            name, rule = tuple_definition
        elif len(tuple_definition) == 3:
            name, rule, level = tuple_definition
        else:
            raise InvalidRuleDefinition('Wrong Rule tuple definition, you should '
                                        'either use (name, rule) or '
                                        '(name, rule, level)')
        self.add_rule(rule=rule, name=name, level=level)
github scrapinghub / spidermon / spidermon / managers.py View on Github external
def _add_definition_from_tuple(self, tuple_definition):
        level = None
        if len(tuple_definition) == 2:
            name, rule = tuple_definition
        elif len(tuple_definition) == 3:
            name, rule, level = tuple_definition
        else:
            raise InvalidRuleDefinition('Wrong Rule tuple definition, you should '
                                        'either use (name, rule) or '
                                        '(name, rule, level)')
        self.add_rule(rule=rule, name=name, level=level)
github scrapinghub / spidermon / spidermon / managers.py View on Github external
def _get_rule(self, rule, test_case):
        if isinstance(rule, Rule):
            return rule
        elif hasattr(rule, '__call__'):
            if test_case:
                return TestCaseRule(rule, test_case)
            else:
                return CallableRule(rule)
        elif isinstance(rule, six.string_types):
            return PythonExpressionRule(rule)
        else:
            raise InvalidRuleDefinition('Wrong Rule definition, rules should be:\n'
                                        '- an instance of Rule/TestCase objects.\n'