Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion ocrd_models/ocrd_models/ocrd_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ def add_agent(self, *args, **kwargs):
el_metsHdr = ET.Element(TAG_METS_METSHDR)
self._tree.getroot().insert(0, el_metsHdr)
# assert(el_metsHdr is not None)
el_agent = ET.SubElement(el_metsHdr, TAG_METS_AGENT)
el_agent = ET.Element(TAG_METS_AGENT)
try:
el_agent_last = next(el_metsHdr.iterchildren(tag=TAG_METS_AGENT, reversed=True))
el_agent_last.addnext(el_agent)
except StopIteration:
el_metsHdr.insert(0, el_agent)
# print(ET.tostring(el_metsHdr))
return OcrdAgent(el_agent, *args, **kwargs)

Expand Down
34 changes: 34 additions & 0 deletions tests/data/mets-with-metsDocumentID.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<mets:mets xmlns:mets="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis-v2-0.xsd http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/mix/v10 http://www.loc.gov/standards/mix/mix10/mix10.xsd">
<mets:metsHdr CREATEDATE="2022-02-15T08:50:20.326804">
<mets:agent TYPE="OTHER" OTHERTYPE="SOFTWARE" ROLE="CREATOR">
<mets:name>ocrd/core v2.30.0</mets:name>
</mets:agent>
<mets:metsDocumentID TYPE="foo" ID="bar">foo/bar</mets:metsDocumentID>
</mets:metsHdr>
<mets:dmdSec ID="DMDLOG_0001">
<mets:mdWrap MDTYPE="MODS">
<mets:xmlData>
<mods:mods xmlns:mods="http://www.loc.gov/mods/v3">
<mods:identifier type="purl">mets-with-metsDocumentID</mods:identifier>
</mods:mods>
</mets:xmlData>
</mets:mdWrap>
</mets:dmdSec>
<mets:amdSec ID="AMD">
</mets:amdSec>
<mets:fileSec>
<mets:fileGrp USE="OCR-D-IMG">
<mets:file ID="OCR-D-IMG-mets" MIMETYPE="application/mets+xml">
<mets:FLocat LOCTYPE="OTHER" OTHERLOCTYPE="FILE" xlink:href="mets-with-metsDocumentID.xml"/>
</mets:file>
</mets:fileGrp>
</mets:fileSec>
<mets:structMap TYPE="PHYSICAL">
<mets:div TYPE="physSequence">
<mets:div TYPE="page" ID="P-mets">
<mets:fptr FILEID="OCR-D-IMG-mets"/>
</mets:div>
</mets:div>
</mets:structMap>
</mets:mets>
1 change: 0 additions & 1 deletion tests/model/test_ocrd_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ def test_agent(sbb_sample_01):
sbb_sample_01.add_agent('foo bar v0.0.1', 'OTHER', 'OTHER', 'YETOTHERSTILL')
assert len(sbb_sample_01.agents) == beforelen + 1


def test_metshdr():
"""
Test whether metsHdr is created on-demand
Expand Down
18 changes: 17 additions & 1 deletion tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from ocrd.resolver import Resolver
from ocrd.workspace import Workspace
from ocrd.workspace_backup import WorkspaceBackupManager

from ocrd_validators import WorkspaceValidator

TMP_FOLDER = '/tmp/test-core-workspace'
SRC_METS = assets.path_to('kant_aufklaerung_1784/data/mets.xml')
Expand Down Expand Up @@ -730,6 +730,22 @@ def test_merge_force(plain_workspace, tmp_path):
files = list(plain_workspace.find_files())
assert len(files) == 1

@pytest.fixture(name='workspace_metsDocumentID')
def _fixture_metsDocumentID(tmp_path):
resolver = Resolver()
mets_content = (Path(__file__).parent / "data/mets-with-metsDocumentID.xml").read_text()
with open(tmp_path / 'mets.xml', 'w', encoding='utf-8') as f:
f.write(mets_content)
yield Workspace(Resolver, directory=tmp_path)

def test_agent_before_metsDocumentID(workspace_metsDocumentID):
report = WorkspaceValidator.validate(Resolver(), mets_url=workspace_metsDocumentID.mets_target)
assert report.is_valid
workspace_metsDocumentID.mets.add_agent('foo bar v0.0.1', 'OTHER', 'OTHER', 'OTHER')
workspace_metsDocumentID.save_mets()
report = WorkspaceValidator.validate(Resolver(), mets_url=workspace_metsDocumentID.mets_target)
print(report.errors)
assert report.is_valid

if __name__ == '__main__':
main(__file__)