refactor: split monolithic phase tests into per-module test files
- rename test_admin_phase4.py -> test_admin.py, test_search.py -> test_searcher.py - split test_phase5.py into test_cleaner, test_embedder, test_image_extractor, test_pages - move schema tests from test_summarizer.py into dedicated test_schemas.py - add sample_papers_range and sample_papers_with_summary fixtures in conftest - update .gitignore to exclude all of data/
This commit is contained in:
@@ -209,3 +209,122 @@ def admin_token():
|
||||
def admin_headers(admin_token):
|
||||
"""带 Bearer token 的请求头。"""
|
||||
return {"Authorization": f"Bearer {admin_token}"}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def wrong_admin_headers():
|
||||
"""错误的 Authorization 请求头。"""
|
||||
return {"Authorization": "Bearer wrong-token"}
|
||||
|
||||
|
||||
# ── 多样例数据 ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_papers_range(db_session):
|
||||
"""插入 5 篇不同日期的论文(用于 admin / cleaner 测试)。"""
|
||||
now = datetime.now(timezone.utc)
|
||||
papers = []
|
||||
for i, (arxiv_id, paper_date_str) in enumerate([
|
||||
("2401.10001", "2024-01-10"),
|
||||
("2401.10002", "2024-01-11"),
|
||||
("2401.10003", "2024-01-12"),
|
||||
("2401.10004", "2024-01-13"),
|
||||
("2401.10005", "2024-01-14"),
|
||||
]):
|
||||
paper_date = date.fromisoformat(paper_date_str)
|
||||
p = Paper(
|
||||
arxiv_id=arxiv_id,
|
||||
title_en=f"Test Paper {i+1}",
|
||||
abstract=f"Abstract for paper {i+1}.",
|
||||
paper_date=paper_date,
|
||||
crawled_at=now,
|
||||
upvotes=i * 10,
|
||||
)
|
||||
db_session.add(p)
|
||||
db_session.flush()
|
||||
db_session.add(PaperAuthor(paper_id=p.id, name=f"Author {i+1}", position=0))
|
||||
db_session.add(PaperTag(paper_id=p.id, tag=f"Tag{i+1}", source="hf"))
|
||||
db_session.add(SummaryStatus(paper_id=p.id, status="pending"))
|
||||
# FTS5
|
||||
db_session.execute(
|
||||
__import__("sqlalchemy").text(
|
||||
"INSERT INTO papers_fts(rowid, title_en, abstract, authors, tags) "
|
||||
"VALUES (:id, :title, :abstract, :authors, :tags)"
|
||||
),
|
||||
{"id": p.id, "title": p.title_en, "abstract": p.abstract,
|
||||
"authors": f"Author {i+1}", "tags": f"Tag{i+1}"},
|
||||
)
|
||||
papers.append(p)
|
||||
db_session.commit()
|
||||
return papers
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def sample_papers_with_summary(db_session):
|
||||
"""插入 5 篇带总结的论文(用于 search / pages / trends 测试)。"""
|
||||
now = datetime.now(timezone.utc)
|
||||
papers = []
|
||||
for i, (arxiv_id, paper_date_str) in enumerate([
|
||||
("2401.20001", "2024-01-10"),
|
||||
("2401.20002", "2024-01-11"),
|
||||
("2401.20003", "2024-01-12"),
|
||||
("2401.20004", "2024-01-13"),
|
||||
("2401.20005", "2024-01-14"),
|
||||
]):
|
||||
paper_date = date.fromisoformat(paper_date_str)
|
||||
p = Paper(
|
||||
arxiv_id=arxiv_id,
|
||||
title_en=f"Test Paper {i+1}",
|
||||
title_zh=f"测试论文 {i+1}",
|
||||
abstract=f"Abstract for paper {i+1}.",
|
||||
paper_date=paper_date,
|
||||
crawled_at=now,
|
||||
upvotes=i * 10 + 5,
|
||||
)
|
||||
db_session.add(p)
|
||||
db_session.flush()
|
||||
|
||||
db_session.add(PaperAuthor(paper_id=p.id, name=f"Author {i+1}", position=0))
|
||||
db_session.add(PaperTag(paper_id=p.id, tag="NLP", source="hf"))
|
||||
db_session.add(PaperTag(paper_id=p.id, tag=f"Tag{i+1}", source="hf"))
|
||||
|
||||
db_session.add(SummaryStatus(
|
||||
paper_id=p.id,
|
||||
status="done" if i < 4 else "pending",
|
||||
quality="normal",
|
||||
))
|
||||
|
||||
# 添加总结(前 4 篇)
|
||||
if i < 4:
|
||||
summary = PaperSummary(
|
||||
paper_id=p.id,
|
||||
one_line=f"这是论文{i+1}的一句话摘要",
|
||||
difficulty="中级",
|
||||
motivation_problem=f"论文{i+1}的研究问题",
|
||||
motivation_goal=f"论文{i+1}的研究目标",
|
||||
method_key_idea=f"论文{i+1}的关键思路",
|
||||
method_overview=f"论文{i+1}的方法概述",
|
||||
updated_at=now,
|
||||
full_json=json.dumps({"title_zh": f"测试论文 {i+1}"}),
|
||||
)
|
||||
db_session.add(summary)
|
||||
|
||||
# FTS5
|
||||
db_session.execute(
|
||||
__import__("sqlalchemy").text(
|
||||
"INSERT INTO papers_fts(rowid, title_en, title_zh, abstract, authors, tags) "
|
||||
"VALUES (:id, :title_en, :title_zh, :abstract, :authors, :tags)"
|
||||
),
|
||||
{
|
||||
"id": p.id,
|
||||
"title_en": p.title_en,
|
||||
"title_zh": p.title_zh or "",
|
||||
"abstract": p.abstract or "",
|
||||
"authors": f"Author {i+1}",
|
||||
"tags": f"NLP, Tag{i+1}",
|
||||
},
|
||||
)
|
||||
papers.append(p)
|
||||
db_session.commit()
|
||||
return papers
|
||||
|
||||
Reference in New Issue
Block a user