def test_check_key(self): p = Pipe() section = { "conditions": [("startswith", "ma"), ("endswith", "ru")] } res = p.check_key("mail.ru", section['conditions'], mode=Logic.AND) self.assertEqual(res, True) section = { "conditions": [("startswith", "ma"), ("endswith", "r")] } res = p.check_key("mail.ru", section['conditions'], mode=Logic.AND) self.assertEqual(res, False) section = { "conditions": [("startswith", "ma"), ("endswith", "r")] } res = p.check_key("mail.ru", section['conditions'], mode=Logic.OR) self.assertEqual(res, True) section = { "conditions": [("startswith", "a"), ("endswith", "r")] } res = p.check_key("mail.ru", section['conditions'], mode=Logic.OR) self.assertEqual(res, False)
def test_alter_delete(self): p = Pipe() section = "all" res = p.alter_delete(copy(self.dictionary), section) self.assertEqual(res, None) section = ["hostname", "status"] res = p.alter_delete(copy(self.dictionary), section) self.assertEqual( [res.get('hostname', None), res.get('status', None)], [None, None] )
def test_apply_with_dict_pipe(self): pipe = { "match": { "hostname": { "conditions": [("iexact", "mail.ru")] } }, "alter": { "drop": "ALL" } } p = Pipe() res = p.apply(copy(self.dictionary), pipe) self.assertEqual(res, None)
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)