27 lines
865 B
Python
27 lines
865 B
Python
import sqlite3
|
|
import tempfile
|
|
import pytest
|
|
from app.db.store import get_connection, run_migrations
|
|
|
|
|
|
def test_migrations_create_tables():
|
|
with tempfile.NamedTemporaryFile(suffix=".db") as f:
|
|
conn = get_connection(f.name)
|
|
run_migrations(conn)
|
|
tables = {r[0] for r in conn.execute(
|
|
"SELECT name FROM sqlite_master WHERE type='table'"
|
|
)}
|
|
assert "chains" in tables
|
|
assert "nodes" in tables
|
|
|
|
|
|
def test_foreign_keys_enforced():
|
|
with tempfile.NamedTemporaryFile(suffix=".db") as f:
|
|
conn = get_connection(f.name)
|
|
run_migrations(conn)
|
|
with pytest.raises(sqlite3.IntegrityError):
|
|
conn.execute(
|
|
"INSERT INTO nodes (id, chain_id, status, created_at) "
|
|
"VALUES ('n1', 'nonexistent', 'pending', 0.0)"
|
|
)
|
|
conn.commit()
|