181 lines
5.3 KiB
Python
181 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script para probar los endpoints OMITIENDO campos null
|
|
(en lugar de enviarlos explícitamente como null)
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
# Headers correctos
|
|
HEADERS_CIRCULATION = {
|
|
"Content-Type": "application/json;charset=utf-8",
|
|
"User-key": "f4ce9fbfa9d721e39b8984805901b5df"
|
|
}
|
|
|
|
HEADERS_STATIONS = {
|
|
"Content-Type": "application/json;charset=utf-8",
|
|
"User-key": "0d021447a2fd2ac64553674d5a0c1a6f"
|
|
}
|
|
|
|
# URLs base
|
|
BASE_CIRCULATION = "https://circulacion.api.adif.es"
|
|
BASE_STATIONS = "https://estaciones.api.adif.es"
|
|
|
|
|
|
def test_endpoint(name, method, url, headers, data=None):
|
|
"""Probar un endpoint y mostrar resultado"""
|
|
print(f"\n{'='*70}")
|
|
print(f"TEST: {name}")
|
|
print(f"{'='*70}")
|
|
print(f"URL: {url}")
|
|
|
|
if data:
|
|
print(f"Body:\n{json.dumps(data, indent=2)}")
|
|
|
|
try:
|
|
if method == "GET":
|
|
response = requests.get(url, headers=headers, timeout=10)
|
|
elif method == "POST":
|
|
response = requests.post(url, headers=headers, json=data, timeout=10)
|
|
else:
|
|
print(f"❌ Método {method} no soportado")
|
|
return False
|
|
|
|
print(f"\nStatus: {response.status_code}")
|
|
|
|
if response.status_code == 200:
|
|
print("✅ SUCCESS")
|
|
result = response.json()
|
|
print(f"\nResponse Preview (primeros 1000 chars):")
|
|
resp_str = json.dumps(result, indent=2, ensure_ascii=False)
|
|
print(resp_str[:1000])
|
|
if len(resp_str) > 1000:
|
|
print("...")
|
|
return True
|
|
else:
|
|
print(f"❌ FAILED")
|
|
print(f"Response: {response.text[:300]}")
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"❌ EXCEPTION: {str(e)}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
print("=" * 70)
|
|
print("PRUEBAS OMITIENDO CAMPOS NULL")
|
|
print("=" * 70)
|
|
|
|
results = {}
|
|
|
|
# Test 1: Salidas - SOLO campos requeridos
|
|
print("\n\n### TEST 1: Departures - SOLO campos necesarios ###")
|
|
results['departures_minimal'] = test_endpoint(
|
|
"Salidas - Madrid Atocha (campos mínimos)",
|
|
"POST",
|
|
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/departures/traffictype/",
|
|
HEADERS_CIRCULATION,
|
|
{
|
|
"commercialService": "BOTH",
|
|
"commercialStopType": "BOTH",
|
|
"page": {
|
|
"pageNumber": 0
|
|
},
|
|
"stationCode": "10200",
|
|
"trafficType": "ALL"
|
|
# Omitiendo destinationStationCode, originStationCode que son null
|
|
}
|
|
)
|
|
|
|
# Test 2: Station Observations
|
|
print("\n\n### TEST 2: Station Observations ###")
|
|
results['station_observations'] = test_endpoint(
|
|
"Observaciones de Estación",
|
|
"POST",
|
|
f"{BASE_STATIONS}/portroyalmanager/secure/stationsobservations/",
|
|
HEADERS_STATIONS,
|
|
{
|
|
"stationCodes": ["10200"]
|
|
}
|
|
)
|
|
|
|
# Test 3: OneOrSeveralPaths - solo campos necesarios
|
|
print("\n\n### TEST 3: OneOrSeveralPaths (campos mínimos) ###")
|
|
results['onepaths_minimal'] = test_endpoint(
|
|
"Detalles de Ruta - solo estaciones",
|
|
"POST",
|
|
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpathdetails/onepaths/",
|
|
HEADERS_CIRCULATION,
|
|
{
|
|
"destinationStationCode": "71801",
|
|
"originStationCode": "10200"
|
|
# Omitiendo allControlPoints, commercialNumber, launchingDate
|
|
}
|
|
)
|
|
|
|
# Test 4: Between Stations
|
|
print("\n\n### TEST 4: Between Stations (campos mínimos) ###")
|
|
results['between_stations'] = test_endpoint(
|
|
"Entre Estaciones (Madrid - Barcelona)",
|
|
"POST",
|
|
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/betweenstations/traffictype/",
|
|
HEADERS_CIRCULATION,
|
|
{
|
|
"commercialService": "BOTH",
|
|
"commercialStopType": "BOTH",
|
|
"destinationStationCode": "71801",
|
|
"originStationCode": "10200",
|
|
"page": {
|
|
"pageNumber": 0
|
|
},
|
|
"trafficType": "ALL"
|
|
# Omitiendo stationCode que es null
|
|
}
|
|
)
|
|
|
|
# Test 5: Arrivals
|
|
print("\n\n### TEST 5: Arrivals ###")
|
|
results['arrivals'] = test_endpoint(
|
|
"Llegadas - Madrid Atocha",
|
|
"POST",
|
|
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/arrivals/traffictype/",
|
|
HEADERS_CIRCULATION,
|
|
{
|
|
"commercialService": "BOTH",
|
|
"commercialStopType": "BOTH",
|
|
"page": {
|
|
"pageNumber": 0
|
|
},
|
|
"stationCode": "10200",
|
|
"trafficType": "ALL"
|
|
}
|
|
)
|
|
|
|
# Resumen
|
|
print("\n\n" + "="*70)
|
|
print("RESUMEN DE PRUEBAS")
|
|
print("="*70)
|
|
|
|
total = len(results)
|
|
passed = sum(1 for v in results.values() if v)
|
|
failed = total - passed
|
|
|
|
for test_name, result in results.items():
|
|
status = "✅ PASS" if result else "❌ FAIL"
|
|
print(f"{status} - {test_name}")
|
|
|
|
print(f"\nTotal: {total} | Pasadas: {passed} | Fallidas: {failed}")
|
|
|
|
if passed == total:
|
|
print("\n🎉 ¡Todas las pruebas pasaron!")
|
|
elif passed > 0:
|
|
print(f"\n✅ {passed} prueba(s) funcionaron correctamente")
|
|
else:
|
|
print(f"\n⚠️ Todas las pruebas fallaron")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|