Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /ruvnet_RuView /archive /v1 /test_application.py
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify WiFi-DensePose API functionality | |
| """ | |
| import asyncio | |
| import aiohttp | |
| import json | |
| import websockets | |
| import sys | |
| from typing import Dict, Any | |
| BASE_URL = "http://localhost:8000" | |
| WS_URL = "ws://localhost:8000" | |
| async def test_health_endpoints(): | |
| """Test health check endpoints.""" | |
| print("๐ Testing health endpoints...") | |
| async with aiohttp.ClientSession() as session: | |
| # Test basic health | |
| async with session.get(f"{BASE_URL}/health/health") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Health check: {data['status']}") | |
| else: | |
| print(f"โ Health check failed: {response.status}") | |
| # Test readiness | |
| async with session.get(f"{BASE_URL}/health/ready") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| status = "ready" if data['ready'] else "not ready" | |
| print(f"โ Readiness check: {status}") | |
| else: | |
| print(f"โ Readiness check failed: {response.status}") | |
| # Test liveness | |
| async with session.get(f"{BASE_URL}/health/live") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Liveness check: {data['status']}") | |
| else: | |
| print(f"โ Liveness check failed: {response.status}") | |
| async def test_api_endpoints(): | |
| """Test main API endpoints.""" | |
| print("\n๐ Testing API endpoints...") | |
| async with aiohttp.ClientSession() as session: | |
| # Test root endpoint | |
| async with session.get(f"{BASE_URL}/") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Root endpoint: {data['name']} v{data['version']}") | |
| else: | |
| print(f"โ Root endpoint failed: {response.status}") | |
| # Test API info | |
| async with session.get(f"{BASE_URL}/api/v1/info") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ API info: {len(data['services'])} services configured") | |
| else: | |
| print(f"โ API info failed: {response.status}") | |
| # Test API status | |
| async with session.get(f"{BASE_URL}/api/v1/status") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ API status: {data['api']['status']}") | |
| else: | |
| print(f"โ API status failed: {response.status}") | |
| async def test_pose_endpoints(): | |
| """Test pose estimation endpoints.""" | |
| print("\n๐ Testing pose endpoints...") | |
| async with aiohttp.ClientSession() as session: | |
| # Test current pose data | |
| async with session.get(f"{BASE_URL}/api/v1/pose/current") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Current pose data: {len(data.get('poses', []))} poses detected") | |
| else: | |
| print(f"โ Current pose data failed: {response.status}") | |
| # Test zones summary | |
| async with session.get(f"{BASE_URL}/api/v1/pose/zones/summary") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| zones = data.get('zones', {}) | |
| print(f"โ Zones summary: {len(zones)} zones") | |
| for zone_id, zone_data in list(zones.items())[:3]: # Show first 3 zones | |
| print(f" - {zone_id}: {zone_data.get('occupancy', 0)} people") | |
| else: | |
| print(f"โ Zones summary failed: {response.status}") | |
| # Test pose stats | |
| async with session.get(f"{BASE_URL}/api/v1/pose/stats") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Pose stats: {data.get('total_detections', 0)} total detections") | |
| else: | |
| print(f"โ Pose stats failed: {response.status}") | |
| async def test_stream_endpoints(): | |
| """Test streaming endpoints.""" | |
| print("\n๐ Testing stream endpoints...") | |
| async with aiohttp.ClientSession() as session: | |
| # Test stream status | |
| async with session.get(f"{BASE_URL}/api/v1/stream/status") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Stream status: {'Active' if data['is_active'] else 'Inactive'}") | |
| print(f" - Connected clients: {data['connected_clients']}") | |
| else: | |
| print(f"โ Stream status failed: {response.status}") | |
| # Test stream metrics | |
| async with session.get(f"{BASE_URL}/api/v1/stream/metrics") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Stream metrics available") | |
| else: | |
| print(f"โ Stream metrics failed: {response.status}") | |
| async def test_websocket_connection(): | |
| """Test WebSocket connection.""" | |
| print("\n๐ Testing WebSocket connection...") | |
| try: | |
| uri = f"{WS_URL}/api/v1/stream/pose" | |
| async with websockets.connect(uri) as websocket: | |
| print("โ WebSocket connected successfully") | |
| # Wait for connection confirmation | |
| message = await asyncio.wait_for(websocket.recv(), timeout=5.0) | |
| data = json.loads(message) | |
| if data.get("type") == "connection_established": | |
| print(f"โ Connection established with client ID: {data.get('client_id')}") | |
| # Send a ping | |
| await websocket.send(json.dumps({"type": "ping"})) | |
| # Wait for pong | |
| pong_message = await asyncio.wait_for(websocket.recv(), timeout=5.0) | |
| pong_data = json.loads(pong_message) | |
| if pong_data.get("type") == "pong": | |
| print("โ WebSocket ping/pong successful") | |
| else: | |
| print(f"โ Unexpected pong response: {pong_data}") | |
| else: | |
| print(f"โ Unexpected connection message: {data}") | |
| except asyncio.TimeoutError: | |
| print("โ WebSocket connection timeout") | |
| except Exception as e: | |
| print(f"โ WebSocket connection failed: {e}") | |
| async def test_calibration_endpoints(): | |
| """Test calibration endpoints.""" | |
| print("\n๐ Testing calibration endpoints...") | |
| async with aiohttp.ClientSession() as session: | |
| # Test calibration status | |
| async with session.get(f"{BASE_URL}/api/v1/pose/calibration/status") as response: | |
| if response.status == 200: | |
| data = await response.json() | |
| print(f"โ Calibration status: {data.get('status', 'unknown')}") | |
| else: | |
| print(f"โ Calibration status failed: {response.status}") | |
| async def main(): | |
| """Run all tests.""" | |
| print("๐ Starting WiFi-DensePose API Tests") | |
| print("=" * 50) | |
| try: | |
| await test_health_endpoints() | |
| await test_api_endpoints() | |
| await test_pose_endpoints() | |
| await test_stream_endpoints() | |
| await test_websocket_connection() | |
| await test_calibration_endpoints() | |
| print("\n" + "=" * 50) | |
| print("โ All tests completed!") | |
| except Exception as e: | |
| print(f"\nโ Test suite failed: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
Xet Storage Details
- Size:
- 7.81 kB
- Xet hash:
- 9e3fe1f0bcc7d356e76298779d8fc99a5b532d5161a9388e273061dc00181f07
ยท
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.