def test_returns_compound_filter(self): filters = [ { 'field': 'msg_type', }, { 'field': 'msg_type', 'value': 'debug', }, { 'field': 'status', 'regexp': '^4', 'include': False, }, ] rule = qvarn.construct_log_filter(filters) allowed = { 'msg_type': 'info', } self.assertTrue(rule.allow(allowed)) also_allowed = { 'msg_type': 'debug', } self.assertTrue(rule.allow(also_allowed)) denied = { 'status': '400', } self.assertFalse(rule.allow(denied))
def _load_filter_rules(self, conf, logname): opt = logname + '-filter' if conf.has_option('main', opt): filename = conf.get('main', opt) with open(filename) as f: filters = yaml.safe_load(f) return qvarn.construct_log_filter(filters) else: return qvarn.FilterAllow()
def test_handles_field_wanted(self): filters = [ { 'field': 'msg_type', }, ] rule = qvarn.construct_log_filter(filters) allowed = { 'msg_type': 'info', } self.assertTrue(rule.allow(allowed)) denied = { 'blah_blah': 'http-response', } self.assertFalse(rule.allow(denied))
def test_handles_regexp_match_wanted(self): filters = [ { 'field': 'status', 'regexp': '^4' }, ] rule = qvarn.construct_log_filter(filters) allowed = { 'status': 400, } self.assertTrue(rule.allow(allowed)) denied = { 'status': 200, } self.assertFalse(rule.allow(denied))
def test_handles_not_included(self): filters = [ { 'field': 'status', 'value': '400', 'include': False, }, ] rule = qvarn.construct_log_filter(filters) allowed = { 'status': '200', } self.assertTrue(rule.allow(allowed)) denied = { 'status': '400', } self.assertFalse(rule.allow(denied))
def test_raises_error_if_no_filters(self): filters = [] with self.assertRaises(Exception): qvarn.construct_log_filter(filters)