140 lines
4.5 KiB
Python
140 lines
4.5 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify admin evaluation page loads and charts render correctly.
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
import time
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
sys.path.insert(0, '/home/ismail/projects/HH')
|
|
django.setup()
|
|
|
|
from django.test import Client
|
|
from apps.accounts.models import User
|
|
|
|
def test_admin_evaluation_charts():
|
|
"""Test that admin evaluation page loads with chart data."""
|
|
print("=" * 70)
|
|
print("Testing Admin Evaluation Page with Charts")
|
|
print("=" * 70)
|
|
|
|
# Get an admin user
|
|
admin = User.objects.filter(
|
|
username__in=['rahaf_admin', 'abrar_admin', 'amaal_admin']
|
|
).first()
|
|
|
|
if not admin:
|
|
print("\n❌ No admin user found. Please run seed_admin_test_data first.")
|
|
return False
|
|
|
|
print(f"\n✓ Using admin user: {admin.username}")
|
|
|
|
# Create client and login
|
|
client = Client()
|
|
logged_in = client.login(username=admin.username, password='Admin123!@#')
|
|
|
|
if not logged_in:
|
|
print(f"❌ Failed to login as {admin.username}")
|
|
return False
|
|
|
|
print(f"✓ Successfully logged in as {admin.username}")
|
|
|
|
# Test page load
|
|
print("\n" + "-" * 70)
|
|
print("Testing Admin Evaluation Page Load")
|
|
print("-" * 70)
|
|
|
|
response = client.get('/dashboard/admin-evaluation/')
|
|
|
|
print(f"✓ Response status: {response.status_code}")
|
|
|
|
if response.status_code != 200:
|
|
print(f"❌ Expected 200, got {response.status_code}")
|
|
return False
|
|
|
|
# Check for chart containers in response
|
|
content = response.content.decode('utf-8')
|
|
|
|
chart_checks = [
|
|
('complaintSourceChart', 'Complaint Source Chart'),
|
|
('complaintStatusChart', 'Complaint Status Chart'),
|
|
('complaintActivationChart', 'Complaint Activation Chart'),
|
|
('complaintResponseChart', 'Complaint Response Chart'),
|
|
('inquiryStatusChart', 'Inquiry Status Chart'),
|
|
('inquiryResponseChart', 'Inquiry Response Chart'),
|
|
]
|
|
|
|
print("\n" + "-" * 70)
|
|
print("Checking Chart Containers")
|
|
print("-" * 70)
|
|
|
|
all_charts_found = True
|
|
for chart_id, chart_name in chart_checks:
|
|
if chart_id in content:
|
|
print(f"✓ {chart_name} container found")
|
|
else:
|
|
print(f"❌ {chart_name} container NOT found")
|
|
all_charts_found = False
|
|
|
|
# Check for ApexCharts library
|
|
print("\n" + "-" * 70)
|
|
print("Checking ApexCharts Library")
|
|
print("-" * 70)
|
|
|
|
if 'apexcharts' in content:
|
|
print("✓ ApexCharts CDN imported")
|
|
else:
|
|
print("❌ ApexCharts CDN NOT imported")
|
|
all_charts_found = False
|
|
|
|
# Check for performance data
|
|
print("\n" + "-" * 70)
|
|
print("Checking Performance Data")
|
|
print("-" * 70)
|
|
|
|
if 'performanceData' in content:
|
|
print("✓ Performance data script found")
|
|
|
|
# Try to extract and parse the data
|
|
import json
|
|
import re
|
|
|
|
# Find the JSON data in the script tag
|
|
match = re.search(r'<script id="performanceData" type="application/json">(.*?)</script>', content, re.DOTALL)
|
|
if match:
|
|
try:
|
|
data = json.loads(match.group(1))
|
|
print(f"✓ Performance data parsed successfully")
|
|
print(f" - Staff metrics count: {len(data.get('staff_metrics', []))}")
|
|
|
|
if data.get('staff_metrics'):
|
|
first_staff = data['staff_metrics'][0]
|
|
print(f" - First staff: {first_staff.get('name')}")
|
|
print(f" - Complaints: {first_staff.get('complaints', {})}")
|
|
print(f" - Inquiries: {first_staff.get('inquiries', {})}")
|
|
|
|
except json.JSONDecodeError as e:
|
|
print(f"❌ Failed to parse performance data JSON: {e}")
|
|
all_charts_found = False
|
|
else:
|
|
print("⚠ Could not extract JSON data (but script tag exists)")
|
|
else:
|
|
print("❌ Performance data script NOT found")
|
|
all_charts_found = False
|
|
|
|
# Summary
|
|
print("\n" + "=" * 70)
|
|
if all_charts_found:
|
|
print("✅ ALL CHECKS PASSED - Charts should render correctly!")
|
|
else:
|
|
print("❌ SOME CHECKS FAILED - Please review the output above")
|
|
print("=" * 70)
|
|
|
|
return all_charts_found
|
|
|
|
if __name__ == '__main__':
|
|
success = test_admin_evaluation_charts()
|
|
sys.exit(0 if success else 1) |