35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
|
|
"""Tests for the migration runner."""
|
||
|
|
|
||
|
|
from migrations.migrate import get_applied, get_connection, migrate_down, migrate_up, verify
|
||
|
|
|
||
|
|
|
||
|
|
def test_migrate_up_and_status(tmp_path):
|
||
|
|
"""Should apply all migrations and track them."""
|
||
|
|
db_path = str(tmp_path / "test.db")
|
||
|
|
count = migrate_up(db_path)
|
||
|
|
assert count >= 2 # At least the 2 existing migrations
|
||
|
|
|
||
|
|
conn = get_connection(db_path)
|
||
|
|
applied = get_applied(conn)
|
||
|
|
assert "001_initial_schema" in applied
|
||
|
|
assert "002_add_sessions_and_audit" in applied
|
||
|
|
|
||
|
|
|
||
|
|
def test_migrate_down(tmp_path):
|
||
|
|
"""Should rollback the last migration."""
|
||
|
|
db_path = str(tmp_path / "test.db")
|
||
|
|
migrate_up(db_path)
|
||
|
|
result = migrate_down(db_path)
|
||
|
|
assert result is True
|
||
|
|
|
||
|
|
conn = get_connection(db_path)
|
||
|
|
applied = get_applied(conn)
|
||
|
|
assert "002_add_sessions_and_audit" not in applied
|
||
|
|
assert "001_initial_schema" in applied
|
||
|
|
|
||
|
|
|
||
|
|
def test_verify():
|
||
|
|
"""Verify should apply migrations to a temp DB cleanly."""
|
||
|
|
result = verify()
|
||
|
|
assert result is True
|