def tool_assert_equal_xml(self, xml_a, xml_b, message=None): self.assertEqual( dom_to_dict(minidom.parseString(xml_a).firstChild), dom_to_dict(minidom.parseString(xml_b).firstChild), message )
def test_dom_to_dict(self): """ Test xml->dict serialization Creates a node, generates the dict using dict_to_dom and compares a pickled result """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_node.setAttribute("testattribute", "value") test_subnode = test_doc.createElement("subtest") test_subnode.appendChild(test_doc.createTextNode("testcontent")) test_node.appendChild(test_subnode) test_doc.appendChild(test_node) test_dict = dom_to_dict(test_node) expected_result = "(dp0\nS'test'\np1\n(" \ "dp2\nS'testattribute'\np3\nS'value'\np4\nsS" \ "'subtest'\np5\n(" \ "dp6\nS'_content'\np7\nS'testcontent'\np8\nsss." self.assertEqual( expected_result, pickle.dumps(test_dict) )
def test_dom_to_dict(self): """ Test xml->dict serialization Creates a node, generates the dict using dict_to_dom and compares a pickled result """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_node.setAttribute("testattribute", "value") test_subnode = test_doc.createElement("subtest") test_subnode.appendChild(test_doc.createTextNode("testcontent")) test_node.appendChild(test_subnode) test_doc.appendChild(test_node) test_dict = dom_to_dict(test_node) expected_result = { "test": { "testattribute": "value", "subtest": { "_content": "testcontent" } } } self.assertEqual(expected_result, test_dict)
def test_dom_to_dict(self): """ Test xml->dict serialization Creates a node, generates the dict using dict_to_dom and compares a pickled result """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_node.setAttribute("testattribute", "value") test_subnode = test_doc.createElement("subtest") test_subnode.appendChild(test_doc.createTextNode("testcontent")) test_node.appendChild(test_subnode) test_doc.appendChild(test_node) test_dict = dom_to_dict(test_node) expected_result = "(dp0\nS'test'\np1\n(" \ "dp2\nS'testattribute'\np3\nS'value'\np4\nsS" \ "'subtest'\np5\n(" \ "dp6\nS'_content'\np7\nS'testcontent'\np8\nsss." self.assertEqual(expected_result, pickle.dumps(test_dict))
def get_header(self): return self._filter_response( dom_to_dict( self.response_doc.getElementsByTagNameNS( "*", "Header" ).item(0).firstChild ) )
def get_response(self, request_id=0): if self.is_batch(): search_node = self.response_doc.getElementsByTagNameNS("*", "BatchResponse").item(0) for child in search_node.childNodes: if child.getAttribute("requestId") == request_id: return self._filter_response(dom_to_dict(child)) return None else: search_node = self.response_doc.getElementsByTagNameNS("*", "Body").item(0) return self._filter_response(dom_to_dict(search_node.firstChild))
def get_response(self, request_id=0): if self.is_batch(): search_node = self.response_doc.getElementsByTagNameNS( "*", "BatchResponse").item(0) for child in search_node.childNodes: if int(child.getAttribute("requestId")) == request_id: return self._filter_response(dom_to_dict(child)) return None else: search_node = self.response_doc.getElementsByTagNameNS( "*", "Body").item(0) return self._filter_response(dom_to_dict(search_node.firstChild))
def test_dict_to_dom_unicode(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': 'value2\xf6', 'subnode31': { '_content': 'testcontent3\xf6' } }, 'listsubnode': [ { "_content": "value1" }, { "_content": "value2" }, { "_content": "value3" } ] } xmlserializer.dict_to_dom(test_node, test_dict) self.assertEqual( xmlserializer.dom_to_dict(test_node), { "test": test_dict } )
def test_dict_to_dom(self): """ Test xml serialization using dict_to_dom method. """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_dict = { 'attr1': 'value1', 'attr2': 'value2', 'subnode1': { '_content': 'testcontent' }, 'subnode2': { 'subnode2attr1': 'value1', 'subnode2attr2': 'value2', '_content': 'testcontent2' }, 'subnode3': { 'subnode3attr1': 'value1', 'subnode3attr2': 'value2', 'subnode31': { '_content': 'testcontent3' } }, 'listsubnode': [{ "_content": "value1" }, { "_content": "value2" }, { "_content": "value3" }] } xmlserializer.dict_to_dom(test_node, test_dict) self.assertEqual(xmlserializer.dom_to_dict(test_node), {"test": test_dict})
def test_dom_to_dict(self): """ Test xml->dict serialization Creates a node, generates the dict using dict_to_dom and compares a pickled result """ test_doc = minidom.Document() test_node = test_doc.createElement("test") test_node.setAttribute("testattribute", "value") test_subnode = test_doc.createElement("subtest") test_subnode.appendChild(test_doc.createTextNode("testcontent")) test_node.appendChild(test_subnode) test_doc.appendChild(test_node) test_dict = dom_to_dict(test_node) expected_result = { "test": { "testattribute": "value", "subtest": { "_content": "testcontent" } } } self.assertEqual( expected_result, test_dict )
def get_header(self): return dom_to_dict(self.response_doc.getElementsByTagNameNS("*", "Header").item(0))
def get_body(self): return dom_to_dict(self.response_doc.getElementsByTagNameNS("*", "Body").item(0))
def tool_assert_equal_xml(self, xml_a, xml_b, message=None): self.assertEqual(dom_to_dict(minidom.parseString(xml_a).firstChild), dom_to_dict(minidom.parseString(xml_b).firstChild), message)
def get_header(self): return self._filter_response( dom_to_dict( self.response_doc.getElementsByTagNameNS( "*", "Header").item(0).firstChild))