示例#1
0
文件: tests.py 项目: FZambia/fly
    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)
示例#2
0
文件: tests.py 项目: FZambia/fly
    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)