123 lines
4.5 KiB
Python
123 lines
4.5 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify ApexCharts fix in admin evaluation dashboard
|
|
"""
|
|
import os
|
|
import django
|
|
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
|
django.setup()
|
|
|
|
from django.test import Client
|
|
from django.contrib.auth import get_user_model
|
|
from django.conf import settings
|
|
from apps.complaints.models import Complaint, Inquiry
|
|
from datetime import datetime, timedelta
|
|
|
|
User = get_user_model()
|
|
|
|
# Add testserver to ALLOWED_HOSTS for testing
|
|
if 'testserver' not in settings.ALLOWED_HOSTS:
|
|
settings.ALLOWED_HOSTS.append('testserver')
|
|
|
|
def test_admin_dashboard():
|
|
"""Test admin evaluation dashboard with seeded data"""
|
|
print("=" * 60)
|
|
print("Testing Admin Evaluation Dashboard with ApexCharts Fix")
|
|
print("=" * 60)
|
|
|
|
# Get admin users
|
|
admin_users = User.objects.filter(is_staff=True, username__in=['rahaf', 'abrar', 'amaal'])
|
|
|
|
if admin_users.count() < 3:
|
|
print(f"❌ Found only {admin_users.count()} admin users, need 3")
|
|
return False
|
|
|
|
print(f"\n✓ Found {admin_users.count()} admin users:")
|
|
for user in admin_users:
|
|
complaints_count = Complaint.objects.filter(assigned_to=user).count()
|
|
inquiries_count = Inquiry.objects.filter(assigned_to=user).count()
|
|
print(f" - {user.username}: {complaints_count} complaints, {inquiries_count} inquiries")
|
|
|
|
# Test dashboard for each admin
|
|
client = Client()
|
|
|
|
for user in admin_users:
|
|
print(f"\n{'='*60}")
|
|
print(f"Testing dashboard for: {user.username}")
|
|
print('='*60)
|
|
|
|
# Login as user
|
|
client.force_login(user)
|
|
|
|
# Try to access admin evaluation dashboard
|
|
try:
|
|
response = client.get('/admin-evaluation/')
|
|
|
|
if response.status_code == 200:
|
|
print(f"✓ Successfully loaded admin evaluation dashboard (Status: {response.status_code})")
|
|
|
|
# Check if performance data is present
|
|
content = response.content.decode('utf-8')
|
|
|
|
if 'performanceData' in content:
|
|
print("✓ Performance data found in template")
|
|
|
|
# Check if ApexCharts script is loaded
|
|
if 'apexcharts' in content.lower():
|
|
print("✓ ApexCharts library is included")
|
|
else:
|
|
print("❌ ApexCharts library not found in template")
|
|
return False
|
|
|
|
# Check if chart elements exist
|
|
chart_elements = [
|
|
'complaintSourceChart',
|
|
'complaintStatusChart',
|
|
'complaintActivationChart',
|
|
'complaintResponseChart',
|
|
'inquiryStatusChart',
|
|
'inquiryResponseChart'
|
|
]
|
|
|
|
missing_charts = []
|
|
for chart_id in chart_elements:
|
|
if chart_id in content:
|
|
print(f"✓ Chart element found: {chart_id}")
|
|
else:
|
|
print(f"❌ Chart element missing: {chart_id}")
|
|
missing_charts.append(chart_id)
|
|
|
|
if missing_charts:
|
|
print(f"❌ Missing {len(missing_charts)} chart elements")
|
|
return False
|
|
else:
|
|
print(f"✓ All {len(chart_elements)} chart elements present")
|
|
|
|
else:
|
|
print("❌ Performance data not found in template")
|
|
return False
|
|
|
|
else:
|
|
print(f"❌ Failed to load dashboard (Status: {response.status_code})")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error accessing dashboard: {str(e)}")
|
|
return False
|
|
|
|
print(f"\n{'='*60}")
|
|
print("✓ ALL TESTS PASSED!")
|
|
print('='*60)
|
|
print("\nNext Steps:")
|
|
print("1. Start the development server: python manage.py runserver")
|
|
print("2. Login as any admin user (rahaf/abrar/amaal)")
|
|
print("3. Navigate to: http://localhost:8000/admin-evaluation/")
|
|
print("4. Check browser console for any JavaScript errors")
|
|
print("5. Verify all 6 charts render correctly")
|
|
|
|
return True
|
|
|
|
if __name__ == '__main__':
|
|
success = test_admin_dashboard()
|
|
exit(0 if success else 1) |