add integration tests for admin, auth, user management, and database initialization
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Tests for DuckDB initialization and schema."""
|
||||
import pytest
|
||||
import duckdb
|
||||
|
||||
from backend.app import db as db_module
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def fresh_db():
|
||||
"""Use an in-memory DB for each test and reset global state."""
|
||||
db_module._conn = None
|
||||
yield
|
||||
db_module.close_db()
|
||||
db_module._conn = None
|
||||
|
||||
|
||||
def test_init_creates_users_table():
|
||||
conn = db_module.init_db(":memory:")
|
||||
result = conn.execute(
|
||||
"SELECT table_name FROM information_schema.tables WHERE table_name = 'users'"
|
||||
).fetchone()
|
||||
assert result is not None
|
||||
|
||||
|
||||
def test_init_creates_refresh_tokens_table():
|
||||
conn = db_module.init_db(":memory:")
|
||||
result = conn.execute(
|
||||
"SELECT table_name FROM information_schema.tables WHERE table_name = 'refresh_tokens'"
|
||||
).fetchone()
|
||||
assert result is not None
|
||||
|
||||
|
||||
def test_init_is_idempotent():
|
||||
conn1 = db_module.init_db(":memory:")
|
||||
conn2 = db_module.init_db(":memory:")
|
||||
assert conn1 is conn2
|
||||
|
||||
|
||||
def test_get_conn_raises_before_init():
|
||||
with pytest.raises(RuntimeError, match="not initialised"):
|
||||
db_module.get_conn()
|
||||
|
||||
|
||||
def test_get_conn_returns_connection_after_init():
|
||||
db_module.init_db(":memory:")
|
||||
conn = db_module.get_conn()
|
||||
assert conn is not None
|
||||
|
||||
|
||||
def test_close_db_resets_connection():
|
||||
db_module.init_db(":memory:")
|
||||
db_module.close_db()
|
||||
with pytest.raises(RuntimeError):
|
||||
db_module.get_conn()
|
||||
Reference in New Issue
Block a user