def test_labels_in_mets_dnx_single_file(): """Test that labels are added to generalFileCharactierists secion and structMap, and that they are populated with the filenames (sans extensions)""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) gfc = mets.findall( './/section[@id="generalFileCharacteristics"]/record')[0] # since we're doing this, let's also test the FileOriginalName key file_original_name = gfc.findall('./key[@id="fileOriginalName"]')[0] assert (file_original_name.text == 'presmaster.jpg') label = gfc.findall('./key[@id="label"]')[0] assert (label.text == 'presmaster') struct_map = mets.findall('./{http://www.loc.gov/METS/}structMap')[0] file_div = struct_map.findall( './/{http://www.loc.gov/METS/}div[@TYPE="FILE"]')[0] assert (file_div.attrib['LABEL'] == 'presmaster')
def test_mets_dnx_single_file(): """Test basic construction of METS DNX for single file""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) print(ET.tounicode(mets, pretty_print=True))
def test_structmap_has_version_in_rep_id_for_single_file_sip(): """test to confirm that a rep's physical structmap has the "-1" at the end of it""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) # print(ET.tounicode(mets, pretty_print=True)) structmap = mets.findall("{http://www.loc.gov/METS/}structMap")[0] # print(structmap.tag) assert (structmap.attrib["ID"][-2:] == "-1")
def test_all_amdsec_subsections_have_dnx_element(): """Make sure that all amdsec have at least a DNX stub element""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) # print(ET.tounicode(mets, pretty_print=True)) amd_sections = mets.findall("{http://www.loc.gov/METS/}amdSec") for section in amd_sections: for tag in ('techMD', 'rightsMD', 'sourceMD', 'digiprovMD'): subsection = section.find("{http://www.loc.gov/METS/}%s" % tag) dnx = subsection.find(".//dnx") assert (dnx != None)
def test_filesec_has_use_attrib_for_single_file_sip(): """test to confirm that a filesec has the USE="VIEW" attribute""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, cms=[{ 'recordId': '55515', 'system': 'emu' }], filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) filegrp = mets.findall(".//{http://www.loc.gov/METS/}fileGrp")[0] assert (filegrp.attrib["USE"] == "VIEW")
def test_structmap_has_table_of_contents_div_for_single_file_mets(): """Test to make sure the structMap has a second-layer div with the LABEL value of "Table of Contents" for single_file METS.""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) struct_maps = mets.findall('./{http://www.loc.gov/METS/}structMap') for struct_map in struct_maps: second_div = struct_map.find( "./{http://www.loc.gov/METS/}div/{http://www.loc.gov/METS/}div") print(second_div.attrib["LABEL"]) assert (second_div.attrib["LABEL"] == "Table of Contents")
def test_digtial_original_dnx_single_file(): """Test that the digitalOriginal value is being properly translated from a boolean input to a lower-case string of 'true' or 'false' for a single-file METS""" ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], digital_original=True) grc = mets.findall('.//section[@id="generalRepCharacteristics"]')[0] # print(ET.tounicode(grc[0], pretty_print=True)) do = grc.findall('.//key[@id="DigitalOriginal"]')[0] assert (do.text == 'true') # for grc in general_rep_characteristics: # assert(grc.text == 'true') print(ET.tounicode(mets, pretty_print=True))
def test_structmap_for_single_file_mets_has_upper_case_type(): ie_dc_dict = {"dc:title": "test title"} mets = mdf.build_single_file_mets( ie_dmd_dict=ie_dc_dict, cms=[{ 'recordId': '55515', 'system': 'emu' }], filepath=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data', 'test_batch_1', 'pm', 'presmaster.jpg'), generalIECharacteristics=[{ 'submissionReason': 'bornDigitalContent', 'IEEntityType': 'periodicIE' }], ) structmap = mets.findall(".//{http://www.loc.gov/METS/}structMap")[0] # filegrp = mets.findall(".//{http://www.loc.gov/METS/}fileGrp")[0] # assert(filegrp.attrib["USE"] == "VIEW") assert (structmap.attrib["TYPE"] == "PHYSICAL") print(structmap.attrib["TYPE"]) assert (structmap.attrib["TYPE"] != "Physical")