Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
dde25344ca
9 files changed
+110
-19
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
tests/services/admin/test_report_service.py
|
||||
|
||||
用途:report_service 报表聚合单元测试(使用分析、应用运营、反馈)。
|
||||
用途:report_service 报表聚合单元测试(使用分析含零使用低使用应用、应用运营、反馈)。
|
||||
"""
|
||||
from app import db
|
||||
from app.models import Agent, ChatLog, Feedback, User
|
||||
@@ -32,6 +32,37 @@ def test_build_usage_report(app):
|
||||
assert data['by_day'][0]['count'] == 1
|
||||
|
||||
|
||||
def test_build_usage_report_low_agents_includes_zero_usage(app):
|
||||
"""
|
||||
低使用应用须含启用且零对话的 Agent(与应用运营零使用对齐)。
|
||||
断言:cold-app 出现在 low_agents 且 count=0;停用应用不计入。
|
||||
"""
|
||||
with app.app_context():
|
||||
used = Agent(name='hot-app', type='api', dify_app_id='app-hot', dify_api_key='key-hot', is_active=True)
|
||||
cold = Agent(name='cold-app', type='api', dify_app_id='app-cold', dify_api_key='key-cold', is_active=True)
|
||||
inactive = Agent(
|
||||
name='off-app',
|
||||
type='api',
|
||||
dify_app_id='app-off',
|
||||
dify_api_key='key-off',
|
||||
is_active=False,
|
||||
)
|
||||
user = User(username='low-user', email='low@example.com', role='user')
|
||||
db.session.add_all([used, cold, inactive, user])
|
||||
db.session.flush()
|
||||
db.session.add(ChatLog(user_id=user.id, agent_id=used.id, query='hi', answer='ok', tokens_used=1))
|
||||
db.session.commit()
|
||||
|
||||
data = report_service.build_usage_report(user_page=1, user_page_size=10, range_key='30d')
|
||||
# by_agent 仅含有对话的应用
|
||||
assert all(item['agent'] != 'cold-app' for item in data['by_agent'])
|
||||
low_names = {item['agent']: item['count'] for item in data['low_agents']}
|
||||
assert low_names.get('cold-app') == 0
|
||||
assert 'off-app' not in low_names
|
||||
assert data['low_agent_max_chats'] == report_service.USAGE_LOW_AGENT_MAX_CHATS
|
||||
assert data['low_agent_list_limit'] == report_service.USAGE_LOW_AGENT_LIST_LIMIT
|
||||
|
||||
|
||||
def test_build_usage_report_excludes_outside_range(app):
|
||||
"""超出所选时间范围的聊天日志不计入统计。"""
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
Reference in new issue
Block a user