Skip to content
Permalink
Browse files

[schema] Validate general hostname format #42

  • Loading branch information
nemesisdesign committed Apr 3, 2016
1 parent 195055d commit ef8c296b2532e13b0459c3b22e17cb755f42151b
Showing with 20 additions and 2 deletions.
  1. +2 −2 netjsonconfig/backends/openwrt/openwrt.py
  2. +1 −0 netjsonconfig/schema.py
  3. +17 −0 tests/openwrt/test_formats.py
@@ -7,7 +7,7 @@

import six
from jinja2 import Environment, PackageLoader
from jsonschema import validate
from jsonschema import FormatChecker, validate
from jsonschema.exceptions import ValidationError as JsonSchemaError

from . import renderers
@@ -130,7 +130,7 @@ def _render_files(self):

def validate(self):
try:
validate(self.config, self.schema)
validate(self.config, self.schema, format_checker=FormatChecker())
except JsonSchemaError as e:
raise ValidationError(e)

@@ -629,6 +629,7 @@
"type": "string",
"maxLength": 63,
"minLength": 1,
"format": "hostname",
"propertyOrder": 1,
},
"ula_prefix": {
@@ -0,0 +1,17 @@
import unittest

from netjsonconfig import OpenWrt
from netjsonconfig.exceptions import ValidationError
from netjsonconfig.utils import _TabsMixin


class TestFormats(unittest.TestCase, _TabsMixin):
maxDiff = None

def test_general_hostname(self):
o = OpenWrt({"general": {"hostname": "invalid hostname"}})
with self.assertRaises(ValidationError):
o.validate()
o.config['general']['hostname'] = 'valid'
o.validate()

0 comments on commit ef8c296

Please sign in to comment.
You can’t perform that action at this time.