Esempio n. 1
0
 def test_update_oxum(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   bag.info['Payload-Oxum'] = '0.0'
   self.assertFalse(bag.is_valid())
   bag.write_baginfo()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertTrue(self.validate(updated_bag))
Esempio n. 2
0
 def test_update_hashes(self):
   bagit.make_bag(self.tmpdir, checksum=['sha1', 'sha256'])
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/hello.txt")
   with open(f, 'w') as r:
     r.write('♡')
   bag.update_hashes()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertTrue(self.validate(updated_bag))
Esempio n. 3
0
 def test_add_payload_file_not_in_multiple_manifests(self):
   bagit.make_bag(self.tmpdir, checksum=['sha1', 'sha256'])
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/._.SYSTEMFILE.db\r")
   with open(f, 'w') as r:
     r.write('♡')
   bag.add_payload_files_not_in_manifest()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertTrue(self.validate(updated_bag))
Esempio n. 4
0
 def test_update_hashes_with_no_filter_match(self):
   bagit.make_bag(self.tmpdir, checksum=['sha1'])
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/hello.txt")
   with open(f, 'w') as r:
     r.write('♡')
   bag.update_hashes(filename_pattern = r"\d")
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertEqual(bag.entries["data/hello.txt"], updated_bag.entries["data/hello.txt"])
   self.assertRaises(bagit.BagValidationError, updated_bag.validate, fast=False)
Esempio n. 5
0
 def test_record_premis_nondefault_human_agent(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir, repairer = "Smokey Yunick")
   bag.add_premisevent(process = "Peek into bag",
     msg = "Just looking around", outcome = "Pass",
     sw_agent = "update_bag.py", human_agent = "Yogi Bear")
   bag.write_bag_updates()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertEqual(updated_bag.premis_events[0]['Event-Human-Agent'],
     "Yogi Bear")
Esempio n. 6
0
 def test_delete_payload_files_not_in_manifest_with_rules(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/Thumbs.db")
   with open(f, 'w') as r:
     r.write('♡')
   self.assertEqual(list(bag.payload_files_not_in_manifest()), ['data/Thumbs.db'])
   bag.delete_payload_files_not_in_manifest(rules = {"Thumbs.db": {"regex": r"[Tt]humbs\.db$", "match": False}})
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertTrue(updated_bag.is_valid(fast = True))
Esempio n. 7
0
 def test_delete_payload_files_not_in_manifest(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/._.SYSTEMFILE.db\r")
   with open(f, 'w') as r:
     r.write('♡')
   self.assertEqual(list(bag.payload_files_not_in_manifest()), ['data/._.SYSTEMFILE.db\r'])
   bag.delete_payload_files_not_in_manifest()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertTrue(self.validate(updated_bag))
Esempio n. 8
0
 def test_update_hashes_with_filter_match(self):
   bagit.make_bag(self.tmpdir, checksum=['sha1'])
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/hello.txt")
   with open(f, 'w') as r:
     r.write('♡')
   bag.update_hashes(filename_pattern = r"\w")
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertEqual(bag.entries["data/hello.txt"], updated_bag.entries["data/hello.txt"])
   self.assertTrue(self.validate(updated_bag))
Esempio n. 9
0
 def test_do_not_delete_payload_files_not_in_manifest_not_rules(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/._.SYSTEMFILE.db\r")
   with open(f, 'w') as r:
     r.write('♡')
   self.assertEqual(list(bag.payload_files_not_in_manifest()), ['data/._.SYSTEMFILE.db\r'])
   bag.delete_payload_files_not_in_manifest(rules = {"Thumbs.db": {"regex": r"[Tt]humbs\\.db$", "match": False}})
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertEqual(list(updated_bag.payload_files_not_in_manifest()), ['data/._.SYSTEMFILE.db\r'])
   self.assertRaises(bagit.BagValidationError, bag.validate, updated_bag, fast=False)
Esempio n. 10
0
 def test_record_premis_events(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   bag.add_premisevent(process = "Peek into bag",
     msg = "Just looking around",
     outcome = "Pass", sw_agent = "update_bag.py")
   bag.write_bag_updates()
   updated_bag = update_bag.Repairable_Bag(path = self.tmpdir)
   self.assertEqual(len(updated_bag.premis_events), 1)
   self.assertEqual(set(updated_bag.premis_events[0].keys()),
     set(['Event-Date-Time', 'Event-Type', 'Event-Detail-Information',
     'Event-Outcome', 'Event-Software-Agent']))
Esempio n. 11
0
 def test_payload_file_not_in_manifest(self):
   bagit.make_bag(self.tmpdir)
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   f = j(self.tmpdir, "data/._.SYSTEMFILE.db\r")
   with open(f, 'w') as r:
     r.write('♡')
   self.assertEqual(list(bag.payload_files_not_in_manifest()), ['data/._.SYSTEMFILE.db\r'])
   self.assertRaises(bagit.BagValidationError, bag.validate, bag, fast=False)
Esempio n. 12
0
 def test_load_bagmake_bag_sha1_sha256_manifest(self):
   bagit.make_bag(self.tmpdir, checksum=['sha1', 'sha256'])
   bag = update_bag.Repairable_Bag(path = self.tmpdir)
   # check that relevant manifests are created
   self.assertTrue(os.path.isfile(j(self.tmpdir, 'manifest-sha1.txt')))
   self.assertTrue(os.path.isfile(j(self.tmpdir, 'manifest-sha256.txt')))
   # check valid with two manifests
   self.assertTrue(self.validate(bag, fast=True))