generated from kgod/ai-review-template
自内部仓库剥离深度优化与 RAG 知识库后的交付版本: - Builder 对话式简历生成(FSM + 意图路由 LLM 兜底增强) - 条目级轻度优化:事实覆盖门禁 + STAR/bullet 修复链,功能/简介/成果与技术栈同级保护 - 简历导入:DOCX/PDF 解析、结构归一、手机号脱敏 - PostgreSQL 运行时 + Alembic 迁移链 Co-Authored-By: Claude <noreply@anthropic.com>
41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
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()
|