75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Direct test of category loading without HTTP client
|
|
"""
|
|
import os
|
|
import django
|
|
import sys
|
|
|
|
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 RequestFactory
|
|
from apps.complaints.ui_views import api_load_categories
|
|
from apps.complaints.models import ComplaintCategory
|
|
|
|
factory = RequestFactory()
|
|
|
|
print('=' * 60)
|
|
print('Testing API Load Categories View Directly')
|
|
print('=' * 60)
|
|
|
|
# Test 1: Without hospital_id
|
|
print('\n1. Testing without hospital_id (system-wide categories):')
|
|
print('-' * 60)
|
|
|
|
request = factory.get('/complaints/public/api/load-categories/')
|
|
response = api_load_categories(request)
|
|
|
|
print(f'Status Code: {response.status_code}')
|
|
|
|
if response.status_code == 200:
|
|
import json
|
|
data = json.loads(response.content)
|
|
print(f'✓ Response is JSON')
|
|
print(f'✓ Total categories: {len(data.get("categories", []))}')
|
|
|
|
categories = data.get('categories', [])
|
|
if categories:
|
|
print(f'\nSample categories:')
|
|
for cat in categories[:5]:
|
|
print(f' - ID: {cat["id"]}, Level: {cat["level"]}, Name: {cat["name_en"]}')
|
|
|
|
level_counts = {}
|
|
for cat in categories:
|
|
level = cat['level']
|
|
level_counts[level] = level_counts.get(level, 0) + 1
|
|
|
|
print(f'\nCategories by level:')
|
|
for level in sorted(level_counts.keys()):
|
|
print(f' - Level {level}: {level_counts[level]} categories')
|
|
else:
|
|
print('✗ No categories returned!')
|
|
else:
|
|
print(f'✗ Failed to get response: {response.status_code}')
|
|
print(f'Response: {response.content.decode()[:500]}')
|
|
|
|
# Test 2: With hospital_id
|
|
print('\n\n2. Testing with hospital_id:')
|
|
print('-' * 60)
|
|
|
|
request = factory.get('/complaints/public/api/load-categories/', {'hospital_id': '12345'})
|
|
response = api_load_categories(request)
|
|
|
|
print(f'Status Code: {response.status_code}')
|
|
|
|
if response.status_code == 200:
|
|
import json
|
|
data = json.loads(response.content)
|
|
print(f'✓ Response is JSON')
|
|
print(f'✓ Total categories: {len(data.get("categories", []))}')
|
|
|
|
print('\n' + '=' * 60)
|
|
print('Test Complete!')
|
|
print('=' * 60) |