Ejemplo n.º 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")
Ejemplo n.º 2
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")
Ejemplo n.º 3
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--")
Ejemplo n.º 4
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--")
Ejemplo n.º 5
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--")
Ejemplo n.º 6
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--")
Ejemplo n.º 7
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--")
Ejemplo n.º 8
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--")
Ejemplo n.º 9
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')
Ejemplo n.º 10
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')
Ejemplo n.º 11
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')
Ejemplo n.º 12
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')
Ejemplo n.º 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")
Ejemplo n.º 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")
Ejemplo n.º 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")