diff --git a/test/testfilemanip.py b/test/testfilemanip.py index 07e3fdc..00dfbe2 100755 --- a/test/testfilemanip.py +++ b/test/testfilemanip.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from newfol.filemanip import Record, FileStorage, SHA256TransactionStore +import newfol.exception import tempfile import unittest @@ -70,6 +71,36 @@ class SHA256TransactionTest(unittest.TestCase): self.assertEqual(SHA256TransactionStore._hash_file(temp), "sha256:" + v) tempdir = None + def create_small_database(self, tempdir): + temp = tempdir.name + "/test" + fp = open(temp, "w") + fp.write(":\n") + fp.close() + return temp + def create_filestorage(self, *args): + class Simple: + pass + x = Simple() + x.tempdir = tempfile.TemporaryDirectory() + x.tempfile = self.create_small_database(x.tempdir) + x.fs = FileStorage("csv", x.tempfile, "sha256", *args) + return x + @unittest.expectedFailure + def test_missing_not_forgiving(self): + x = self.create_filestorage({"forgiving": False}) + with self.assertRaisesRegex(newfol.exception.UpgradeNeededError, + 'missing checksum'): + x.fs.load() + x.tempdir.cleanup() + def test_missing_forgiving(self): + x = self.create_filestorage({"forgiving": True}) + x.fs.load() + x.tempdir.cleanup() + def test_missing(self): + x = self.create_filestorage() + x.fs.load() + x.tempdir.cleanup() + if __name__ == '__main__': unittest.main()