1 parent
0421994fe6
commit
425ea7449b
138 files changed
+5705
-1012
No files matched your search
@@ -0,0 +1,32 @@
|
||||
from pathlib import Path
|
||||
import sqlite3
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def test_all_user_sqlite_migrations_apply_on_fresh_database(tmp_path):
|
||||
db_path = tmp_path / "user.sqlite"
|
||||
conn = sqlite3.connect(db_path)
|
||||
migrations = sorted((ROOT / "migrations/sqlite").glob("V*.sql"))
|
||||
user_migrations = [m for m in migrations if m.name != "V047__sessions.sql"]
|
||||
assert len(user_migrations) == 46
|
||||
for migration in user_migrations:
|
||||
conn.executescript(migration.read_text())
|
||||
version = int(migration.name[1:4])
|
||||
conn.execute(f"PRAGMA user_version = {version}")
|
||||
assert conn.execute("PRAGMA user_version").fetchone()[0] == 46
|
||||
tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
assert {"user_meta", "folders", "messages", "drafts", "contacts"} <= tables
|
||||
assert "sessions" not in tables
|
||||
conn.close()
|
||||
|
||||
|
||||
def test_session_sqlite_migration_is_separate_and_valid(tmp_path):
|
||||
db_path = tmp_path / "rustbox.sqlite"
|
||||
conn = sqlite3.connect(db_path)
|
||||
conn.executescript((ROOT / "migrations/sqlite/V047__sessions.sql").read_text())
|
||||
tables = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='table'")}
|
||||
indexes = {row[0] for row in conn.execute("SELECT name FROM sqlite_master WHERE type='index'")}
|
||||
assert "sessions" in tables
|
||||
assert {"idx_sessions_browser", "idx_sessions_user", "idx_sessions_expiry"} <= indexes
|
||||
conn.close()
|
||||
Reference in new issue
Block a user