forked from Friz-zy/python-keepass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_io.py
28 lines (24 loc) · 821 Bytes
/
test_io.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import tempfile
import shutil
import os
import keepass.kpdb
def test_write():
"""
Try to create a file and then read it back in.
"""
password = 'REINDEER FLOTILLA'
tempdir = tempfile.mkdtemp()
kdb_path = os.path.join(tempdir, 'test_write.kdb')
try:
db = keepass.kpdb.Database()
db.add_entry(path='Secrets/Terrible', title='Gonk', username='foo', password='bar', url='https://example.org/')
assert len(db.groups) == 4
assert len(db.entries) == 3
db.write(kdb_path, password)
assert os.path.isfile(kdb_path)
db2 = keepass.kpdb.Database(kdb_path, password)
assert len(db.groups) == 4
assert len(db.entries) == 3
assert db.entries[2].name() == 'Gonk'
finally:
shutil.rmtree(tempdir)