Permalink
Browse files

Avoid modifying original config argument

  • Loading branch information...
nemesisdesign committed Dec 2, 2015
1 parent 69197ed commit 00051861eedcba93b23ea6a4654f5e4e9562a2a8
Showing with 10 additions and 1 deletion.
  1. +3 −1 netjsonconfig/backends/openwrt/openwrt.py
  2. +7 −0 tests/openwrt/test_backend.py
@@ -4,6 +4,7 @@
import time
import tarfile
from io import BytesIO
from copy import deepcopy
from jsonschema import validate
from jsonschema.exceptions import ValidationError as JsonSchemaError
@@ -32,7 +33,8 @@ def __init__(self, config, templates=[]):
as a base for the main config, defaults to empty list
:raises TypeError: raised if config is not dict or templates is not a list
"""
config = self._load(config)
# perform deepcopy to avoid modifying the original config argument
config = deepcopy(self._load(config))
# allow omitting NetJSON type
if 'type' not in config:
config.update({'type': 'DeviceConfiguration'})
@@ -12,8 +12,15 @@ class TestBackend(unittest.TestCase, _TabsMixin):
"""
tests for backends.openwrt.OpenWrt
"""
def test_config_copy(self):
config = {'interfaces': []}
o = OpenWrt(config)
o.validate()
self.assertDictEqual(config, {'interfaces': []})
def test_json_method(self):
config = {
"type": "DeviceConfiguration",
"interfaces": [
{
"name": "lo",

0 comments on commit 0005186

Please sign in to comment.