118 lines
3.8 KiB
Python
118 lines
3.8 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to diagnose domain dropdown issue.
|
|
This simulates what happens when the public complaint form loads.
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
django.setup()
|
|
|
|
from django.test import Client
|
|
from django.urls import reverse
|
|
|
|
print("=" * 80)
|
|
print("TESTING DOMAIN DROPDOWN ISSUE")
|
|
print("=" * 80)
|
|
|
|
# Create a test client
|
|
client = Client()
|
|
|
|
# Test 1: Check if the URL is accessible
|
|
print("\n1. Testing API URL accessibility...")
|
|
try:
|
|
url = reverse('complaints:api_load_categories')
|
|
print(f" URL generated: {url}")
|
|
print(f" ✓ URL generated successfully")
|
|
except Exception as e:
|
|
print(f" ✗ URL generation failed: {e}")
|
|
sys.exit(1)
|
|
|
|
# Test 2: Test the API endpoint
|
|
print("\n2. Testing API endpoint...")
|
|
try:
|
|
response = client.get(url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
|
print(f" Status code: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
import json
|
|
data = json.loads(response.content)
|
|
print(f" ✓ API returns valid JSON")
|
|
print(f" Categories returned: {len(data['categories'])}")
|
|
|
|
# Count levels
|
|
level_counts = {}
|
|
for cat in data['categories']:
|
|
level = cat['level']
|
|
level_counts[level] = level_counts.get(level, 0) + 1
|
|
|
|
print(f" Categories by level:")
|
|
for level in sorted(level_counts.keys()):
|
|
print(f" Level {level}: {level_counts[level]} categories")
|
|
else:
|
|
print(f" ✗ API returned error status: {response.status_code}")
|
|
print(f" Response content: {response.content}")
|
|
except Exception as e:
|
|
print(f" ✗ API call failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
# Test 3: Test the public complaint form page
|
|
print("\n3. Testing public complaint form page...")
|
|
try:
|
|
form_url = reverse('complaints:public_complaint_submit')
|
|
print(f" Form URL: {form_url}")
|
|
|
|
response = client.get(form_url)
|
|
print(f" Status code: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
print(f" ✓ Form page loads successfully")
|
|
|
|
# Check for jQuery in response
|
|
content = response.content.decode('utf-8')
|
|
|
|
# Check for jQuery loading
|
|
if 'jquery' in content.lower():
|
|
print(f" ✓ jQuery is referenced in page")
|
|
|
|
# Check for loadDomains function
|
|
if 'loadDomains' in content:
|
|
print(f" ✓ loadDomains function is defined")
|
|
|
|
# Check for API URL reference
|
|
if 'api_load_categories' in content:
|
|
print(f" ✓ API endpoint is referenced")
|
|
|
|
# Check for document.ready
|
|
if '$(document).ready' in content:
|
|
print(f" ✓ jQuery document ready handler is present")
|
|
|
|
# Check if loadDomains is called on page load
|
|
if "loadDomains('')" in content:
|
|
print(f" ✓ loadDomains is called on page initialization")
|
|
else:
|
|
print(f" ✗ Form page returned error: {response.status_code}")
|
|
except Exception as e:
|
|
print(f" ✗ Form page load failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
# Test 4: Check hospitals are available
|
|
print("\n4. Checking hospital data...")
|
|
try:
|
|
from apps.organizations.models import Hospital
|
|
hospitals = Hospital.objects.filter(status='active').order_by('name')
|
|
print(f" Active hospitals: {hospitals.count()}")
|
|
for hospital in hospitals[:5]:
|
|
print(f" - {hospital.name} (ID: {hospital.id})")
|
|
except Exception as e:
|
|
print(f" ✗ Failed to get hospitals: {e}")
|
|
|
|
print("\n" + "=" * 80)
|
|
print("TEST COMPLETE")
|
|
print("=" * 80) |