Skip to content

Commit

Permalink
Resolve #44 - manifest_url for SIP labels
Browse files Browse the repository at this point in the history
-   Test case to expose the issue
-   New constant for SIP manifest locations
-   Slight PEP-8 cosmetic fix (spaces around `+`)
  • Loading branch information
nutjob4life committed Apr 23, 2020
1 parent e35b329 commit bce766e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/pds/aipgen/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
6 changes: 3 additions & 3 deletions src/pds/aipgen/sip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/pds/aipgen/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
'''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):
'''Functional test case for SIP generation.
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')
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit bce766e

Please sign in to comment.