Backend tests run on SQLite by default (78 passed, 1 skipped); no Postgres needed
- conftest: default SHONAR_TEST_DATABASE_URL is a temp SQLite file, matching the bundled-lite engine; set the env var to a PG URL to exercise that path - models.py: add sqlite_where to the two partial unique indexes — without it SQLite built a FULL unique index on recording_id (WHERE not carried over), wrongly blocking a second export asset per recording - test_m9: pass UUID objects (not str) to direct ORM inserts/gets; SQLite's GUID bind processor rejects strings (asyncpg tolerated them) Verified: pytest -q = 78 passed, 1 skipped; ruff check clean
This commit is contained in:
parent
adc40201a1
commit
a94609c07b
3 changed files with 35 additions and 9 deletions
|
|
@ -1,7 +1,10 @@
|
|||
"""Pytest fixtures.
|
||||
|
||||
Tests run against a real PostgreSQL (deploy/docker-compose.dev.yml) using a
|
||||
dedicated ``shonar_test`` database, plus a temporary local storage root.
|
||||
Default: SQLite (aiosqlite) in a temp dir — matches the desktop
|
||||
bundled-lite engine and needs no services running. Set
|
||||
``SHONAR_TEST_DATABASE_URL`` to a PostgreSQL URL (e.g.
|
||||
``postgresql+asyncpg://shonar:shonar@localhost:5432/shonar_test``) to
|
||||
exercise the Postgres path, including the tsvector FTS columns.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
|
@ -15,9 +18,11 @@ import pytest
|
|||
import pytest_asyncio
|
||||
|
||||
# Configure env BEFORE importing the app so Settings picks it up.
|
||||
_db_dir = tempfile.mkdtemp(prefix="shonar-test-db-")
|
||||
TEST_DB = os.environ.get(
|
||||
"SHONAR_TEST_DATABASE_URL",
|
||||
"postgresql+asyncpg://shonar:shonar@localhost:5432/shonar_test",
|
||||
# Bundled-lite default: throwaway SQLite file; no services required.
|
||||
f"sqlite+aiosqlite:///{os.path.join(_db_dir, 'test.db')}",
|
||||
)
|
||||
os.environ["SHONAR_DATABASE_URL"] = TEST_DB
|
||||
os.environ["SHONAR_SECRET_KEY"] = "test-secret-key-0123456789abcdef0123456789abcdef"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue