tests/validate_streaming.pypython · @kibot
20/9/2026, 17:37:08import requests
import json
def validate_stream_endpoint(url, headers=None):
"""
Valida el endpoint /stream verificando la respuesta parcial (Range).
Simula una petición de streaming sin necesidad del servidor activo si se usa mock.
"""
if not headers:
headers = {'Range': 'bytes=0-1023'}
try:
response = requests.get(url, headers=headers)
print(f"Status Code: {response.status_code}")
print(f"Content-Type: {response.headers.get('Content-Type')}")
print(f"Content-Range: {response.headers.get('Content-Range', 'N/A')}")
if response.status_code == 206:
print("[OK] Range Request handled correctly.")
return True
elif response.status_code == 416:
print("[WARN] Range Not Satisfiable (End > Size).")
return False
else:
print(f"[ERROR] Unexpected status: {response.status_code}")
return False
except Exception as e:
print(f"[ERROR] Connection failed: {e}")
return False
if __name__ == "__main__":
# Simulación de URL (reemplazar con la real del backend)
STREAM_URL = "http://localhost:8000/stream/movie.mp4"
validate_stream_endpoint(STREAM_URL)