def get_object_from_xml(xml): paths_xml = xml.findall(PathXmlParser.PATH_TAG) paths = [] for path_xml in paths_xml: points = PointXmlParser.get_object_from_xml(path_xml) paths.append(points) return paths
def test_get_object_from_xml(self): locations = [ Location(30.5, 40.5), Location(50.5, 60.5), Location(70.5, 80.5) ] xml = """<path> <point lat="%s" lon="%s"/> <point lat="%s" lon="%s"/> <point lat="%s" lon="%s"/> </path>""" % ( locations[0].latitude, locations[0].longitude, locations[1].latitude, locations[1].longitude, locations[2].latitude, locations[2].longitude ) root_xml = xmlLib.fromstring(xml) parsed_locations = PointXmlParser.get_object_from_xml(root_xml) self.assertEqual(len(parsed_locations), 3) self.assertEqual(parsed_locations[0], locations[0]) self.assertEqual(parsed_locations[1], locations[1]) self.assertEqual(parsed_locations[2], locations[2])