Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rules_as_tuple3():
manager = ActionsManager(ACTIONS_AS_TUPLE3)
_test_actions(
actions=manager.definitions,
values=(
# (class, trigger, name)
(DummyAction, settings.CHECK_STATE_ALWAYS, 'Always'),
(DummyAction, settings.CHECK_STATE_PASSED, 'On Passed'),
(DummyAction, settings.CHECK_STATE_FAILED, 'On Failed'),
(DummyAction, settings.CHECK_STATE_ERROR, 'On Error'),
),
},
"required": ["message", "traceback"],
},
},
"required": ["state", "rule"],
}
}
CHECK_RESULTS_PASS_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_PASS_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_PASSED]
CHECK_RESULTS_FAIL_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_FAIL_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_FAILED]
CHECK_RESULTS_ERROR_SCHEMA = copy.deepcopy(CHECK_RESULTS_SCHEMA)
CHECK_RESULTS_ERROR_SCHEMA['items']['properties']['state']['enum'] = [settings.CHECK_STATE_ERROR]
CHECK_RESULTS_ERROR_SCHEMA['items']['required'].append('error')
ACTION_RESULTS_SCHEMA = {
"type": "array",
"items": {
"type": "object",
"properties": {
"state": {"enum": list(settings.ACTION_STATES)},
"action": {
"type": "object",
"properties": {
"name": {"type": "string"},
"type": {"type": "string"},
"trigger": {"enum": list(settings.ACTION_TRIGGERS)},
},
DummyAction(),
DummyAction(),
DummyAction(),
]
ACTIONS_AS_TUPLE2 = [
('A', DummyAction()),
('B', DummyAction()),
('C', DummyAction()),
]
ACTIONS_AS_TUPLE3 = [
('Always', DummyAction(), settings.CHECK_STATE_ALWAYS),
('On Passed', DummyAction(), settings.CHECK_STATE_PASSED),
('On Failed', DummyAction(), settings.CHECK_STATE_FAILED),
('On Error', DummyAction(), settings.CHECK_STATE_ERROR),
]
@property
def error_actions(self):
return self._get_actions_for_trigger(settings.CHECK_STATE_ERROR)
def _check_rule(self, definition, stats):
result = RuleCheckResult(definition=definition)
try:
check_result = definition.rule.run_check(stats)
result.state = settings.CHECK_STATE_PASSED if check_result else settings.CHECK_STATE_FAILED
except Exception, e:
result.state = settings.CHECK_STATE_ERROR
result.error_message = str(e)
result.error_traceback = traceback.format_exc()
return result
@property
def error_actions(self):
return self._get_actions_for_trigger(settings.CHECK_STATE_ERROR)
def _check_rule(self, definition, stats):
result = RuleCheckResult(definition=definition)
try:
check_result = definition.rule.run_check(stats)
result.state = settings.CHECK_STATE_PASSED if check_result else settings.CHECK_STATE_FAILED
except Exception, e:
result.state = settings.CHECK_STATE_ERROR
result.error_message = str(e)
result.error_traceback = traceback.format_exc()
return result
def error(self):
return self.state == settings.CHECK_STATE_ERROR
@property
def error(self):
return self.state == settings.CHECK_STATE_ERROR