Skip to content

Commit

Permalink
[OpenWisp] Declared hostname required #18
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Nov 23, 2015
1 parent d0275cf commit f1d1269
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions netjsonconfig/backends/openwisp/openwisp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from io import BytesIO

from ..openwrt.openwrt import OpenWrt
from .schema import schema


class OpenWisp(OpenWrt):
""" OpenWisp Backend """
schema = schema

def generate(self, name='openwrt-config'):
"""
Expand Down
14 changes: 14 additions & 0 deletions netjsonconfig/backends/openwisp/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
OpenWisp specific JSON-Schema definition
(extends OpenWrt JSON-Schema)
"""
from ..openwrt.schema import schema as openwrt_schema
from ...utils import merge_config

schema = merge_config(openwrt_schema, {
"properties": {
"general": {
"required": ["hostname"]
}
}
})
10 changes: 10 additions & 0 deletions tests/openwisp/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tarfile

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


Expand Down Expand Up @@ -31,3 +32,12 @@ def test_uci(self):
# close and delete tar.gz file
tar.close()
os.remove('openwrt-config.tar.gz')

def test_hostname_required(self):
o = OpenWisp({
"general": {
"timezone": "Coordinated Universal Time"
}
})
with self.assertRaises(ValidationError):
o.validate()

0 comments on commit f1d1269

Please sign in to comment.