From 18d58b82814e3a71dcd43fc2b3922beb4a49b5ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Garc=C3=ADa=20Crespo?= Date: Fri, 30 Apr 2021 20:31:40 +0200 Subject: [PATCH] Include DMDID attributes in normative structMap --- metsrw/__init__.py | 2 +- metsrw/fsentry.py | 3 +-- tests/test_normative_structmap.py | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/metsrw/__init__.py b/metsrw/__init__.py index c211607..225c63b 100644 --- a/metsrw/__init__.py +++ b/metsrw/__init__.py @@ -43,7 +43,7 @@ LOGGER = logging.getLogger(__name__) LOGGER.addHandler(logging.NullHandler()) -__version__ = "0.3.19" +__version__ = "0.3.20" __all__ = [ "Agent", diff --git a/metsrw/fsentry.py b/metsrw/fsentry.py index 31986dd..24e9814 100644 --- a/metsrw/fsentry.py +++ b/metsrw/fsentry.py @@ -471,8 +471,7 @@ def serialize_structmap(self, recurse=True, normative=False): if (not normative) and self.file_id(): etree.SubElement(el, utils.lxmlns("mets") + "fptr", FILEID=self.file_id()) if self.dmdids: - if (not normative) or (normative and self.is_empty_dir): - el.set("DMDID", " ".join(self.dmdids)) + el.set("DMDID", " ".join(self.dmdids)) if self.mets_div_type.lower() == "directory" and self.admids: el.set("ADMID", " ".join(self.admids)) if recurse and self._children: diff --git a/tests/test_normative_structmap.py b/tests/test_normative_structmap.py index 36da7bb..4854838 100644 --- a/tests/test_normative_structmap.py +++ b/tests/test_normative_structmap.py @@ -13,6 +13,8 @@ import metsrw from metsrw.plugins.premisrw import PREMISObject, PREMIS_3_0_NAMESPACES, lxmlns +from lxml import etree + class TestNormativeStructMap(TestCase): """Test normative logical structmap class.""" @@ -71,6 +73,7 @@ def test_write_normative_structmap(self): # Create the parent directory of the empty directory and give it a # simple PREMIS object also. f3 = metsrw.FSEntry("level3.txt", file_uuid=str(uuid.uuid4())) + f3.add_dmdsec(etree.Element("data"), "OTHER") d2 = metsrw.FSEntry("dir2", type="Directory", children=[f3, d_empty]) d2_id = str(uuid.uuid4()) d2_premis_object = PREMISObject(identifier_value=d2_id) @@ -157,3 +160,14 @@ def test_write_normative_structmap(self): "{}type".format(lxmlns("xsi", premis_version="3.0")) ) assert xsi_type == "premis:intellectualEntity" + + # Expect that the file in the normative logical structmap includes the + # DMDID attribute. + dmdid = normative_structmap_el.find(exists_in_both_path, metsrw.NAMESPACES).get( + "DMDID" + ) + assert dmdid.startswith("dmdSec_") + file_3_dmd_sec = doc.find( + 'mets:dmdSec[@ID="{}"]'.format(dmdid), metsrw.NAMESPACES + ) + assert file_3_dmd_sec is not None