Add more tests for SHA256TransactionStore.
One of the tests is a known failure because of a bug, so mark it accordingly. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
e509dacc9a
commit
41fef74e9d
1 changed files with 31 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue