-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
42 lines (32 loc) · 1.23 KB
/
Copy pathtest.py
File metadata and controls
42 lines (32 loc) · 1.23 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# LICENSE MIT Neo Sahadeo 2026
import os
import unittest
import sqlcipher
CIPHER = "test1234"
DB_NAME = "test.db"
class TestSQLExecute(unittest.TestCase):
@classmethod
def setUpClass(cls):
if os.path.exists(DB_NAME):
os.remove(DB_NAME)
cls._conn = sqlcipher.open(DB_NAME, CIPHER)
@classmethod
def tearDownClass(cls):
cls._conn.close()
def test_table_creation(self):
self._conn.execute("CREATE TABLE IF NOT EXISTS users ( username STR, salt BLOB NOT NULL )")
self._conn.execute("SELECT * from users")
def test_insert(self):
self.test_table_creation()
self._conn.execute("INSERT INTO users (username, salt) VALUES (?, ?)", ("neo", b"12345"))
data = self._conn.execute("SELECT * from users WHERE username = ?", ("neo",))
assert (len(data) > 0)
def test_key_change(self):
self._conn.execute("PRAGMA rekey = '4321test'")
self._conn.close()
self._conn = sqlcipher.open(DB_NAME, CIPHER)
with self.assertRaises(RuntimeError) as cm:
print(self._conn.execute("SELECT * from users"))
self.assertEqual(str(cm.exception), 'file is not a database')
if __name__ == "__main__":
unittest.main()