- apps/api: psycopg v3 repositories, schema.sql + migration runner, state machine implementing the data-model transition table, approval gate with sha256 hash match + 24h expiry enforced at send time, EchoTransport pluggable sender, LLM calls routed through packages.llm-gateway with mock mode, 47 pytest tests green - apps/api/Dockerfile.test: python 3.13-slim test image (DinD-safe: migrations copied as directory) - docker-compose.yml: add api-test service on compose network (host port publishing is broken in this sandbox; container-to-container networking used) - Fix: replace masked placeholder password in config.py/conftest.py defaults
47 lines
No EOL
1.2 KiB
Python
47 lines
No EOL
1.2 KiB
Python
"""Pytest fixtures: database setup/teardown for all tests.
|
|
|
|
Uses a real PostgreSQL on port 5433 (jobhunt-test-pg container).
|
|
Each test module gets a clean database via truncate fixtures.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
# Set DATABASE_URL before importing app modules
|
|
os.environ.setdefault(
|
|
"DATABASE_URL",
|
|
"postgresql://jobhunt:jobhunt@localhost:5433/jobhunt",
|
|
)
|
|
|
|
from app.db import close_pool, get_pool # noqa: E402
|
|
from app.db import migrate as migrate_mod # noqa: E402
|
|
from app.db import repo_app, repo_profile # noqa: E402
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def _setup_database():
|
|
"""Run migrations once at session start."""
|
|
migrate_mod.reset_database()
|
|
yield
|
|
close_pool()
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _truncate_tables():
|
|
"""Truncate all tables before each test (except schema_migrations)."""
|
|
import psycopg
|
|
from app.config import DATABASE_URL
|
|
|
|
with psycopg.connect(DATABASE_URL) as conn:
|
|
conn.execute(
|
|
"""
|
|
TRUNCATE TABLE task_run, outbox, approval, artifact,
|
|
application, job_posting, cv_section, profile
|
|
CASCADE
|
|
"""
|
|
)
|
|
conn.commit()
|
|
yield |