def test_XML_Dict_Serializer_create_link_nodes(self): self.serializer = wsgi.XMLDictSerializer() xml_doc = minidom.Document() links = [{"rel": "rel", "href": "href", "type": "type"}] link_nodes = self.serializer._create_link_nodes(xml_doc, links) self.assertEqual('<atom:link href="href" rel="rel" type="type"/>', link_nodes[0].toxml())
def test_XML_Dict_Serializer_node_dict(self): self.serializer = wsgi.XMLDictSerializer() doc = minidom.Document() metadata = mock.Mock() metadata.get.return_value = { "node": { "item_name": "name", "item_key": "key" } } nodename = "node" data = {"data_key": "data_value"} result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual('<name key="data_key">data_value</name>', result.childNodes[0].toxml()) mock_get_nodename = mock.Mock() mock_get_nodename.get.return_vale = "k" metadata.get.return_value = {"k": "v"} nodename = "node" data = {"data_key": "data_value"} result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual("node", result.nodeName) metadata.get.return_value = {} nodename = "node" data = {"data_key": "data_value"} result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual('<data_key>data_value</data_key>', result.childNodes[0].toxml())
def __call__(self, req): if req.content_type == 'application/xml': serializer = wsgi.XMLDictSerializer() else: serializer = wsgi.JSONDictSerializer() resp = webob.Response(request=req) default_webob_exc = webob.exc.HTTPInternalServerError() resp.status_code = self.error.get('code', default_webob_exc.code) serializer.default(resp, self.error) return resp
def test_add_xmlns(self): xml_dict_serializer = wsgi.XMLDictSerializer() xml_dict_serializer.xmlns = mock.sentinel.xmlns mock_node = mock.Mock() xml_dict_serializer._add_xmlns(mock_node, has_atom=False) mock_node.setAttribute.assert_called_once_with('xmlns', mock.sentinel.xmlns) mock_node.reset_mock() xml_dict_serializer._add_xmlns(mock_node, has_atom=True) mock_node.setAttribute.assert_has_calls([ mock.call('xmlns', mock.sentinel.xmlns), mock.call('xmlns:atom', "http://www.w3.org/2005/Atom") ])
def test_XML_Dict_Serializer_node_list(self): self.serializer = wsgi.XMLDictSerializer() doc = minidom.Document() metadata = mock.Mock() metadata.get.return_value = {"node": {"item_name": "name", "item_key": "key"}} nodename = "node" data = ["data_1", "data_2", "data_3"] result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual('<name key="data_1"/>', result.childNodes[0].toxml()) nodename = "not_node" data = ["data_1", "data_2", "data_3"] result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual(3, len(result.childNodes)) nodename = "nodes" data = ["data_1", "data_2", "data_3"] result = self.serializer._to_xml_node(doc, metadata, nodename, data) self.assertEqual(3, len(result.childNodes))
def test_XML_Dict_Serializer_default_string(self): self.serializer = wsgi.XMLDictSerializer() actual_xml = self.serializer.default({"XML Root": "some data"}) expected_xml = b'<XML Root>some data</XML Root>\n' self.assertEqual(expected_xml, actual_xml)