45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
"""
|
|
tests/services/admin/test_dashboard_service.py
|
|
|
|
用途:dashboard_service 统计聚合单元测试。
|
|
"""
|
|
from app import db
|
|
from app.models import Agent, ChatLog, Feedback, PermissionRequest, User
|
|
from app.services.admin.dashboard_service import (
|
|
compute_dashboard_badges,
|
|
compute_dashboard_summary,
|
|
compute_legacy_dashboard_stats,
|
|
)
|
|
|
|
|
|
def test_compute_dashboard_summary_empty(app):
|
|
with app.app_context():
|
|
summary = compute_dashboard_summary()
|
|
assert summary['agent_count'] == 0
|
|
assert summary['user_count'] == 0
|
|
assert summary['total_conversations'] == 0
|
|
assert summary['avg_score'] == 0.0
|
|
|
|
|
|
def test_compute_dashboard_badges_counts_pending(app):
|
|
with app.app_context():
|
|
user = User(username='pending-u', email='p@example.com', status='pending', role='user')
|
|
agent = Agent(name='a1', is_active=True)
|
|
db.session.add_all([user, agent])
|
|
db.session.flush()
|
|
req = PermissionRequest(user_id=user.id, agent_id=agent.id, status='pending', reason='test')
|
|
db.session.add(req)
|
|
db.session.commit()
|
|
|
|
badges = compute_dashboard_badges()
|
|
assert badges['pending_approvals'] >= 1
|
|
assert badges['pending_requests'] >= 1
|
|
|
|
|
|
def test_compute_legacy_dashboard_stats_keys(app):
|
|
with app.app_context():
|
|
stats = compute_legacy_dashboard_stats()
|
|
assert 'total_users' in stats
|
|
assert 'pending_approvals' in stats
|
|
assert 'pending_requests' in stats
|