130 lines
4.4 KiB
Python
130 lines
4.4 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test the admin evaluation page with seeded data.
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
|
sys.path.insert(0, '/home/ismail/projects/HH')
|
|
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
|
|
|
|
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_evaluation_page():
|
|
"""Test the admin evaluation page loads and has data."""
|
|
print("=" * 70)
|
|
print("Testing Admin Evaluation Page")
|
|
print("=" * 70)
|
|
|
|
# Get an admin user
|
|
admin_user = User.objects.filter(username='rahaf', is_staff=True).first()
|
|
if not admin_user:
|
|
print("\n❌ Admin user 'rahaf' not found. Please run seed_admin_test_data.py first.")
|
|
return False
|
|
|
|
print(f"\n✓ Using admin user: {admin_user.get_full_name()}")
|
|
|
|
# Count complaints and inquiries
|
|
total_complaints = Complaint.objects.count()
|
|
total_inquiries = Inquiry.objects.count()
|
|
|
|
print(f"\n✓ Total complaints in database: {total_complaints}")
|
|
print(f"✓ Total inquiries in database: {total_inquiries}")
|
|
|
|
if total_complaints == 0 and total_inquiries == 0:
|
|
print("\n❌ No test data found. Please run seed_admin_test_data.py first.")
|
|
return False
|
|
|
|
# Test the page
|
|
client = Client()
|
|
client.force_login(admin_user)
|
|
|
|
print(f"\n✓ Admin user logged in")
|
|
|
|
# Test the admin evaluation endpoint
|
|
response = client.get('/admin-evaluation/')
|
|
|
|
if response.status_code == 200:
|
|
print(f"\n✓ Admin evaluation page loaded successfully (status: {response.status_code})")
|
|
else:
|
|
print(f"\n❌ Admin evaluation page failed to load (status: {response.status_code})")
|
|
return False
|
|
|
|
# Check for key elements in the response
|
|
content = response.content.decode('utf-8')
|
|
|
|
checks = [
|
|
('ApexCharts CDN', 'cdn.jsdelivr.net/npm/apexcharts'),
|
|
('Performance data script', 'id="performanceData"'),
|
|
('Complaint Source Chart', 'id="complaintSourceChart"'),
|
|
('Complaint Status Chart', 'id="complaintStatusChart"'),
|
|
('Complaint Activation Chart', 'id="complaintActivationChart"'),
|
|
('Complaint Response Chart', 'id="complaintResponseChart"'),
|
|
('Inquiry Status Chart', 'id="inquiryStatusChart"'),
|
|
('Inquiry Response Chart', 'id="inquiryResponseChart"'),
|
|
('renderChart function', 'function renderChart(elementId, options)'),
|
|
('Inquiry tab listener', 'shown.bs.tab'),
|
|
]
|
|
|
|
print("\n" + "-" * 70)
|
|
print("Checking page elements:")
|
|
print("-" * 70)
|
|
|
|
all_passed = True
|
|
for name, pattern in checks:
|
|
if pattern in content:
|
|
print(f"✓ {name} found")
|
|
else:
|
|
print(f"❌ {name} NOT found")
|
|
all_passed = False
|
|
|
|
# Check for performance data
|
|
print("\n" + "-" * 70)
|
|
print("Checking performance data:")
|
|
print("-" * 70)
|
|
|
|
if 'staff_metrics' in content:
|
|
print("✓ Staff metrics data found in page")
|
|
|
|
# Try to extract staff count
|
|
if 'staff_metrics' in content and 'total' in content.lower():
|
|
print("✓ Performance metrics appear to be populated")
|
|
else:
|
|
print("❌ Staff metrics data NOT found in page")
|
|
all_passed = False
|
|
|
|
# Summary
|
|
print("\n" + "=" * 70)
|
|
if all_passed:
|
|
print("✅ ALL TESTS PASSED!")
|
|
print("\nThe admin evaluation page is ready to use:")
|
|
print(" - Page loads successfully")
|
|
print(" - All chart containers are present")
|
|
print(" - ApexCharts library is loaded")
|
|
print(" - Performance data is included")
|
|
print(" - Chart initialization code is present")
|
|
print(" - Tab event listeners are configured")
|
|
print("\nTo view the page:")
|
|
print(f" 1. Login as {admin_user.username} (password: password123)")
|
|
print(" 2. Navigate to /dashboard/admin-evaluation/")
|
|
else:
|
|
print("❌ SOME TESTS FAILED - Please review the output above")
|
|
print("=" * 70)
|
|
|
|
return all_passed
|
|
|
|
if __name__ == '__main__':
|
|
success = test_admin_evaluation_page()
|
|
sys.exit(0 if success else 1) |