def test_check_match_with_logic(self): p = Pipe() section = { "hostname": { "conditions": [("exact", "mail.ru"), ] }, "protocol": { "conditions": [("exact", "snmp"), ] } } res = p.check_match(copy(self.dictionary), section, mode=Logic.AND) self.assertEqual(res, False) res = p.check_match(copy(self.dictionary), section, mode=Logic.OR) self.assertEqual(res, True)
def test_check_match_without_logic(self): p = Pipe() section = { "hostname": { "conditions": [("exact", "mail.ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("exact", "bail.ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, False) section = { "hostname": { "conditions": [("startswith", "mai"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("startswith", "bai"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, False) section = { "hostname": { "conditions": [("endswith", "ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("endswith", "com"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, False) section = { "hostname": { "conditions": [("regex", "^mail[\.]{1,}ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("regex", "^mail[\-]{1,}ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, False) section = { "hostname": { "conditions": [("contains", "ail.r"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("contains", "ya.r"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, False) section = { "hostname": { "conditions": [("iexact", "Mail.ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "hostname": { "conditions": [("iexact", "Mail.ru"), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "repeats": { "conditions": [("gt", 50), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True) section = { "repeats": { "conditions": [("lt", 5000), ] } } res = p.check_match(copy(self.dictionary), section) self.assertEqual(res, True)