def test_recordstatus(schematron_fx): """Test that RECORDSTATUS can always be 'submission', and also 'update' and 'dissemination' for CSC. """ (mets, root) = parse_xml_file('mets_valid_complete.xml') hdr = find_element(root, 'metsHdr', 'mets') set_attribute(hdr, 'RECORDSTATUS', 'mets', 'update') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 set_attribute(hdr, 'RECORDSTATUS', 'mets', 'dissemination') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 agent = find_element(hdr, 'name', 'mets') agent.text = 'CSC - IT Center for Science Ltd.' set_attribute(hdr, 'RECORDSTATUS', 'mets', 'submission') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 set_attribute(hdr, 'RECORDSTATUS', 'mets', 'update') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 set_attribute(hdr, 'RECORDSTATUS', 'mets', 'dissemination') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0
def test_deprecated_value(schematron_fx): """In 'usage' element, value 'primary display' was deprecated in MODS 3.4 and 'primary' was given instead. :schematron_fx: Schematron compile fixture """ (mods, elem_context, elem_version) = prepare_xml('url', '3.4') # Success without 'usage' svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 0 # Warning with 'primary display' set_attribute(elem_context, 'usage', 'mods', 'primary display') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 1 # No warning with old version 3.3 set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '3.3') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 0 # No warning with MODS 3.4, when using 'primary' set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '3.4') set_attribute(elem_context, 'usage', 'mods', 'primary') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 0 # New value 'primary' is an error with MODS 3.3 set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '3.3') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 1
def test_addml_reference_version(schematron_fx): """Test element 'reference' with ADDML versions 8.2 and 8.3. It is required only in 8.2. :schematron_fx: Schematron compile fixture """ xml = METS_HEAD+'''<addml:addml><addml:dataset/></addml:addml>'''+METS_TAIL # Element 'reference' is required in 8.2, but missing (mets, root) = parse_xml_string(xml) (mets, root) = add_containers(root, 'mets:mets/mets:amdSec') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FIRED) == 1 assert svrl.count(SVRL_FAILED) == 1 # Element 'reference' is required in 8.2, and it exists elem_handler = find_element(root, 'dataset', 'addml') set_element(elem_handler, 'reference', 'addml') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # No checks with version 8.3 elem_handler = find_element(root, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', '8.3') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets, params=False) assert svrl.count(SVRL_FIRED) == 0 assert svrl.count(SVRL_FAILED) == 0
def test_disallowed_hierarch_attrib( schematron_fx, container, context, disallowed_attribute, version): """Various attributes have been added to newer MODS versions. Test the checks that disallow the use of new element/attribute in an old MODS version. Here the context element require container, since MODS has other irrelevant context elements with the same name outside the container. :schematron_fx: Schematron compile fixture :container: Element, where the context exists :context: Context element, which may contain new attribute. :disallowed_attribute: The new attribute :version: Earliest MODS version where the attribute applies """ (mods, elem_context, elem_version) = prepare_xml(container, version) elem_context = set_element(elem_context, context, 'mods') set_attribute(elem_context, disallowed_attribute, 'mods', 'default') # Success with given version svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 0 # Error with earlier versions set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '%.1f' % (float(version)-0.1)) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 1 # Success again, if attribute removed elem_context.clear() svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 0
def test_addml_headerlevel_version(schematron_fx): """Test element 'headerLevel' with ADDML versions 8.2 and 8.3. It is a new element in 8.3 (forbidden in 8.2). :schematron_fx: Schematron compile fixture """ xml = '''<addml:addml><addml:dataset><addml:reference/><addml:flatFiles> <addml:flatFileDefinitions><addml:flatFileDefinition> <addml:recordDefinitions><addml:recordDefinition> <addml:headerLevel/> </addml:recordDefinition></addml:recordDefinitions> </addml:flatFileDefinition></addml:flatFileDefinitions> </addml:flatFiles></addml:dataset></addml:addml>''' \ % NAMESPACES (mets, root) = parse_xml_string(METS_HEAD+xml+METS_TAIL) (mets, root) = add_containers(root, 'mets:mets/mets:amdSec') # Element 'headerLevel' is forbidden in 8.2 svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets, params=False) assert svrl.count(SVRL_FIRED) == 2 assert svrl.count(SVRL_FAILED) == 1 # No checks with version 8.3 elem_handler = find_element(root, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', '8.3') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets, params=False) assert svrl.count(SVRL_FIRED) == 0 assert svrl.count(SVRL_FAILED) == 0
def test_value_items_root(schematron_fx, attribute, nspace, fixed): """Test that a value is required in a certain attributes. :schematron_fx: Schematron compile fixture :attribute: Attribute, where the value is required :nspace: Namespace key of the attribute :fixed: Boolean, if the required value is fixed """ (mets, root) = parse_xml_file('mets_valid_complete.xml') if nspace == 'fi': fix_version_17(root) # Use arbitrary value elem_handler = find_element(root, 'mets', 'mets') set_attribute(elem_handler, attribute, nspace, 'aaa') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) if fixed: assert svrl.count(SVRL_FAILED) == 1 else: assert svrl.count(SVRL_FAILED) == 0 # Use empty value set_attribute(elem_handler, attribute, nspace, '') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_disallowed_attribute_premis_rightsmd(schematron_fx): """Test that attributes 'authority', 'authorityURI', 'valueURI' in PREMIS 2.3 are disallowed in PREMIS 2.2. :schematron_fx: Schematron compile fixture """ xml = '''<mets:rightsMD xmlns:mets="%(mets)s" xmlns:premis="%(premis)s"> <mets:mdWrap MDTYPE="PREMIS:RIGHTS" MDTYPEVERSION="2.3"> <mets:xmlData><premis:rights><premis:rightsStatement/> </premis:rights></mets:xmlData></mets:mdWrap> </mets:rightsMD>''' % NAMESPACES (mets, root) = parse_xml_string(xml) (mets, root) = add_containers(root, 'mets:mets/mets:amdSec') elem_handler = find_element(root, 'rightsStatement', 'premis') elem_handler = set_element(elem_handler, 'xxx', 'premis') for disallowed in ['authority', 'authorityURI', 'valueURI']: set_attribute(elem_handler, disallowed, 'premis', 'default') # Works in 2.3 svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # Disallowed in 2.2 elem_wrap = find_element(root, 'mdWrap', 'mets') set_attribute(elem_wrap, 'MDTYPEVERSION', 'mets', '2.2') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 3 # 2.2 works, if attributes removed elem_handler.clear() svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0
def test_fileid(schematron_fx): """Test that FILEID is allowed in fptr or area, but disallowed, if missing. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # FILEID in fptr and area elem_handler = find_element(root, 'fptr', 'mets') elem_handler_area = set_element(elem_handler, 'area', 'mets') set_attribute(elem_handler_area, 'FILEID', 'mets', get_attribute(elem_handler, 'FILEID', 'mets')) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # FILEID only in area del_attribute(elem_handler, 'FILEID', 'mets') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # Also area missing del_element(elem_handler, 'area', 'mets') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_mdtype_items_rightsmd(schematron_fx): """Test that all valid metadata types and their versions work properly. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') elem_handler = find_element(root, 'rightsMD', 'mets') elem_handler = find_element(elem_handler, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPE', 'mets', 'PREMIS:RIGHTS') # Test that all MDTYPEVERSIONs work with all specifications for specversion in [ '1.5.0', '1.6.0', '1.7.0', '1.7.1', '1.7.2', '1.7.3', '1.7.4' ]: if specversion in ['1.7.0', '1.7.1', '1.7.3', '1.7.4']: fix_version_17(root) else: set_attribute(root, 'CATALOG', 'fikdk', specversion) set_attribute(root, 'SPECIFICATION', 'fikdk', specversion) for version in ['2.3', '2.2']: set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', version) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # Test unknown version fix_version_17(root) set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', 'xxx') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_objid_unique(schematron_fx): """Check that error is given, if OBJID is not unique with METS IDs, except for CONTENTID that can be identical to OBJID. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') objid = get_attribute(root, 'OBJID', 'mets') contentid = get_attribute(root, 'CONTENTID', 'fikdk') set_attribute(root, 'CONTENTID', 'fikdk', objid) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 set_attribute(root, 'CONTENTID', 'fikdk', contentid) elem_handler = find_element(root, 'dmdSec', 'mets') section_id = get_attribute(elem_handler, 'ID', 'mets') set_attribute(root, 'OBJID', 'mets', section_id) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 set_attribute(root, 'OBJID', 'mets', objid) fix_version_17(root) set_attribute(root, 'CONTRACTID', 'fi', objid) svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_identifier_value_premis_event_agent(schematron_fx, premisroot, mdtype, nonempty): """PREMIS identifier elements can not be empty. Test that a value in the element is required. :schematron_fx: Schematron compile fixture :premisroot: PREMIS root element name :mdtype: MDTYPE :nonempty: element that requires a value """ xml = '''<mets:digiprovMD xmlns:mets="%(mets)s"> <mets:mdWrap MDTYPEVERSION="2.3"><mets:xmlData/></mets:mdWrap> </mets:digiprovMD>''' % NAMESPACES (mets, root) = parse_xml_string(xml) (mets, root) = add_containers(root, 'mets:mets/mets:amdSec') elem_handler = find_element(root, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPE', 'mets', mdtype) elem_handler = find_element(elem_handler, 'xmlData', 'mets') for elem in premisroot: elem_handler = set_element(elem_handler, elem, 'premis') elem_handler = set_element(elem_handler, nonempty, 'premis') # Empty identifier element fails svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 # Arbitrary value added elem_handler.text = 'xxx' svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0
def test_version(schematron_fx): """Test the case that MODS version differs from @MDTYPEVERSION. """ (mods, elem_context, elem_version) = prepare_xml(None, '3.7') set_attribute(elem_context, 'version', 'mods', '3.7') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 0 set_attribute(elem_context, 'version', 'mods', '3.6') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 1
def test_missing_links_dmdsec(schematron_fx): """Test the case where linking missing from ADMID, DMDID and FILEID to corresponding METS sections. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') elem_handler = find_element(root, 'div', 'mets') refs = get_attribute(elem_handler, 'DMDID', 'mets').split() set_attribute(elem_handler, 'DMDID', 'mets', '') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == len(refs)
def test_missing_ids_structmap(schematron_fx, context): """Test the case where sections are missing for ADMID, DMDID and FILEID links. :schematron_fx: Schematron compile fixture :context: Section to be removed. """ (mets, root) = parse_xml_file('mets_valid_complete.xml') elem_handler = find_element(root, context, 'mets') # We actually just remove the id set_attribute(elem_handler, 'ID', 'mets', '') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_arbitrary_attributes_structmap(schematron_fx, context): """Test that arbitrary attributes are forbidden in METS anyAttribute sections. """ (mets, root) = parse_xml_file('mets_valid_complete.xml') elem_handler = find_element(root, context, 'mets') for spec in [None, '1.7.0']: if spec == '1.7.0': fix_version_17(root) for ns in ['fi', 'fikdk', 'dc']: set_attribute(elem_handler, 'xxx', ns, 'xxx') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 del_attribute(elem_handler, 'xxx', ns)
def test_mdtype_items_mdwrap(schematron_fx, context, mdtype, othermdtype, mdtypeversion): """Test that all valid metadata types and their versions work properly. :schematron_fx: Schematron compile fixture :context: METS section to be tested :mdtype: MDTYPE attribute value :othermdtype: OTHERMDTYPE attribute valur :mdtypeversion: MDTYPEVERSION attribute value """ (mets, root) = parse_xml_file('mets_valid_complete.xml') fix_version_17(root) elem_handler = find_element(root, context, 'mets') elem_handler = find_element(elem_handler, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPE', 'mets', mdtype) if othermdtype is not None: set_attribute(elem_handler, 'OTHERMDTYPE', 'mets', othermdtype) # Test that unknown OTHERMDTYPE gives error, if MDTYPE is not 'OTHER' set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', mdtypeversion[0]) set_attribute(elem_handler, 'OTHERMDTYPE', 'mets', 'xxx') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) if mdtype == 'OTHER': assert svrl.count(SVRL_FAILED) == 0 else: assert svrl.count(SVRL_FAILED) == 1
def test_othermdtype(schematron_fx, context): """Test that OTHERMDTYPE and the version are mandatory, but can be anything in all METS sections, if MDTYPE is OTHER. :schematron_fx: Schematron compile fixture :context: METS section to be tested """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # OTHERMDTYPE and version can be anything elem_handler = find_element(root, context, 'mets') elem_handler = find_element(elem_handler, 'mdWrap', 'mets') set_attribute(elem_handler, 'MDTYPE', 'mets', 'OTHER') set_attribute(elem_handler, 'OTHERMDTYPE', 'mets', 'xxx') set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', 'xxx') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # Version is mandatory del_attribute(elem_handler, 'MDTYPEVERSION', 'mets') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 # OTHERMDTYPE is missing del_attribute(elem_handler, 'OTHERMDTYPE', 'mets') set_attribute(elem_handler, 'MDTYPEVERSION', 'mets', 'xxx') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 2
def test_native_stream(schematron_fx): """ Test a case where a video container listed in specifications contains an unsupported stream, and fi-dpres-no-file-format-validation is marked. In this case, streams are not required in METS. """ (mets, root) = parse_xml_file("mets_video_container.xml") svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) elem_handler = find_element(root, "file", "mets") set_attribute(elem_handler, "USE", "mets", "fi-dpres-no-file-format-validation") del_element(elem_handler, "stream", "mets") del_element(elem_handler, "stream", "mets") svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0
def test_contractid_format(catalog_fx): """Test that contractid allows only correctly formatted UUID """ (mets, root) = prepare_xml_for_tests() fix_version_17(root) (returncode, _, _) = catalog_fx(xmltree=mets) assert returncode == 0 set_attribute(root, 'CONTRACTID', 'fi', 'c5a193b3-bb63-4348-bd25-6c20bb72264b') (returncode, _, _) = catalog_fx(xmltree=mets) assert returncode == 3 set_attribute(root, 'CONTRACTID', 'fi', 'urn:uuid:xxx') (returncode, _, _) = catalog_fx(xmltree=mets) assert returncode == 3
def test_value_items_metshdr(schematron_fx): """Test that a value is required in a certain attributes. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # Use arbitrary value elem_handler = find_element(root, 'metsHdr', 'mets') set_attribute(elem_handler, 'RECORDSTATUS', 'mets', 'aaa') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 # Use empty value set_attribute(elem_handler, 'RECORDSTATUS', 'mets', '') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_disallowed_items_structmap(schematron_fx, disallowed, context): """Test if use of disallowed atrtibute or element causes error. :schematron_fx: Schematron compile fixture :disallowed: Disallowed element or attribute, use '@' for attributes. :context: Context element, where the attribute or element exists """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # Set disallowed attribute/element elem_handler = find_element(root, context, 'mets') if disallowed[0] == '@': set_attribute(elem_handler, disallowed[1:], 'mets', 'default') else: set_element(elem_handler, disallowed, 'mets') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def prepare_xml(context_element, version): """The EAD3 metadata is prepared here for all the tests below. :context_element: Context element, where the test is done :version: EAD3 version to be used. """ xml = '''<mets:dmdSec xmlns:mets="%(mets)s" xmlns:ead3="%(ead3)s"> <mets:mdWrap MDTYPE="EAD3" MDTYPEVERSION="1.1.0"> <mets:xmlData><ead3:ead/></mets:xmlData></mets:mdWrap> </mets:dmdSec>''' % NAMESPACES (ead3, root) = parse_xml_string(xml) (ead3, root) = add_containers(root, 'mets:mets') elem_handler = find_element(root, 'ead', 'ead3') if context_element is not None: elem_context = set_element(elem_handler, context_element, 'ead3') elem_version = find_element(root, 'mdWrap', 'mets') set_attribute(elem_version, 'MDTYPEVERSION', 'mets', version) return (ead3, elem_context, elem_version)
def test_section_schemas(catalog_fx, rootelement, namespace, section): """Test that section schemas in the catalog work in validation. :catalog_fx: Schema catalog validation fixture :rootelement: Root element of the section metadata :namespace: Namespace of the section metadata :section: METS metadata section """ (mets, root) = prepare_xml_for_tests() elem_handler = find_element(root, section, 'mets') elem_handler = find_element(elem_handler, 'xmlData', 'mets') elem_handler.clear() elem_handler = set_element(elem_handler, rootelement, namespace) if rootelement == 'object': set_attribute(elem_handler, 'type', 'xsi', 'premis:file') set_element(elem_handler, 'xxx', namespace) (returncode, _, stderr) = catalog_fx(xmltree=mets) assert returncode == 3 assert b'xxx' in stderr
def test_value_items_structmap(schematron_fx, attribute, nspace): """Test that a value is required in a certain attributes. :schematron_fx: Schematron compile fixture :attribute: Attribute, where the value is required :nspace: Namespace key of the attribute """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # Use arbitrary value elem_handler = find_element(root, 'mptr', 'mets') set_attribute(elem_handler, attribute, nspace, 'aaa') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 # Use empty value set_attribute(elem_handler, attribute, nspace, '') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_digiprov_object(schematron_fx): """PREMIS:OBJECT is allowed in digiprovMD, if it's type is representation. :schematron_fx: Schematron compile fixture """ xml = '''<mets:mets fi:CATALOG="1.6.0" xmlns:mets="%(mets)s" xmlns:premis="%(premis)s" xmlns:xsi="%(xsi)s" xmlns:fi="%(fikdk)s" xmlns:dc="%(dc)s"> <mets:dmdSec> <mets:mdWrap MDTYPE='DC' MDTYPEVERSION="1.1"> <mets:xmlData><dc:subject/></mets:xmlData></mets:mdWrap> </mets:dmdSec><mets:amdSec> <mets:techMD> <mets:mdWrap MDTYPE='PREMIS:OBJECT' MDTYPEVERSION="2.3"> <mets:xmlData> <premis:object/></mets:xmlData></mets:mdWrap></mets:techMD> <mets:digiprovMD> <mets:mdWrap MDTYPE='PREMIS:OBJECT' MDTYPEVERSION="2.3"> <mets:xmlData> <premis:object xsi:type='premis:representation'/> </mets:xmlData></mets:mdWrap></mets:digiprovMD> <mets:digiprovMD> <mets:mdWrap MDTYPE='PREMIS:EVENT' MDTYPEVERSION="2.3"> <mets:xmlData><premis:event/></mets:xmlData></mets:mdWrap> </mets:digiprovMD></mets:amdSec></mets:mets>''' % NAMESPACES ET.register_namespace('premis', NAMESPACES['premis']) (mets, root) = parse_xml_string(xml) # Works with premis:representation svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 # Fails with other values elem_handler = find_element(root, 'digiprovMD', 'mets') elem_handler = find_element(elem_handler, 'object', 'premis') set_attribute(elem_handler, 'type', 'xsi', 'premis:file') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 set_attribute(elem_handler, 'type', 'xsi', 'premis:bitstream') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1
def test_ead3_extension(schematron_fx, xml, failures): """Test the rule which checks the content of the <objectxmlwrap> element in EAD3. It may contain any elements, but only outside EAD3 namespace. :schematron_fx: Schematron compile fixture :xml: XML to be validated :failures: Number of Schematron failures to expect """ (xmltree, root) = parse_xml_string(xml) (xmltree, mets_root) = add_containers( root, 'mets:mets/mets:dmdSec/mets:mdWrap/mets:xmlData/ead3:ead') mdwrap = find_element(mets_root, 'mdWrap', 'mets') set_attribute(mdwrap, 'MDTYPEVERSION', 'mets', '1.0.0') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=xmltree, params=False) assert svrl.count(SVRL_FIRED) == 1 assert svrl.count(SVRL_FAILED) == failures set_attribute(mdwrap, 'MDTYPEVERSION', 'mets', '1.1.0') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=xmltree, params=False) assert svrl.count(SVRL_FIRED) == 0
def test_catalogs(schematron_fx): """Test the Schema catalog version numbering in METS. :schematron_fx: Schematron compile fixture """ (mets, root) = parse_xml_file('mets_valid_complete.xml') # Conflict between fi:CATALOG and fi:SPECIFICATION set_attribute(root, 'CATALOG', 'fikdk', '1.5.0') del_attribute(root, 'CONTENTID', 'fikdk') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 1 assert svrl.count(SVRL_REPORT) == 1 # Deprecated specification set_attribute(root, 'SPECIFICATION', 'fikdk', '1.5.0') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mets) assert svrl.count(SVRL_FAILED) == 0 assert svrl.count(SVRL_REPORT) == 1
def prepare_xml(context_element, version): """The MODS metadata is prepared here for all the tests below. :context_element: Context element, where the test is done :version: MODS version to be used. """ xml = '''<mets:dmdSec xmlns:mets="%(mets)s" xmlns:mods="%(mods)s"> <mets:mdWrap MDTYPE="MODS" MDTYPEVERSION="3.7"> <mets:xmlData><mods:mods/></mets:xmlData></mets:mdWrap> </mets:dmdSec>''' % NAMESPACES (mods, root) = parse_xml_string(xml) (mods, root) = add_containers(root, 'mets:mets') elem_handler = find_element(root, 'mods', 'mods') if context_element is not None: elem_context = set_element(elem_handler, context_element, 'mods') else: elem_context = elem_handler elem_version = find_element(root, 'mdWrap', 'mets') set_attribute(elem_version, 'MDTYPEVERSION', 'mets', version) return (mods, elem_context, elem_version)
def test_deprecated_element(schematron_fx): """Element 'province' was deprecated in MODS 3.6 :schematron_fx: Schematron compile fixture """ (mods, elem_context, elem_version) = prepare_xml( 'hierarchicalGeographic', '3.6') # Success without 'province' svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 0 set_element(elem_context, 'province', 'mods') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) # Warning, if 'province' exists assert svrl.count(SVRL_REPORT) == 1 # Success when version changed to 3.5 set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '3.5') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_REPORT) == 0
def test_removed_element(schematron_fx): """Element 'extraterrestrialArea' was removed in MODS 3.6 :schematron_fx: Schematron compile fixture """ (mods, elem_context, elem_version) = prepare_xml('hierarchicalGeographic', '3.6') # Success without 'extraterrestrialArea' svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 0 # Error, if 'extraterrestrialArea' exists set_element(elem_context, 'extraterrestrialArea', 'mods') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 1 # Success when version changed to 3.5 set_attribute(elem_version, 'MDTYPEVERSION', 'mets', '3.5') svrl = schematron_fx(schematronfile=SCHFILE, xmltree=mods) assert svrl.count(SVRL_FAILED) == 0