
From: Royce Lv <lvroyce@linux.vnet.ibm.com> Add testcase for xml_to_dict to validate string, xml file, and invalid string. Signed-off-by: Royce Lv <lvroyce@linux.vnet.ibm.com> --- tests/test_xmlutil.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/test_xmlutil.py diff --git a/tests/test_xmlutil.py b/tests/test_xmlutil.py new file mode 100644 index 0000000..0a93b54 --- /dev/null +++ b/tests/test_xmlutil.py @@ -0,0 +1,64 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2014 +# +# Authors: +# Royce Lv <lvroyce@linux.vnet.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import unittest + + +from kimchi.xmlutils import xml_to_dict +from kimchi.exception import ParseError + + +XML_STR = """ +<sources> + <source> + <host name='10.66.90.100'/> + <device path='iqn.2001-05.com.equallogic:0-8a0906-12a1f7d03'/> + </source> + <source> + <host name='10.66.90.100'/> + <device path='iqn.2001-05.com.equallogic:0-8a0906-9951f7d02'/> + </source> + <source> + <host name='10.66.90.100'/> + <device path='iqn.2001-05.com.equallogic:0-8a0906-6eb1f7d01'/> + </source> +</sources> +""" + +ILLEGAL_STR = """ +<sources> +<sources/> +""" + + +class XMLParseTests(unittest.TestCase): + def test_parse_xml_string(self): + res = xml_to_dict(XML_STR) + dic = {'sources': + {'source': [ + {'device': {'path': 'iqn.2001-05.com.equallogic:0-8a0906-12a1f7d03'}, 'host': {'name': '10.66.90.100'}}, + {'device': {'path': 'iqn.2001-05.com.equallogic:0-8a0906-9951f7d02'}, 'host': {'name': '10.66.90.100'}}, + {'device': {'path': 'iqn.2001-05.com.equallogic:0-8a0906-6eb1f7d01'}, 'host': {'name': '10.66.90.100'}}]}} + self.assertEquals(res, dic) + + def test_parse_illegal(self): + self.assertRaises(ParseError, xml_to_dict, ILLEGAL_STR) -- 1.8.1.2