def test_ark_ediid(self): podf = os.path.join(self.sipdir, "_pod.json") with open(podf) as fd: pod = json.load(fd) pod['identifier'] = self.arkid with open(podf, 'w') as fd: json.dump(pod, fd, indent=2) bagname = self.arkid[11:] + ".1_0.mbag0_4-0" self.bagr = midas.PreservationBagger(self.arkid, '_preserv', self.revdir, self.mddir, self.bagr.cfg) self.assertEqual(self.bagr.midasid, self.arkid) self.assertEqual(self.bagr.name, self.arkid[11:]) self.assertEqual(self.bagr.indir, os.path.join(self.revdir, self.arkid[16:])) self.assertEqual(os.path.basename(self.bagr.bagdir), bagname) self.assertEqual(os.path.basename(self.bagr.bagbldr.bagdir), bagname) self.bagr.ensure_metadata_preparation() self.assertEqual(self.bagr.bagbldr.id, self.arkid) self.assertEqual(os.path.basename(self.bagr.bagbldr.bag.dir), bagname) nerdm = self.bagr.bagbldr.bag.nerd_metadata_for('') self.assertEqual(nerdm['ediid'], self.arkid) self.assertEqual(nerdm['@id'], self.arkid)
def setUp(self): self.tf = Tempfiles() self.workdir = self.tf.mkdir("bagger") self.mddir = os.path.join(self.workdir, "mddir") os.mkdir(self.mddir) # TODO: copy input data to writable location testsip = os.path.join(self.testsip, "review") self.revdir = os.path.join(self.workdir, "review") shutil.copytree(testsip, self.revdir) config = { 'relative_to_indir': True, 'bag_builder': { 'validate_id': r'(pdr\d)|(mds[01])', 'copy_on_link_failure': False, 'init_bag_info': { 'Source-Organization': "National Institute of Standards and Technology", 'Contact-Email': ["*****@*****.**"], 'Organization-Address': ["100 Bureau Dr., Gaithersburg, MD 20899"], 'NIST-BagIt-Version': "0.4", 'Multibag-Version': "0.4" } }, 'store_dir': '/tmp' } self.bagr = midas.PreservationBagger(self.midasid, '_preserv', self.revdir, self.mddir, config) self.sipdir = os.path.join(self.revdir, "1491") self.bagparent = os.path.join(self.sipdir, "_preserv")
def test_ensure_metadata_preparation_requireupdate(self): # test resolving an identifier for a dataset being updated (after # an initial publication) srczip = os.path.join(distarchive, "1491.1_0.mbag0_4-0.zip") destzip = os.path.join(distarchive, self.midasid + ".1_0.mbag0_4-0.zip") cached = os.path.join(self.pubcache, os.path.basename(destzip)) self.bagr = midas.PreservationBagger(self.midasid, '_preserv', self.revdir, self.mddir, self.bagr.cfg, asupdate=False) try: # put a record in the RMM to signal the AIP's existence shutil.copy(os.path.join(datadir, self.midasid + ".json"), mdarchive) shutil.copyfile(srczip, destzip) self.bagr.ensure_metadata_preparation() self.fail("Failed to prevent represerving without update") except midas.PreservationStateException as ex: self.assertTrue(ex.aipexists) finally: if os.path.exists(destzip): os.remove(destzip) if os.path.exists(cached): os.remove(cached) rec = os.path.join(mdarchive, self.midasid + ".json") if os.path.exists(rec): os.remove(rec)
def setUp(self): self.tf = Tempfiles() self.workdir = self.tf.mkdir("bagger") self.mddir = os.path.join(self.workdir, "mddir") os.mkdir(self.mddir) self.pubcache = self.tf.mkdir("headcache") # TODO: copy input data to writable location testsip = os.path.join(self.testsip, "review") self.revdir = os.path.join(self.workdir, "review") shutil.copytree(testsip, self.revdir) now = time.time() for base, dirs, files in os.walk(self.revdir): for f in files + dirs: os.utime(os.path.join(base, f), (now, now)) config = { 'relative_to_indir': True, 'bag_builder': { 'copy_on_link_failure': False, 'init_bag_info': { 'Source-Organization': "National Institute of Standards and Technology", 'Contact-Email': ["*****@*****.**"], 'Organization-Address': ["100 Bureau Dr., Gaithersburg, MD 20899"], 'NIST-BagIt-Version': "0.4", 'Multibag-Version': "0.4" } }, 'repo_access': { 'headbag_cache': self.pubcache, 'distrib_service': { 'service_endpoint': "http://localhost:9091/" }, 'metadata_service': { 'service_endpoint': "http://localhost:9092/" } }, 'store_dir': distarchdir } self.bagr = midas.PreservationBagger(self.midasid, '_preserv', self.revdir, self.mddir, config) self.sipdir = os.path.join(self.revdir, "1491") self.bagparent = os.path.join(self.sipdir, "_preserv")
def test_ensure_metadata_preparation_ensureupdate(self): # test that we can catch a request for an update to an AIP # that doesn't exist yet. self.bagr = midas.PreservationBagger(self.midasid, '_preserv', self.revdir, self.mddir, self.bagr.cfg, asupdate=True) try: self.bagr.ensure_metadata_preparation() self.fail("Failed to prevent to ensure previous publication") except midas.PreservationStateException as ex: self.assertTrue(not ex.aipexists)