Skip to content

Commit

Permalink
[openwrt] Added 'config_value' identifier in utils.merge_list
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jan 24, 2017
1 parent 6f712d1 commit fcae96c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netjsonconfig/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def merge_config(template, config):
return result


def merge_list(list1, list2, identifiers=['name', 'id']):
def merge_list(list1, list2, identifiers=['name', 'config_value', 'id']):
"""
Merges ``list2`` on top of ``list1``.
Expand Down
36 changes: 36 additions & 0 deletions tests/openwrt/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,39 @@ def test_warning(self):
]
})
self.assertEqual(o.render(), 'package luci\n')

def test_merge(self):
template = {
"luci": [
{
"config_name": "core",
"config_value": "main",
"number": 3,
"list": ["eth0"],
"some_value": True
}
]
}
config = {
"luci": [
{
"config_name": "core",
"config_value": "main",
"number": 4,
"list": ["wlan0"]
}
]
}
expected = {
"luci": [
{
"config_name": "core",
"config_value": "main",
"number": 4,
"list": ["eth0", "wlan0"],
"some_value": True
}
]
}
o = OpenWrt(config, templates=[template])
self.assertEqual(o.config, expected)
6 changes: 6 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,9 @@ def test_merge_list_union_and_override(self):
{"id": "test1", "a": "0", "b": "b"},
{"id": "test2", "c": "c"}
])

def test_merge_list_config_value(self):
template = [{"config_value": "test1", "tx": 1}]
config = [{"config_value": "test1", "tx": 2}]
result = merge_list(template, config)
self.assertEqual(result, config)

0 comments on commit fcae96c

Please sign in to comment.