初始化提交
This commit is contained in:
commit
887c1f449e
963 files changed
+166869
No files matched your search
@@ -0,0 +1,62 @@
|
||||
"""太一枢目标数据访问测试(per-character 查询 + 进度更新)。"""
|
||||
|
||||
import pytest
|
||||
|
||||
from app.db.session import AsyncSessionLocal
|
||||
from app.models.governance import Goal
|
||||
from app.repositories import governance as repo
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_goals_by_character() -> None:
|
||||
"""返回指定 character_id 的目标列表。"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
g1 = Goal(id="goal_1", title="t1", level="task", character_id="char_a")
|
||||
g2 = Goal(id="goal_2", title="t2", level="task", character_id="char_b")
|
||||
session.add_all([g1, g2])
|
||||
await session.flush()
|
||||
|
||||
goals = await repo.list_goals_by_character(session, "char_a")
|
||||
assert len(goals) == 1
|
||||
assert goals[0].id == "goal_1"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_goals_by_character_filters_status() -> None:
|
||||
"""按 status 过滤指定角色的目标。"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
g1 = Goal(id="goal_3", title="t3", level="task", character_id="char_c", status="active")
|
||||
g2 = Goal(
|
||||
id="goal_4",
|
||||
title="t4",
|
||||
level="task",
|
||||
character_id="char_c",
|
||||
status="completed",
|
||||
)
|
||||
session.add_all([g1, g2])
|
||||
await session.flush()
|
||||
|
||||
goals = await repo.list_goals_by_character(session, "char_c", status_filter="active")
|
||||
assert len(goals) == 1
|
||||
assert goals[0].id == "goal_3"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_goal_progress() -> None:
|
||||
"""更新目标的 progress 字段。"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
goal = Goal(id="goal_5", title="t5", level="task")
|
||||
session.add(goal)
|
||||
await session.flush()
|
||||
|
||||
updated = await repo.update_goal_progress(session, "goal_5", 0.75)
|
||||
assert updated is not None
|
||||
assert updated.progress == 0.75
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_update_goal_progress_nonexistent() -> None:
|
||||
"""更新不存在的目标返回 None。"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
result = await repo.update_goal_progress(session, "goal_nonexistent", 0.5)
|
||||
assert result is None
|
||||
Reference in new issue
Block a user