7ec4fb0747
- LLM 客户端:全部 SSE 流式输出,兼容 OpenAI 接口
- AI 月报解析:SSE 流式端点 POST /reports/{id}/parse
- 健康度计算引擎:四维评分(财务/经营/AI商业化/AI成本)
- 风险自动检测引擎:6 条规则自动检测指标越界
- AI Copilot:SSE 流式对话 POST /copilot/chat
- 权限中间件:角色级 + 字段级权限控制
- 测试:21 个新测试(健康度 8 + 风险检测 8 + 权限 5),总计 64 passed
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
"""权限中间件测试。"""
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from app.core.permissions import filter_fields, require_min_role, require_role, ROLE_HIERARCHY
|
|
|
|
|
|
class TestRoleHierarchy:
|
|
"""角色层级。"""
|
|
|
|
def test_admin_highest(self):
|
|
assert ROLE_HIERARCHY["admin"] > ROLE_HIERARCHY["investor"]
|
|
assert ROLE_HIERARCHY["admin"] > ROLE_HIERARCHY["founder"]
|
|
|
|
def test_investor_above_founder(self):
|
|
assert ROLE_HIERARCHY["investor"] > ROLE_HIERARCHY["founder"]
|
|
|
|
|
|
class TestFilterFields:
|
|
"""字段级权限过滤。"""
|
|
|
|
def test_investor_sees_all(self):
|
|
"""investor 可见全部字段。"""
|
|
data = {"name": "公司A", "total_funding": "1亿", "description": "测试"}
|
|
user = SimpleNamespace(role="investor")
|
|
result = filter_fields("company", data, user)
|
|
assert result == data
|
|
|
|
def test_founder_filtered(self):
|
|
"""founder 只能看限定字段。"""
|
|
data = {"name": "公司A", "total_funding": "1亿", "description": "测试", "id": "123"}
|
|
user = SimpleNamespace(role="founder")
|
|
result = filter_fields("company", data, user)
|
|
assert "name" in result
|
|
assert "id" in result
|
|
assert "total_funding" not in result
|
|
|
|
def test_admin_sees_all(self):
|
|
"""admin 可见全部字段。"""
|
|
data = {"name": "公司A", "total_funding": "1亿"}
|
|
user = SimpleNamespace(role="admin")
|
|
result = filter_fields("company", data, user)
|
|
assert result == data
|