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