59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for the pagination route to verify error handling and browser cleanup.
|
|
"""
|
|
|
|
import asyncio
|
|
import aiohttp
|
|
import json
|
|
import sys
|
|
|
|
async def test_pagination(url, api_key):
|
|
"""Test the pagination endpoint with a given URL"""
|
|
async with aiohttp.ClientSession() as session:
|
|
headers = {"X-API-Key": api_key}
|
|
|
|
# Test URL with pagination
|
|
test_url = f"http://localhost:8000/pagination?url={url}"
|
|
|
|
print(f"Testing pagination for: {url}")
|
|
|
|
try:
|
|
async with session.get(test_url, headers=headers) as response:
|
|
if response.status == 200:
|
|
result = await response.json()
|
|
print(f"✅ Success: {json.dumps(result, indent=2)}")
|
|
return True
|
|
else:
|
|
error_text = await response.text()
|
|
print(f"❌ Error {response.status}: {error_text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Exception: {e}")
|
|
return False
|
|
|
|
async def main():
|
|
"""Main test function"""
|
|
# Test URLs - some with pagination, some without
|
|
test_urls = [
|
|
"https://example.com", # No pagination
|
|
"https://httpbin.org/get", # No pagination
|
|
"https://news.ycombinator.com", # Has pagination
|
|
]
|
|
|
|
api_key = "test-key" # Replace with your actual API key
|
|
|
|
print("Testing pagination route...")
|
|
print("=" * 50)
|
|
|
|
for url in test_urls:
|
|
success = await test_pagination(url, api_key)
|
|
print("-" * 30)
|
|
|
|
# Small delay between tests
|
|
await asyncio.sleep(1)
|
|
|
|
print("Test completed!")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |