You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
4.6 KiB
118 lines
4.6 KiB
#!/usr/bin/env python
|
|
"""
|
|
Simple script to test hadis API endpoints connectivity.
|
|
This script manually tests all hadis URLs to verify they return proper HTTP status codes.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import django
|
|
from django.conf import settings
|
|
from django.test import override_settings
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.base')
|
|
django.setup()
|
|
|
|
from django.test import Client
|
|
from django.urls import reverse
|
|
from rest_framework import status
|
|
|
|
|
|
def test_endpoint(client, url_name, kwargs=None, description=""):
|
|
"""Test a single endpoint and return the result"""
|
|
try:
|
|
if kwargs:
|
|
url = reverse(url_name, kwargs=kwargs)
|
|
else:
|
|
url = reverse(url_name)
|
|
|
|
response = client.get(url)
|
|
status_code = response.status_code
|
|
|
|
if status_code in [status.HTTP_200_OK, status.HTTP_404_NOT_FOUND]:
|
|
result = "✅ PASS"
|
|
else:
|
|
result = f"❌ FAIL ({status_code})"
|
|
|
|
print(f"{result} {description}: {url} -> {status_code}")
|
|
return status_code in [status.HTTP_200_OK, status.HTTP_404_NOT_FOUND]
|
|
|
|
except Exception as e:
|
|
print(f"❌ ERROR {description}: {url_name} -> {str(e)}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Main test function"""
|
|
print("🧪 Testing Hadis API Endpoints Connectivity")
|
|
print("=" * 60)
|
|
|
|
# Override ALLOWED_HOSTS for testing
|
|
with override_settings(ALLOWED_HOSTS=['testserver']):
|
|
client = Client()
|
|
total_tests = 0
|
|
passed_tests = 0
|
|
|
|
# Test non-parameterized endpoints
|
|
print("\n📋 Testing non-parameterized endpoints:")
|
|
non_param_endpoints = [
|
|
('hadis-collection-list', None, 'Collections'),
|
|
('hadis-sect-list', None, 'Sync Sects'),
|
|
('hadis-category-tree', None, 'Sync Categories Tree'),
|
|
('hadis-sync', None, 'Sync Hadis'),
|
|
('transmitter-sync', None, 'Sync Narrators'),
|
|
('reference-sync', None, 'Sync References'),
|
|
('hadis-info', None, 'Info'),
|
|
('hadis-category-tree-normal', None, 'Categories Tree Normal'),
|
|
('categories', None, 'Categories'),
|
|
('hadis-main-list', None, 'Hadis Main List (Arguments)'),
|
|
('hadis-filters', None, 'Hadis Filters'),
|
|
('narrator-filters', None, 'Narrator Filters'),
|
|
('narrators', None, 'Narrators'),
|
|
('references', None, 'References'),
|
|
]
|
|
|
|
for url_name, kwargs, description in non_param_endpoints:
|
|
total_tests += 1
|
|
if test_endpoint(client, url_name, kwargs, description):
|
|
passed_tests += 1
|
|
|
|
# Test parameterized endpoints
|
|
print("\n📋 Testing parameterized endpoints:")
|
|
param_endpoints = [
|
|
('categories-by-sect', {'sect_type': '1'}, 'Categories by Sect (type=1)'),
|
|
('categories-tree-by-sect', {'sect_type': '1', 'slug': 'test-category'}, 'Categories Tree by Sect'),
|
|
('categories-tree-by-sect-source', {'sect_type': '1', 'slug': 'test-category', 'source_type': 'quran'}, 'Categories Tree by Sect Source'),
|
|
('hadis-list', {'category_slug': 'test-category'}, 'Hadis List by Category'),
|
|
('narrator-detail', {'narrator_slug': 'test-narrator'}, 'Narrator Detail'),
|
|
('narrator-opinions', {'narrator_slug': 'test-narrator'}, 'Narrator Opinions'),
|
|
('narrator-original-texts', {'narrator_slug': 'test-narrator'}, 'Narrator Original Texts'),
|
|
('reference-detail', {'reference_slug': 'test-reference'}, 'Reference Detail'),
|
|
('hadis-basic', {'hadis_slug': 'test-hadis'}, 'Hadis Basic'),
|
|
('hadis-detail', {'hadis_slug': 'test-hadis'}, 'Hadis Detail'),
|
|
('hadis-transmitters', {'hadis_slug': 'test-hadis'}, 'Hadis Transmitters'),
|
|
('hadis-corrections', {'hadis_slug': 'test-hadis'}, 'Hadis Corrections'),
|
|
]
|
|
|
|
for url_name, kwargs, description in param_endpoints:
|
|
total_tests += 1
|
|
if test_endpoint(client, url_name, kwargs, description):
|
|
passed_tests += 1
|
|
|
|
# Summary
|
|
print("\n" + "=" * 60)
|
|
print(f"📊 Test Results: {passed_tests}/{total_tests} endpoints accessible")
|
|
success_rate = (passed_tests / total_tests) * 100 if total_tests > 0 else 0
|
|
print(f"📈 Success Rate: {success_rate:.1f}%")
|
|
if passed_tests == total_tests:
|
|
print("✅ All endpoints are properly configured and accessible!")
|
|
else:
|
|
print("⚠️ Some endpoints may have issues")
|
|
|
|
return passed_tests == total_tests
|
|
|
|
|
|
if __name__ == '__main__':
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|