Skip to content

Commit

Permalink
Allow omitting { "type": "DeviceConfiguration" } #13
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
nemesifier committed Sep 30, 2015
1 parent 7d83314 commit b7da52c
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 34 deletions.
3 changes: 3 additions & 0 deletions netjsonconfig/backends/openwrt/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self, config):
"""
if not isinstance(config, dict):
raise TypeError('Config argument must be an istance of dict or one of its subclasses')
# allow omitting NetJSON type
if 'type' not in config:
config.update({'type': 'DeviceConfiguration'})
self.config = config
self.env = Environment(loader=PackageLoader('netjsonconfig.backends.openwrt', 'templates'),
trim_blocks=True)
Expand Down
8 changes: 0 additions & 8 deletions tests/openwrt/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class TestBackend(unittest.TestCase):
"""
def test_json(self):
config = {
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "lo",
Expand All @@ -31,10 +30,6 @@ def test_json(self):
self.assertEqual(json.loads(o.json()), config)

def test_validate(self):
o = OpenWrt({})
with self.assertRaises(ValidationError):
o.validate()

o = OpenWrt({'type': 'WRONG'})
with self.assertRaises(ValidationError):
o.validate()
Expand All @@ -51,7 +46,6 @@ def test_type_error(self):

def test_system_invalid_timezone(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"general": {
"hostname": "test_system",
"timezone": "WRONG",
Expand All @@ -62,7 +56,6 @@ def test_system_invalid_timezone(self):

def test_schema_radio_wrong_driver(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand All @@ -80,7 +73,6 @@ def test_schema_radio_wrong_driver(self):

def test_schema_radio_wrong_protocol(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand Down
11 changes: 0 additions & 11 deletions tests/openwrt/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TestNetworkRendererer(unittest.TestCase, _TabsMixin):
"""
def test_loopback(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "lo",
Expand All @@ -37,7 +36,6 @@ def test_loopback(self):

def test_multiple_ip(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0.1",
Expand Down Expand Up @@ -90,7 +88,6 @@ def test_multiple_ip(self):

def test_dhcp(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0",
Expand All @@ -114,7 +111,6 @@ def test_dhcp(self):

def test_multiple_dhcp(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0",
Expand Down Expand Up @@ -146,7 +142,6 @@ def test_multiple_dhcp(self):

def test_ipv4_routes(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth1",
Expand Down Expand Up @@ -207,7 +202,6 @@ def test_ipv4_routes(self):

def test_ipv6_routes(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth1",
Expand Down Expand Up @@ -260,7 +254,6 @@ def test_ipv6_routes(self):

def test_additional_proto(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "mobile0",
Expand All @@ -282,7 +275,6 @@ def test_additional_proto(self):

def test_interface_custom_attrs(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "mobile0",
Expand Down Expand Up @@ -311,7 +303,6 @@ def test_interface_custom_attrs(self):

def test_eth_bridge(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0",
Expand Down Expand Up @@ -374,7 +365,6 @@ def test_eth_bridge(self):

def test_dns(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0",
Expand Down Expand Up @@ -411,7 +401,6 @@ def test_dns(self):

def test_rules(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"ip_rules": [
{
"in": "eth0",
Expand Down
3 changes: 0 additions & 3 deletions tests/openwrt/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TestSystemRendererer(unittest.TestCase, _TabsMixin):
"""
def test_system(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"general": {
"hostname": "test_system",
"timezone": "Europe/Rome",
Expand All @@ -30,7 +29,6 @@ def test_system(self):

def test_ntp(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"ntp": {
"enabled": True,
"enable_server": False,
Expand All @@ -56,7 +54,6 @@ def test_ntp(self):

def test_led_1(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"led": [
{
"name": "USB1",
Expand Down
12 changes: 0 additions & 12 deletions tests/openwrt/test_wireless.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class TestWirelessRendererer(unittest.TestCase, _TabsMixin):
"""
def test_radio(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand Down Expand Up @@ -60,7 +59,6 @@ def test_radio(self):

def test_radio_2ghz_mac80211(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand Down Expand Up @@ -104,7 +102,6 @@ def test_radio_2ghz_mac80211(self):

def test_radio_2ghz_athk(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand Down Expand Up @@ -148,7 +145,6 @@ def test_radio_2ghz_athk(self):

def test_radio_ac_and_custom_attrs(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"radios": [
{
"name": "radio0",
Expand Down Expand Up @@ -180,7 +176,6 @@ def test_radio_ac_and_custom_attrs(self):

def test_wifi_interfaces(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -243,7 +238,6 @@ def test_wifi_interfaces(self):

def test_wifi_encryption_wep_open(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -289,7 +283,6 @@ def test_wifi_encryption_wep_open(self):

def test_wifi_encryption_wep_shared(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -335,7 +328,6 @@ def test_wifi_encryption_wep_shared(self):

def test_wifi_encryption_wpa_personal(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -383,7 +375,6 @@ def test_wifi_encryption_wpa_personal(self):

def test_wifi_encryption_wpa2_personal(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -432,7 +423,6 @@ def test_wifi_encryption_wpa2_personal(self):

def test_encryption_disabled(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -479,7 +469,6 @@ def test_encryption_disabled(self):

def test_multiple_ssid(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "wlan0",
Expand Down Expand Up @@ -539,7 +528,6 @@ def test_multiple_ssid(self):

def test_wifi_bridge(self):
o = OpenWrt({
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "eth0",
Expand Down

0 comments on commit b7da52c

Please sign in to comment.