Пример #1
0
def test_structmap_file_type_exists():
    """Test to make sure the TYPE="FILE" attrib exists in the 
    structMap file-level divs, and that it only includes the
    filename up to the extension."""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    struct_maps = mets.findall('./{http://www.loc.gov/METS/}structMap')
    for struct_map in struct_maps:
        file_divs = struct_map.findall(
            './/{http://www.loc.gov/METS/}div[@TYPE="FILE"]')
        assert (len(file_divs) > 0)
    print(ET.tounicode(mets, pretty_print=True))
Пример #2
0
def test_structmap_has_table_of_contents_div_for_normal_factory():
    """Test to make sure the structumap has a second-layer div with the
    LABEL value of "Table of Contents"."""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        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")
Пример #3
0
def test_mets_dnx_deriv_copy_gets_preservationType():
    """Test basic construction of METS DNX, but assigning an access derivative
    (using the mm dir for efficiency's sake)"""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        access_derivative_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    print(ET.tounicode(mets, pretty_print=True))
    ad_pres_type = mets.findall(
        './{http://www.loc.gov/METS/}amdSec[@ID="rep2-amd"]'
        '/{http://www.loc.gov/METS/}techMD/{http://www.loc.gov/METS/}mdWrap/{http://www.loc.gov/METS/}xmlData'
        '/dnx/section[@id="generalRepCharacteristics"]/record/key[@id="preservationType"]'
    )[0]
    assert (ad_pres_type.text == "DERIVATIVE_COPY")
Пример #4
0
def test_digtial_original_dnx():
    """Test that the digitalOriginal value is being properly translated
    from a boolean input to a lower-case string of 'true' or 'false'"""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(ie_dmd_dict=ie_dc_dict,
                          pres_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'pm'),
                          modified_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'mm'),
                          input_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1'),
                          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')
Пример #5
0
def test_gfc_file_label_exists():
    """Test to make sure the label is added to the 
    generalFileCharacteristics sections, and that it onlye includes the
    filename up to the extension."""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    file_gen_chars_list = mets.findall(
        './/section[@id="generalFileCharacteristics"]')
    for el in file_gen_chars_list:
        fop = el.findall('./record/key[@id="label"]')
        assert (fop[0].text in ('presmaster', 'modifiedmaster'))
    print(ET.tounicode(mets, pretty_print=True))
Пример #6
0
def test_mets_dnx_with_cms():
    """Test basic construction of METS DNX, with CMS details"""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        cms=[{
            'recordId': '55515',
            'system': 'emu'
        }],
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    print(ET.tounicode(mets, pretty_print=True))
    cms_id = mets.findall(
        './/dnx/section[@id="CMS"]/record/key[@id="recordId"]')
    # print(cms_id[0].tag)
    # cms_id = mets.find('.//{http://www.exlibrisgroup.com/dps/dnx}section[@ID="CMS"]/{http://www.exlibrisgroup.com/dps/dnx}record/{http://www.exlibrisgroup.com/dps/dnx}key[@recordId]')
    assert (cms_id[0].text == '55515')
Пример #7
0
def test_mets_dnx():
    """Test basic construction of METS DNX"""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    print(ET.tounicode(mets, pretty_print=True))
Пример #8
0
def test_mets_dnx_with_for_single_rep():
    """
    """
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(ie_dmd_dict=ie_dc_dict,
                          pres_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'pm'),
                          input_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'pm'),
                          generalIECharacteristics=[{
                              'submissionReason':
                              'bornDigitalContent',
                              'IEEntityType':
                              'periodicIE'
                          }],
                          digital_original=True)
    digital_original_el = mets.xpath('.//key[@id="DigitalOriginal"]')[0]
    assert (digital_original_el.text == "true")
Пример #9
0
def test_mets_dnx_with_digital_original_details():
    """Test big fix where true/false value was being populated with uppercase
    inital letter, when translating True or False booleans to strings.
    """
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(ie_dmd_dict=ie_dc_dict,
                          pres_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'pm'),
                          modified_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'mm'),
                          input_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1'),
                          generalIECharacteristics=[{
                              'submissionReason':
                              'bornDigitalContent',
                              'IEEntityType':
                              'periodicIE'
                          }],
                          digital_original=True)
    digital_original_el = mets.xpath('.//key[@id="DigitalOriginal"]')[0]
    assert (digital_original_el.text == "true")
Пример #10
0
def test_file_original_path_exists():
    """Test to make sure the fileOriginalPath is added to the 
    generalFileCharacteristics sections"""
    ie_dc_dict = {"dc:title": "test title"}
    mets = mdf.build_mets(
        ie_dmd_dict=ie_dc_dict,
        pres_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'pm'),
        modified_master_dir=os.path.join(
            os.path.dirname(os.path.realpath(__file__)), 'data',
            'test_batch_1', 'mm'),
        input_dir=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'data', 'test_batch_1'),
        generalIECharacteristics=[{
            'submissionReason': 'bornDigitalContent',
            'IEEntityType': 'periodicIE'
        }],
    )
    file_gen_chars_list = mets.findall(
        './/section[@id="generalFileCharacteristics"]')
    for el in file_gen_chars_list:
        fop = el.findall('./record/key[@id="fileOriginalName"]')
        assert (fop[0].text in ('presmaster.jpg', 'modifiedmaster.jpg'))
Пример #11
0
def test_structmap_has_version_in_rep_id_for_multi_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_mets(ie_dmd_dict=ie_dc_dict,
                          pres_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'pm'),
                          modified_master_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1', 'mm'),
                          input_dir=os.path.join(
                              os.path.dirname(os.path.realpath(__file__)),
                              'data', 'test_batch_1'),
                          generalIECharacteristics=[{
                              'submissionReason':
                              'bornDigitalContent',
                              'IEEntityType':
                              'periodicIE'
                          }],
                          digital_original=True)
    structmap = mets.findall("{http://www.loc.gov/METS/}structMap")[0]
    # print(structmap.tag)
    assert (structmap.attrib["ID"][-2:] == "-1")