First test using is_xml_equal function

darcs-hash:20080229070242-86b55-e6f244052d1bde8ced3c5f7a1f804fc8d77e381d.gz
This commit is contained in:
David Rousselie
2008-02-29 08:02:42 +01:00
parent 17fe7ff3fa
commit 64cc251a26
2 changed files with 39 additions and 18 deletions

View File

@@ -383,19 +383,13 @@ class JCLCommandManager_TestCase(JCLTestCase):
self.command_manager.add_form_select_users_jids(command_node, "title", self.command_manager.add_form_select_users_jids(command_node, "title",
"description", "description",
Lang.en.field_users_jids) Lang.en.field_users_jids)
x_data = info_query.xpath_eval("c:command/data:x", self.assertTrue(jcl.tests.is_xml_equal(\
{"c": "http://jabber.org/protocol/commands", u"<command xmlns='http://jabber.org/protocol/commands'>"
"data": "jabber:x:data"}) + "<x xmlns='jabber:x:data' type='form'>"
self.assertEquals(len(x_data), 1) + "<field var='user_jids' type='jid-multi' label='"
self.assertEquals(x_data[0].prop("type"), "form") + Lang.en.field_users_jids + "' />"
user_jid_field = info_query.xpath_eval("c:command/data:x/data:field[1]", + "</x></command>",
{"c": "http://jabber.org/protocol/commands", info_query.xmlnode.children))
"data": "jabber:x:data"})
self.assertNotEquals(user_jid_field, None)
self.assertEquals(len(user_jid_field), 1)
self.assertEquals(user_jid_field[0].prop("var"), "user_jids")
self.assertEquals(user_jid_field[0].prop("type"), "jid-multi")
self.assertEquals(user_jid_field[0].prop("label"), Lang.en.field_users_jids)
def test_add_form_select_user_jid(self): def test_add_form_select_user_jid(self):
info_query = Iq(stanza_type="set", info_query = Iq(stanza_type="set",

View File

@@ -36,10 +36,12 @@ def is_xml_equal(xml_ref, xml_test, strict=False, test_sibling=True):
return True return True
if (xml_ref is None) and (xml_test is None): if (xml_ref is None) and (xml_test is None):
return True return True
if isinstance(xml_ref, types.StringType): if isinstance(xml_ref, types.StringType) \
xml_ref = libxml2.parseDoc(xml_ref) or isinstance(xml_ref, types.UnicodeType):
if isinstance(xml_test, types.StringType): xml_ref = libxml2.parseDoc(xml_ref).children
xml_test = libxml2.parseDoc(xml_test) if isinstance(xml_test, types.StringType) \
or isinstance(xml_test, types.UnicodeType):
xml_test = libxml2.parseDoc(xml_test).children
def check_equality(test_func, ref, test, strict): def check_equality(test_func, ref, test, strict):
""" """
@@ -65,7 +67,7 @@ def is_xml_equal(xml_ref, xml_test, strict=False, test_sibling=True):
xml_ref, xml_test, strict): xml_ref, xml_test, strict):
return False return False
if not check_equality(lambda ref, test: ref.ns() == test.ns(), if not check_equality(lambda ref, test: str(ref.ns()) == str(test.ns()),
xml_ref, xml_test, strict): xml_ref, xml_test, strict):
return False return False
@@ -109,6 +111,31 @@ def is_xml_equal(xml_ref, xml_test, strict=False, test_sibling=True):
return True return True
class JCLTest_TestCase(unittest.TestCase): class JCLTest_TestCase(unittest.TestCase):
def test_is_xml_equal_str_node_vs_xml_node(self):
"""
Test if an xml node is equal to its string representation.
"""
# Get xml_node children because parseDoc return an xmlDocument
# and we usually test against an xmlNode
xml_node = libxml2.parseDoc("<test />").children
self.assertTrue(is_xml_equal(str(xml_node), xml_node))
def test_is_xml_equal_xml_node_vs_str_node(self):
"""
Test if an xml node is equal to its string representation.
"""
# Get xml_node children because parseDoc return an xmlDocument
# and we usually test against an xmlNode
xml_node = libxml2.parseDoc("<test />").children
self.assertTrue(is_xml_equal(xml_node, str(xml_node)))
def test_is_xml_equal_namespace(self):
"""
Test for namespace equality.
"""
self.assertTrue(is_xml_equal("<test xmlns='http://test.com' />",
"<test xmlns='http://test.com' />"))
########################################################################### ###########################################################################
## Test weak equality ## Test weak equality
########################################################################### ###########################################################################