Skip to content

Commit

Permalink
test: Add add_dict_to_node test
Browse files Browse the repository at this point in the history
  • Loading branch information
skycastlelily authored and pvoborni committed May 14, 2024
1 parent f4324bf commit 2c0c2bb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/mrack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,13 @@ def add_dict_to_node(node, input_dict):
child_node.appendChild(
add_dict_to_node(xml_doc().createElement(k), v)
)
if key.startswith("_"):
node.setAttribute(key[1:], str(value))
else:
node.appendChild(add_dict_to_node(xml_doc().createElement(key), value))
if key.startswith("_"):
node.setAttribute(key[1:], str(value))
else:
node.appendChild(
add_dict_to_node(xml_doc().createElement(key), value)
)

return node

Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from xml.dom.minidom import Document as xml_doc

import pytest

from mrack.utils import (
add_dict_to_node,
get_fqdn,
get_os_type,
get_shortname,
Expand Down Expand Up @@ -170,3 +173,37 @@ def test_get_ssh_options(self, provisioning_config, metahost1):
def test_ssh_options_to_cli(self, options, expected):
"""Test conversion of SSH options to CLI params."""
assert ssh_options_to_cli(options) == expected

@pytest.mark.parametrize(
"req_node, dct, expected",
[
(
xml_doc().createElement("not"),
{
"key_value": {
"_key": "NETBOOT_METHOD",
"_op": "like",
"_value": "grub2",
}
},
'<not><key_value key="NETBOOT_METHOD" op="like" value="grub2"/></not>',
),
(
xml_doc().createElement("and"),
{
"not": [
{
"key_value": {
"_key": "BOOTDISK",
"_op": "==",
"_value": "dum",
}
},
]
},
'<and><not><key_value key="BOOTDISK" op="==" value="dum"/></not></and>',
),
],
)
def test_add_dict_to_node(self, req_node, dct, expected):
assert add_dict_to_node(req_node, dct).toxml() == expected

0 comments on commit 2c0c2bb

Please sign in to comment.