Exemplo n.º 1
0
def test_ambiguous_mets_file_is_error(tmpdir):
    for i in range(3):
        touch(tmpdir / "metadata" / ("METS.%d.xml" % i))

    with pytest.raises(
        Exception, match="Multiple METS files found in %s/metadata" % tmpdir
    ):
        find_mets_file(str(tmpdir))
def parse_reingest_mets(job, transfer_uuid, transfer_path):
    # Parse METS to extract information needed by later microservices
    mets_path = find_mets_file(transfer_path)
    try:
        root = etree.parse(mets_path)
    except Exception:
        job.pyprint("Error parsing reingest METS", mets_path, " - skipping")
        logger.info("Error parsing reingest mets %s - skipping",
                    mets_path,
                    exc_info=True)
        return

    # Get SIP UUID from METS name
    sip_uuid = os.path.basename(mets_path).replace("METS.",
                                                   "").replace(".xml", "")
    # Note: Because DublinCore and PREMIS rights are not database-level foreign keys, this works even though the SIP may not exist yet
    parse_mets_to_db.parse_dc(job, sip_uuid, root)
    parse_mets_to_db.parse_rights(job, sip_uuid, root)
Exemplo n.º 3
0
def test_no_mets_file_is_error(tmpdir):
    with pytest.raises(Exception, match="No METS file found in %s/metadata" % tmpdir):
        find_mets_file(str(tmpdir))
Exemplo n.º 4
0
def test_finds_matching_mets_file(tmpdir):
    touch(tmpdir / "metadata" / "METS.1.xml")
    assert find_mets_file(str(tmpdir)) == str(tmpdir / "metadata" / "METS.1.xml")