157 lines
5.9 KiB
Python
157 lines
5.9 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script for admin evaluation dashboard
|
|
"""
|
|
import os
|
|
import django
|
|
import sys
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
sys.path.insert(0, '/home/ismail/projects/HH')
|
|
django.setup()
|
|
|
|
from django.test import RequestFactory
|
|
from django.contrib.auth import get_user_model
|
|
from apps.dashboard.views import admin_evaluation
|
|
|
|
User = get_user_model()
|
|
|
|
def test_admin_evaluation_view():
|
|
"""Test the admin evaluation view"""
|
|
print("=" * 60)
|
|
print("Testing Admin Evaluation Dashboard")
|
|
print("=" * 60)
|
|
|
|
# Get one of the test admin users
|
|
admin_user = User.objects.filter(username='rahaf').first()
|
|
|
|
if not admin_user:
|
|
print("❌ Admin user 'rahaf' not found!")
|
|
return False
|
|
|
|
print(f"\n✅ Found admin user: {admin_user.username}")
|
|
print(f" Email: {admin_user.email}")
|
|
print(f" Role: {admin_user.role}")
|
|
|
|
# Create a fake request
|
|
factory = RequestFactory()
|
|
request = factory.get('/admin-evaluation/')
|
|
request.user = admin_user
|
|
|
|
try:
|
|
# Call the view
|
|
print("\n📊 Calling admin_evaluation view...")
|
|
response = admin_evaluation(request)
|
|
|
|
print(f"✅ View executed successfully!")
|
|
print(f" Status code: {response.status_code}")
|
|
|
|
# Check response data
|
|
if hasattr(response, 'context_data'):
|
|
context = response.context_data
|
|
|
|
if 'performance_data' in context:
|
|
perf_data = context['performance_data']
|
|
print(f"\n✅ Performance data found")
|
|
print(f" Staff metrics count: {len(perf_data.get('staff_metrics', []))}")
|
|
print(f" Start date: {perf_data.get('start_date')}")
|
|
print(f" End date: {perf_data.get('end_date')}")
|
|
print(f" Date range: {perf_data.get('date_range')}")
|
|
|
|
# Display staff metrics
|
|
staff_metrics = perf_data.get('staff_metrics', [])
|
|
if staff_metrics:
|
|
print(f"\n📈 Staff Performance:")
|
|
for staff in staff_metrics:
|
|
print(f"\n - {staff['name']}")
|
|
print(f" Hospital: {staff['hospital']}")
|
|
print(f" Department: {staff['department']}")
|
|
print(f" Complaints: {staff['complaints']['total']}")
|
|
print(f" Inquiries: {staff['inquiries']['total']}")
|
|
|
|
# Complaint breakdown
|
|
comp = staff['complaints']
|
|
if comp['total'] > 0:
|
|
print(f" Status: Open={comp['status']['open']}, "
|
|
f"In Progress={comp['status']['in_progress']}, "
|
|
f"Resolved={comp['status']['resolved']}, "
|
|
f"Closed={comp['status']['closed']}")
|
|
print(f" Activation (≤2h): {comp['activation_time']['within_2h']}, "
|
|
f"(>2h): {comp['activation_time']['more_than_2h']}")
|
|
else:
|
|
print(f" No complaints assigned")
|
|
|
|
# Inquiry breakdown
|
|
inq = staff['inquiries']
|
|
if inq['total'] > 0:
|
|
print(f" Status: Open={inq['status']['open']}, "
|
|
f"In Progress={inq['status']['in_progress']}, "
|
|
f"Resolved={inq['status']['resolved']}, "
|
|
f"Closed={inq['status']['closed']}")
|
|
else:
|
|
print(f" No inquiries assigned")
|
|
|
|
return True
|
|
else:
|
|
print("❌ 'performance_data' not found in context")
|
|
return False
|
|
else:
|
|
print("❌ Response has no context_data")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"\n❌ Error executing view:")
|
|
print(f" {type(e).__name__}: {str(e)}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return False
|
|
|
|
def check_test_data():
|
|
"""Check that test data exists"""
|
|
print("\n" + "=" * 60)
|
|
print("Checking Test Data")
|
|
print("=" * 60)
|
|
|
|
from apps.complaints.models import Complaint, Inquiry
|
|
from apps.accounts.models import User
|
|
|
|
# Check admin users
|
|
admin_users = User.objects.filter(role='admin')
|
|
print(f"\n👥 Admin users: {admin_users.count()}")
|
|
for user in admin_users:
|
|
print(f" - {user.username} ({user.email})")
|
|
|
|
# Check complaints
|
|
complaints = Complaint.objects.filter(assigned_to__role='admin')
|
|
print(f"\n📝 Total complaints assigned to admins: {complaints.count()}")
|
|
for user in admin_users:
|
|
user_complaints = complaints.filter(assigned_to=user)
|
|
print(f" - {user.username}: {user_complaints.count()} complaints")
|
|
|
|
# Check inquiries
|
|
inquiries = Inquiry.objects.filter(assigned_to__role='admin')
|
|
print(f"\n❓ Total inquiries assigned to admins: {inquiries.count()}")
|
|
for user in admin_users:
|
|
user_inquiries = inquiries.filter(assigned_to=user)
|
|
print(f" - {user.username}: {user_inquiries.count()} inquiries")
|
|
|
|
return True
|
|
|
|
if __name__ == '__main__':
|
|
print("\n🚀 Admin Evaluation Dashboard Test\n")
|
|
|
|
# First check test data
|
|
check_test_data()
|
|
|
|
# Then test the view
|
|
success = test_admin_evaluation_view()
|
|
|
|
print("\n" + "=" * 60)
|
|
if success:
|
|
print("✅ All tests passed!")
|
|
print(" The admin evaluation dashboard is working correctly.")
|
|
else:
|
|
print("❌ Tests failed!")
|
|
print(" Please check the error messages above.")
|
|
print("=" * 60 + "\n") |