Skip to content

Commit

Permalink
Do not create amdSec when bag metadata is empty
Browse files Browse the repository at this point in the history
This prevents the creation and association of a amdSec element to the
objects directory in the structMap when the transfer bag metadata is
missing or unreadable.
  • Loading branch information
replaceafill authored Jan 9, 2025
1 parent ab974d5 commit 60fc2c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MCPClient/lib/clientScripts/create_mets_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,7 @@ def create_object_metadata(job, struct_map, baseDirectoryPath, state):
)
bag_info = [find_bag_metadata(job, path) for path in paths]

if not transfer and not source and not bag_info:
if not transfer and not source and not any(bag_info):
return

state.globalAmdSecCounter += 1
Expand Down
13 changes: 12 additions & 1 deletion tests/MCPClient/test_create_mets_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,15 +431,26 @@ def bag_path(sip_directory_path: pathlib.Path, sip: SIP) -> pathlib.Path:

@pytest.mark.django_db
@mock.patch("create_mets_v2.Bag")
@pytest.mark.parametrize(
"info",
[
{"Bagging-Date": "2025-01-08", "Payload-Oxum": "0.2"},
{},
],
ids=[
"populated",
"empty",
],
)
def test_bag_metadata_is_recorded_in_a_amdsec(
bag_class: mock.Mock,
info: dict[str, str],
mcp_job: Job,
sip_directory_path: pathlib.Path,
sip: SIP,
sip_file: File,
bag_path: pathlib.Path,
) -> None:
info = {"Bagging-Date": "2025-01-08", "Payload-Oxum": "0.2"}
bag_class.return_value = mock.Mock(info=info)
mets_path = sip_directory_path / f"METS.{sip.uuid}.xml"

Expand Down

0 comments on commit 60fc2c5

Please sign in to comment.