Improve coverage for from_xml and to_xml (#76)
Improve coverage for from_xml and to_xml Reviewed-by: https://github.com/apps/ansible-zuulpull/79/head
parent
32a6922235
commit
454e2ca935
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
trivial:
|
||||
- Improve coverage of uts related to to_xml and from_xml filter plugin.
|
|
@ -9,7 +9,8 @@ __metaclass__ = type
|
|||
|
||||
import unittest
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible_collections.ansible.utils.plugins.filter.from_xml import from_xml
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible_collections.ansible.utils.plugins.filter.from_xml import _from_xml
|
||||
|
||||
INVALID_DATA = '<netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">'
|
||||
|
||||
|
@ -30,11 +31,10 @@ class TestFromXml(unittest.TestCase):
|
|||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = [INVALID_DATA, "xmltodict"]
|
||||
args = ["", INVALID_DATA, "xmltodict"]
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleError) as error:
|
||||
from_xml(*args, **kwargs)
|
||||
print(str(error.exception))
|
||||
_from_xml(*args, **kwargs)
|
||||
self.assertIn(
|
||||
"Error when using plugin 'from_xml': Input Xml is not valid",
|
||||
str(error.exception),
|
||||
|
@ -43,7 +43,26 @@ class TestFromXml(unittest.TestCase):
|
|||
def test_valid_data(self):
|
||||
"""Check passing valid data as per criteria"""
|
||||
self.maxDiff = None
|
||||
args = [VALID_DATA, "xmltodict"]
|
||||
result = from_xml(*args)
|
||||
print(result)
|
||||
args = ["", VALID_DATA, "xmltodict"]
|
||||
result = _from_xml(*args)
|
||||
self.assertEqual(result, OUTPUT)
|
||||
|
||||
def test_args(self):
|
||||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = []
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleFilterError) as error:
|
||||
_from_xml(*args, **kwargs)
|
||||
self.assertIn("missing required arguments: data", str(error.exception))
|
||||
|
||||
def test_invalid_engine(self):
|
||||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = ["", INVALID_DATA, "test"]
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleError) as error:
|
||||
_from_xml(*args, **kwargs)
|
||||
self.assertIn("engine: test is not supported", str(error.exception))
|
||||
|
|
|
@ -9,7 +9,8 @@ __metaclass__ = type
|
|||
|
||||
import unittest
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible_collections.ansible.utils.plugins.filter.to_xml import to_xml
|
||||
from ansible.errors import AnsibleFilterError
|
||||
from ansible_collections.ansible.utils.plugins.filter.to_xml import _to_xml
|
||||
|
||||
INVALID_DATA = '<netconf-state xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring">'
|
||||
|
||||
|
@ -31,20 +32,37 @@ class TestToXml(unittest.TestCase):
|
|||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = [INVALID_DATA, "xmltodict"]
|
||||
args = ["", INVALID_DATA, "xmltodict"]
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleError) as error:
|
||||
to_xml(*args, **kwargs)
|
||||
print(str(error.exception))
|
||||
_to_xml(*args, **kwargs)
|
||||
self.assertIn(
|
||||
"Error when using plugin 'to_xml': Input json is not valid",
|
||||
str(error.exception),
|
||||
"we were unable to convert to dict", str(error.exception)
|
||||
)
|
||||
|
||||
def test_valid_data(self):
|
||||
"""Check passing valid data as per criteria"""
|
||||
self.maxDiff = None
|
||||
args = [VALID_DATA, "xmltodict"]
|
||||
result = to_xml(*args)
|
||||
print(result)
|
||||
args = ["", VALID_DATA, "xmltodict"]
|
||||
result = _to_xml(*args)
|
||||
self.assertEqual(result, OUTPUT)
|
||||
|
||||
def test_args(self):
|
||||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = []
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleFilterError) as error:
|
||||
_to_xml(*args, **kwargs)
|
||||
self.assertIn("missing required arguments: data", str(error.exception))
|
||||
|
||||
def test_invalid_engine(self):
|
||||
"""Check passing invalid argspec"""
|
||||
|
||||
# missing required arguments
|
||||
args = ["", VALID_DATA, "test"]
|
||||
kwargs = {}
|
||||
with self.assertRaises(AnsibleError) as error:
|
||||
_to_xml(*args, **kwargs)
|
||||
self.assertIn("engine: test is not supported", str(error.exception))
|
||||
|
|
Loading…
Reference in New Issue