@@ -268,11 +268,42 @@ def test_validate_optional_tagfile(self):
268
268
bag = bagit .Bag (self .tmpdir )
269
269
self .assertRaises (bagit .BagValidationError , self .validate , bag )
270
270
271
+ def test_validate_optional_tagfile_in_directory (self ):
272
+ bag = bagit .make_bag (self .tmpdir )
273
+ tagdir = tempfile .mkdtemp (dir = self .tmpdir )
274
+
275
+ if not os .path .exists (j (tagdir , "tagfolder" )):
276
+ os .makedirs (j (tagdir , "tagfolder" ))
277
+
278
+ with open (j (tagdir , "tagfolder" , "tagfile" ), "w" ) as tagfile :
279
+ tagfile .write ("test" )
280
+ relpath = j (tagdir , "tagfolder" , "tagfile" ).replace (self .tmpdir + os .sep , "" )
281
+ relpath .replace ("\\ " , "/" )
282
+ with open (j (self .tmpdir , "tagmanifest-md5.txt" ), "w" ) as tagman :
283
+ # Incorrect checksum.
284
+ tagman .write ("8e2af7a0143c7b8f4de0b3fc90f27354 " + relpath + "\n " )
285
+ bag = bagit .Bag (self .tmpdir )
286
+ self .assertRaises (bagit .BagValidationError , self .validate , bag )
287
+
288
+ hasher = hashlib .new ("md5" )
289
+ with open (j (tagdir , "tagfolder" , "tagfile" ), "r" ) as tf :
290
+ contents = tf .read ().encode ('utf-8' )
291
+ hasher .update (contents )
292
+ with open (j (self .tmpdir , "tagmanifest-md5.txt" ), "w" ) as tagman :
293
+ tagman .write (hasher .hexdigest () + " " + relpath + "\n " )
294
+ bag = bagit .Bag (self .tmpdir )
295
+ self .assertTrue (self .validate (bag ))
296
+
297
+ # Missing tagfile.
298
+ os .remove (j (tagdir , "tagfolder" , "tagfile" ))
299
+ bag = bagit .Bag (self .tmpdir )
300
+ self .assertRaises (bagit .BagValidationError , self .validate , bag )
301
+
271
302
def test_sha1_tagfile (self ):
272
303
info = {
'Bagging-Date' :
'1970-01-01' ,
'Contact-Email' :
'[email protected] ' }
273
304
bag = bagit .make_bag (self .tmpdir , checksum = ['sha1' ], bag_info = info )
274
305
self .assertTrue (os .path .isfile (j (self .tmpdir , 'tagmanifest-sha1.txt' )))
275
- self .assertEqual (bag .entries ['bag-info.txt' ]['sha1' ], 'd7f086508df433e5d7464b5a3835d5501df14404 ' )
306
+ self .assertEqual (bag .entries ['bag-info.txt' ]['sha1' ], 'ec70407d895d4e550bc0a7ea40a82ad653d136e5 ' )
276
307
277
308
def test_validate_unreadable_file (self ):
278
309
bag = bagit .make_bag (self .tmpdir , checksum = ["md5" ])
@@ -329,15 +360,15 @@ def test_make_bag(self):
329
360
self .
assertTrue (
'Contact-Email: [email protected] ' in bag_info_txt )
330
361
self .assertTrue ('Bagging-Date: 1970-01-01' in bag_info_txt )
331
362
self .assertTrue ('Payload-Oxum: 991765.5' in bag_info_txt )
332
- self .assertTrue ('Bag-Software-Agent: bagit.py <http://github.com/libraryofcongress/bagit-python>' in bag_info_txt )
363
+ self .assertTrue ('Bag-Software-Agent: bagit.py v1.5.4 <http://github.com/libraryofcongress/bagit-python>' in bag_info_txt )
333
364
334
365
# check tagmanifest-md5.txt
335
366
self .assertTrue (os .path .isfile (j (self .tmpdir , 'tagmanifest-md5.txt' )))
336
367
with open (j (self .tmpdir , 'tagmanifest-md5.txt' )) as tm :
337
368
tagmanifest_txt = tm .read ()
338
369
self .assertTrue ('9e5ad981e0d29adc278f6a294b8c2aca bagit.txt' in tagmanifest_txt )
339
370
self .assertTrue ('a0ce6631a2a6d1a88e6d38453ccc72a5 manifest-md5.txt' in tagmanifest_txt )
340
- self .assertTrue ('6a5090e27cb29d5dda8a0142fbbdf37e bag-info.txt' in tagmanifest_txt )
371
+ self .assertTrue ('bfe59ad8af1a227d27c191b4178c399f bag-info.txt' in tagmanifest_txt )
341
372
342
373
def test_make_bag_sha1_manifest (self ):
343
374
bagit .make_bag (self .tmpdir , checksum = ['sha1' ])
0 commit comments