def testDCXMLNonRootElements(self): """Test for expected Dublin Core elements.""" generated_dxml = generate_dc_xml(UNTL_DICT) generated_dxml_root = objectify.fromstring(generated_dxml) constant_dxml_root = objectify.fromstring(DUBLIN_CORE_XML) results = [] # Check if each of the root's children from the generated XML # has a match in the string constant's XML. for child in generated_dxml_root.iterchildren(): # For each child, get all of the children with the same tag # from the XML being compared. same_tag_list = constant_dxml_root.findall(child.tag) element_found = False child_children = len(child.getchildren()) # Check if any of the possible elements are a match. for current in same_tag_list: if (current.text == child.text and current.tail == child.tail and current.attrib == child.attrib and len(current.getchildren()) == child_children): element_found = True break results.append(element_found) # If all elements came up with a match. Let it be True. self.assertTrue(all(results))
def testDCXMLRootElement(self): """Check the Dublin Core for expected attrib and nsmap on root.""" generated_dxml = generate_dc_xml(UNTL_DICT) # Verify root element has expected attribs, nsmap, and tag. generated_dxml_root = objectify.fromstring(generated_dxml) schema_location = ('http://www.openarchives.org/OAI/2.0/oai_dc/ ' 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd') expected_tag = '{http://www.openarchives.org/OAI/2.0/oai_dc/}dc' self.assertTrue(schema_location in generated_dxml_root.attrib.values()) self.assertEqual(generated_dxml_root.nsmap, DC_NAMESPACES) self.assertEqual(generated_dxml_root.tag, expected_tag)