diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index c9518a4..8fa4ec8 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -15,19 +15,26 @@ tests that COMMIT (the whole point of this lane — transaction-ownership behavi import pytest from alembic import command from alembic.config import Config -from sqlalchemy import text +from sqlalchemy import create_engine, text import app.models # noqa: F401 — register every model on Base.metadata +from app.config import settings from app.db import Base, SessionLocal, engine def _db_reachable() -> bool: + # A throwaway engine with a bounded connect_timeout so a slow/firewalled DATABASE_URL can't + # hang the whole suite at import (the app engine has no connect timeout). The compose lane + # gates on `service_healthy`, but this keeps a manual run honest too. + probe = create_engine(settings.database_url, connect_args={"connect_timeout": 3}) try: - with engine.connect() as conn: + with probe.connect() as conn: conn.execute(text("SELECT 1")) return True except Exception: return False + finally: + probe.dispose() _DB_REACHABLE = _db_reachable() diff --git a/backend/tests/test_plex_facets.py b/backend/tests/test_plex_facets.py index a8eae42..fe8198b 100644 --- a/backend/tests/test_plex_facets.py +++ b/backend/tests/test_plex_facets.py @@ -15,16 +15,17 @@ from app.main import app from app.models import PlexLibrary, PlexShow, User -def test_facets_survives_json_null_genres(db): +def test_facets_survives_json_null_genres(db, monkeypatch): lib = PlexLibrary(plex_key="1", title="Shows", kind="show", enabled=True) db.add(lib) db.flush() db.add(PlexShow(rating_key="s1", library_id=lib.id, title="No Genre Show")) user = User(email="facets@example.com") db.add(user) - # The request gate 503s an unconfigured instance; mark this throwaway DB configured. - state.mark_configured(db) db.commit() + # The request gate 503s an unconfigured instance; flip the process-level "configured" flag the + # gate reads. monkeypatch auto-restores it, so it can't leak "configured" into another test. + monkeypatch.setattr(state, "_configured_cache", True) # Simulate a pre-0.53.1 row: genres persisted as a JSONB scalar `null` (what SQLAlchemy wrote # before none_as_null=True), NOT SQL NULL — this is the value jsonb_array_elements_text() chokes # on. A Python None now maps to SQL NULL, so we set the scalar directly. @@ -38,7 +39,6 @@ def test_facets_survives_json_null_genres(db): resp = client.get("/api/plex/facets?scope=show") finally: app.dependency_overrides.clear() - state._configured_cache = False # one-way process cache — don't leak "configured" to other tests assert resp.status_code == 200, resp.text # The scalar-null show contributes no genres — and, crucially, doesn't abort the whole endpoint.