from __future__ import annotations import os from uuid import uuid4 from fastapi.testclient import TestClient from sqlalchemy import create_engine, text from app.main import create_app from app.postgres_database import PostgresDatabase from app.services import RuleBasedEntryExpander, RuleBasedExperienceExtractor, RuleBasedResumeRewriter from app.settings import Settings def test_create_app_uses_postgres_when_database_path_is_not_supplied(monkeypatch) -> None: schema = f"test_runtime_{uuid4().hex}" database_url = os.environ["RESUME_AGENT_TEST_DATABASE_URL"] monkeypatch.setenv("RESUME_AGENT_DATABASE_SCHEMA", schema) monkeypatch.setenv("RESUME_AGENT_DEFAULT_TIER", "free") application = create_app( extractor=RuleBasedExperienceExtractor(), rewriter=RuleBasedResumeRewriter(), expander=RuleBasedEntryExpander(), settings=Settings(llm_provider="rule", database_url=database_url), ) try: assert isinstance(application.state.database, PostgresDatabase) with TestClient(application) as client: response = client.post("/ai-api/resume-agent/sessions", json={}) assert response.status_code == 201 session_id = response.json()["session_id"] assert application.state.database.get_session(session_id) is not None finally: application.state.database.engine.dispose() engine = create_engine(database_url) try: with engine.begin() as connection: connection.execute(text(f'DROP SCHEMA IF EXISTS "{schema}" CASCADE')) finally: engine.dispose()