def should_unmarshal(self): converter = XmlConverter() result = converter.unmarshal('<html><img><link href="http://google.com" rel="alternative" type="application/xml">A Link</link><link href="http://yahoo.com" rel="self" type="application/xml" /></img></html>') assert result.tag == 'html' assert result.img.tag == 'img' assert result.img.link[0].text == 'A Link' assert len(result.img.link) == 2 assert len(result.links().links) == 2
def should_unmarshal(self): converter = XmlConverter() result = converter.unmarshal( '<html><img><link href="http://google.com" rel="alternative" type="application/xml">A Link</link><link href="http://yahoo.com" rel="self" type="application/xml" /></img></html>' ) assert result.tag == 'html' assert result.img.tag == 'img' assert result.img.link[0].text == 'A Link' assert len(result.img.link) == 2 assert len(result.links().links) == 2
def should_unmarshal(self): xml = XmlConverter() result = xml.unmarshal('<html><div><link href="http://google.com" ' + 'rel="alternative" type="application/xml">' + 'A Link</link><link href="http://yahoo.com" ' + 'rel="self" type="application/xml" /></div>' + '<div>Hello World</div>' + '</html>') assert result.tag == 'html' assert len(result.div) == 2 assert result.div[0].tag == 'div' assert result.div[0].link[0].text == 'A Link' assert len(result.div[0].link) == 2 assert len(result.links()) == 2
def should_marshal(self): converter = XmlConverter() d = {'html': {'img': ''}} result = converter.marshal(d) assert result == '<html><img /></html>'
def test_should_discover_a_marshaller_for_a_type(self): assert Converters.marshaller_for( "application/atom").__class__ == XmlConverter().__class__ converter = PlainConverter() Converters.register("text/plain", converter) assert Converters.marshaller_for("text/plain") == converter