src/auth/db.py : schéma SQLite et connexion (#73)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def users_db_path(monkeypatch, tmp_path):
|
||||
from src.auth.db import reset_conn_for_tests
|
||||
|
||||
db_path = tmp_path / "users.test.sqlite"
|
||||
monkeypatch.setenv("USERS_DB_PATH", str(db_path))
|
||||
reset_conn_for_tests()
|
||||
yield db_path
|
||||
reset_conn_for_tests()
|
||||
@@ -0,0 +1,31 @@
|
||||
from src.auth.db import get_conn, init_schema
|
||||
|
||||
|
||||
def test_init_schema_creates_tables(users_db_path):
|
||||
init_schema()
|
||||
conn = get_conn()
|
||||
tables = {
|
||||
row[0]
|
||||
for row in conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table'"
|
||||
).fetchall()
|
||||
}
|
||||
assert {"users", "email_verification_tokens", "password_reset_tokens"} <= tables
|
||||
|
||||
|
||||
def test_init_schema_is_idempotent(users_db_path):
|
||||
init_schema()
|
||||
init_schema()
|
||||
conn = get_conn()
|
||||
tables = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table'"
|
||||
).fetchall()
|
||||
names = [r[0] for r in tables]
|
||||
assert names.count("users") == 1
|
||||
|
||||
|
||||
def test_pragmas_active(users_db_path):
|
||||
init_schema()
|
||||
conn = get_conn()
|
||||
assert conn.execute("PRAGMA foreign_keys").fetchone()[0] == 1
|
||||
assert conn.execute("PRAGMA journal_mode").fetchone()[0].lower() == "wal"
|
||||
Reference in New Issue
Block a user