def test_xml_parsing(): test_xml = """ <xml> <order> <product>rails training</product> <description>rest training</description> <price>512.45</price> <links> <link href="http://www.caelum.com.br/orders/1" rel="self"/> <link href="http://www.caelum.com.br/orders/1/payment" rel="payment"/> </links> </order> </xml> """ e = ElementTree.fromstring(test_xml) order = XMLResource(e) links = order.links() assert len(order.order) == 4 assert order.order.product == 'rails training' assert links.self.rel == "self" assert links.self.href == "http://www.caelum.com.br/orders/1" assert links.payment.rel == "payment" assert links.payment.href == "http://www.caelum.com.br/orders/1/payment"
def test_xml_without_links(): test_xml = """ <xml> <order> <product>rails training</product> <description>rest training</description> <price>512.45</price> </order> </xml> """ e = ElementTree.fromstring(test_xml) order = XMLResource(e) links = order.links() assert len(links) == 0