@@ -1130,7 +1130,30 @@ def test_fetching_payload_file(self):
1130
1130
with self .assertRaises (bagit .BagError ):
1131
1131
self .bag .validate ()
1132
1132
# re-fetch it
1133
- self .bag .fetch_files_to_be_fetched ()
1133
+ self .bag .fetch ()
1134
+ # should be valid again
1135
+ self .bag .validate ()
1136
+ self .assertEqual (len (self .bag .compare_fetch_with_fs ()), 0 , 'complete' )
1137
+
1138
+ def test_force_fetching (self ):
1139
+ test_payload = 'loc/2478433644_2839c5e8b8_o_d.jpg'
1140
+ with open (j (self .tmpdir , "fetch.txt" ), "w" ) as fetch_txt :
1141
+ print ("https://github.com/LibraryOfCongress/bagit-python/raw/master/test-data/%s %s data/%s" % (
1142
+ test_payload , 139367 , test_payload ), file = fetch_txt )
1143
+ self .bag .save (manifests = True )
1144
+ # now replace one payload file with an empty string
1145
+ with open (j (self .tmpdir , "data" , test_payload ), 'w' ) as payload :
1146
+ payload .write ('' )
1147
+ # should be invalid now
1148
+ with self .assertRaisesRegexp (bagit .BagError , "^Payload-Oxum validation failed." ):
1149
+ self .bag .validate ()
1150
+ # non-forcefully downloading should not help
1151
+ self .bag .fetch ()
1152
+ # should **still* be invalid now
1153
+ with self .assertRaisesRegexp (bagit .BagError , "^Payload-Oxum validation failed." ):
1154
+ self .bag .validate ()
1155
+ # fetch with force
1156
+ self .bag .fetch (force = True )
1134
1157
# should be valid again
1135
1158
self .bag .validate ()
1136
1159
self .assertEqual (len (self .bag .compare_fetch_with_fs ()), 0 , 'complete' )
0 commit comments