Exemple #1
0
    def test_template_with_structure(self):
        frosting = Frosting(self.template)
        frosting.load_yaml_structure(self.structure)
        frosting.add("var1", "1.1.1.1")
        frosting.add("var2", "2.2.2.2")
        result = frosting.compile()

        self.assertEqual(result, "1.1.1.1:2.2.2.2")
Exemple #2
0
    def test_cidrv6_validator_error(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.CIDRv6'
            }
        }

        frost.load_structure(structure)
        with self.assertRaises(frosting.exceptions.FieldInputNotValid):
            frost.add('var', '2001:db8:f00:ba44::1ac')
Exemple #3
0
    def test_asn_validator_error(self):
        frost = Frosting("--{{asn}}--")
        structure = {
            "asn": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.ASN'
            }
        }

        frost.load_structure(structure)
        with self.assertRaises(frosting.exceptions.FieldInputNotValid):
            frost.add('asn', 'WRONG')
Exemple #4
0
    def test_iox_phy_intf_validator_error(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.VLAN'
            }
        }

        frost.load_structure(structure)
        with self.assertRaises(frosting.exceptions.FieldInputNotValid):
            frost.add('var', 'xe-0/1/2/1')
Exemple #5
0
 def test_regex_validator_error(self):
     frost = Frosting("--{{foo}}--")
     structure = {
         "foo": {
             'type': 'frosting.types.TextInput',
             'validator': 'frosting.validators.RegexValidator',
             'regex': '^[a-z][0-9]$'
         }
     }
     frost.load_structure(structure)
     with self.assertRaises(frosting.exceptions.FieldInputNotValid):
         frost.add('foo', 'INCORRECT')
Exemple #6
0
    def test_regex_validator(self):
        frost = Frosting("--{{foo}}--")
        structure = {
            "foo": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.RegexValidator',
                'regex': '^[a-z][0-9]$'
            }
        }
        frost.load_structure(structure)
        frost.add('foo', 'b7')
        result = frost.compile()

        self.assertEqual(result, "--b7--")
Exemple #7
0
    def test_cidrv6_validator(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.CIDRv6'
            }
        }

        frost.load_structure(structure)
        frost.add('var', '2001:db8:f00:ba44::1ac/96')
        result = frost.compile()

        self.assertEqual(result, "--2001:db8:f00:ba44::1ac/96--")
Exemple #8
0
    def test_cidrv4_validator(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.CIDRv4'
            }
        }

        frost.load_structure(structure)
        frost.add('var', '198.18.0.10/32')
        result = frost.compile()

        self.assertEqual(result, "--198.18.0.10/32--")
Exemple #9
0
    def test_iox_phy_intf_validator(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.IOSXR_Physical_Interface'
            }
        }

        frost.load_structure(structure)
        frost.add('var', 'TenGigE0/1/2/3')
        result = frost.compile()

        self.assertEqual(result, "--TenGigE0/1/2/3--")
Exemple #10
0
    def test_vlan_validator(self):
        frost = Frosting("--{{var}}--")
        structure = {
            "var": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.VLAN'
            }
        }

        frost.load_structure(structure)
        frost.add('var', '100')
        result = frost.compile()

        self.assertEqual(result, "--100--")
Exemple #11
0
    def test_asn_validator(self):
        frost = Frosting("--{{asn}}--")
        structure = {
            "asn": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.ASN'
            }
        }

        frost.load_structure(structure)
        frost.add('asn', '65123')
        result = frost.compile()

        self.assertEqual(result, "--65123--")
Exemple #12
0
    def test_limit_string_input(self):
        frost = Frosting(self.template)
        structure = {
            "var1": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.IPv4_Address'
            },
            "var2": {
                'type': 'frosting.types.IntegerInput',
                'limit': '1..100'
            }
        }
        frost.load_structure(structure)
        frost.add("var1", "1.1.1.1")
        frost.add("var2", "99")
        result = frost.compile()

        self.assertEqual(result, "1.1.1.1:99")
Exemple #13
0
    def test_dict_structure(self):
        frost = Frosting(self.template)
        structure = {
            "var1": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.IPv4_Address'
            },
            "var2": {
                'type': 'frosting.types.TextInput',
                'validator': 'frosting.validators.IPv4_Address'
            }
        }
        frost.load_structure(structure)
        frost.add("var1", "1.1.1.1")
        frost.add("var2", "2.2.2.2")
        result = frost.compile()

        self.assertEqual(result, "1.1.1.1:2.2.2.2")
Exemple #14
0
 def test_validator(self):
     frost = Frosting(self.template)
     frost.load_yaml_structure(self.structure)
     with self.assertRaises(frosting.exceptions.FieldInputNotValid):
         frost.add("var1", "1.1.1.1.1")
Exemple #15
0
 def test_template_no_structure(self):
     frosting = Frosting(self.template)
     frosting.add("var1", "foo")
     frosting.add("var2", "bar")
     result = frosting.compile()
     self.assertEqual(result, "foo:bar")