From bce766ee7f08ca4d992470fd674b220060d52d46 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Thu, 23 Apr 2020 17:35:14 -0500 Subject: [PATCH] Resolve #44 - `manifest_url` for SIP labels - Test case to expose the issue - New constant for SIP manifest locations - Slight PEP-8 cosmetic fix (spaces around `+`) --- src/pds/aipgen/constants.py | 3 +++ src/pds/aipgen/sip.py | 6 +++--- src/pds/aipgen/tests/test_functional.py | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/pds/aipgen/constants.py b/src/pds/aipgen/constants.py index df33a14..34fcfbc 100644 --- a/src/pds/aipgen/constants.py +++ b/src/pds/aipgen/constants.py @@ -62,3 +62,6 @@ 'SHA-1': 'sha1', 'SHA-256': 'sha256', } + +# The "well-defined" location for SIP manifests +SIP_MANIFEST_URL = 'https://pds-gamma.jpl.nasa.gov/data/pds4/manifests/' diff --git a/src/pds/aipgen/sip.py b/src/pds/aipgen/sip.py index 0daa027..f7ae4b2 100644 --- a/src/pds/aipgen/sip.py +++ b/src/pds/aipgen/sip.py @@ -33,7 +33,7 @@ from .constants import ( INFORMATION_MODEL_VERSION, PDS_NS_URI, XML_SCHEMA_INSTANCE_NS_URI, XML_MODEL_PI, - PDS_SCHEMA_URL, AIP_PRODUCT_URI_PREFIX, PDS_LABEL_FILENAME_EXTENSION, HASH_ALGORITHMS + PDS_SCHEMA_URL, AIP_PRODUCT_URI_PREFIX, PDS_LABEL_FILENAME_EXTENSION, HASH_ALGORITHMS, SIP_MANIFEST_URL ) from .utils import ( getPrimariesAndOtherInfo, getMD5, getLogicalIdentifierAndFileInventory, parseXML, getDigest, addLoggingArguments @@ -353,8 +353,8 @@ def _writeLabel(logicalID, versionID, title, digest, size, numEntries, hashName, deep.append(etree.Comment('MD5 digest checksum for the manifest file')) etree.SubElement(deep, prefix + 'manifest_checksum').text = digest etree.SubElement(deep, prefix + 'checksum_type').text = 'MD5' - etree.SubElement(deep, prefix + 'manifest_url').text = 'file:' + os.path.abspath(manifestFile) - etree.SubElement(deep, prefix + 'aip_lidvid').text = AIP_PRODUCT_URI_PREFIX + logicalID.split(':')[-1]+ '_v' + versionID + '::1.0' + etree.SubElement(deep, prefix + 'manifest_url').text = SIP_MANIFEST_URL + etree.SubElement(deep, prefix + 'aip_lidvid').text = AIP_PRODUCT_URI_PREFIX + logicalID.split(':')[-1] + '_v' + versionID + '::1.0' aipMD5 = getMD5(aipFile) if aipFile else '00000000000000000000000000000000' etree.SubElement(deep, prefix + 'aip_label_checksum').text = aipMD5 diff --git a/src/pds/aipgen/tests/test_functional.py b/src/pds/aipgen/tests/test_functional.py index bdb8585..eae8944 100644 --- a/src/pds/aipgen/tests/test_functional.py +++ b/src/pds/aipgen/tests/test_functional.py @@ -32,8 +32,10 @@ '''PDS AIP-GEN functional tests''' -import unittest, tempfile, shutil, os, pkg_resources, filecmp +from lxml import etree from pds.aipgen.sip import produce +from pds.aipgen.constants import PDS_NS_URI +import unittest, tempfile, shutil, os, pkg_resources, filecmp class SIPFunctionalTestCase(unittest.TestCase): @@ -41,6 +43,7 @@ class SIPFunctionalTestCase(unittest.TestCase): TODO: factor this out so we can generically do AIP and other file-based functional tests too. ''' + _urlXPath = f'./{{{PDS_NS_URI}}}Information_Package_Component_Deep_Archive/{{{PDS_NS_URI}}}manifest_url' def setUp(self): super(SIPFunctionalTestCase, self).setUp() self.input = pkg_resources.resource_stream(__name__, 'data/ladee_test/mission_bundle/LADEE_Bundle_1101.xml') @@ -49,7 +52,7 @@ def setUp(self): os.chdir(self.testdir) def test_sip_of_a_ladee(self): '''Test if the SIP manifest of LADEE bundle works as expected''' - manifest, label = produce( + manifest, ignoredLabel = produce( bundle=self.input, hashName='md5', registryServiceURL=None, @@ -61,6 +64,22 @@ def test_sip_of_a_ladee(self): aipFile=None ) self.assertTrue(filecmp.cmp(manifest, self.valid), "SIP manifest doesn't match the valid version") + def test_label_url(self): + '''Test if the label of a SIP manifest has the right ``manifest_url``''' + ignoredManifest, label = produce( + bundle=self.input, + hashName='md5', + registryServiceURL=None, + insecureConnectionFlag=True, + site='PDS_ATM', + offline=True, + baseURL='https://atmos.nmsu.edu/PDS/data/PDS4/LADEE/', + allCollections=True, + aipFile=None + ) + matches = etree.parse(label).getroot().findall(self._urlXPath) + self.assertEqual(1, len(matches)) + self.assertEqual('https://pds-gamma.jpl.nasa.gov/data/pds4/manifests/', matches[0].text) def tearDown(self): self.input.close() os.chdir(self.cwd)