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 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.encode('utf-8')) 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)
def test_generate_dc_xml(): xml = untldoc.generate_dc_xml(DC_DICTIONARY) expected_xml = ( '<?xml version="1.0" encoding="UTF-8"?>\n' '<oai_dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/"' ' xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"' ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' ' xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/' ' http://www.openarchives.org/OAI/2.0/oai_dc.xsd">\n' ' <dc:title>Tres Actos</dc:title>\n' ' <dc:creator>Enhorn, Blair</dc:creator>\n' ' <dc:publisher>Fake Publishing</dc:publisher>\n' ' <dc:date>1944</dc:date>\n' '</oai_dc:dc>\n') xml_lines = xml.decode().split('\n') expected_xml_lines = expected_xml.split('\n') # All but the second XML line should be in a specific order, so sort the # text of the second line to check equality. xml_lines[1] = sorted(xml_lines[1].split()) expected_xml_lines[1] = sorted(expected_xml_lines[1].split()) assert xml_lines == expected_xml_lines