a1c5544694
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from pathlib import Path
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.main import create_app
|
|
|
|
# /healthz reports the VERSION file's value — the flotilla deploy gate compares
|
|
# body.version against the pinned target (flotilla-core SPEC §8.1 phase 8).
|
|
_VERSION = (Path(__file__).resolve().parents[2] / "VERSION").read_text().strip()
|
|
|
|
|
|
def test_healthz_ok_on_migrated_empty_db(fresh_db_url):
|
|
app = create_app(database_url=fresh_db_url)
|
|
with TestClient(app) as client:
|
|
resp = client.get("/healthz")
|
|
assert resp.status_code == 200
|
|
assert resp.json() == {"status": "ok", "version": _VERSION}
|
|
|
|
|
|
def test_startup_migrates_from_empty(fresh_db_url):
|
|
# create_app on an empty DB must self-migrate so /healthz reports current.
|
|
app = create_app(database_url=fresh_db_url)
|
|
with TestClient(app) as client:
|
|
assert client.get("/healthz").status_code == 200
|
|
# the schema_migrations row exists -> migrations ran at startup
|
|
import psycopg
|
|
|
|
with psycopg.connect(fresh_db_url) as conn:
|
|
n = conn.execute("SELECT count(*) FROM schema_migrations").fetchone()[0]
|
|
assert n >= 1
|