Files
adif-api-reverse-engineering/test_corrected_api.py

204 lines
6.5 KiB
Python

#!/usr/bin/env python3
"""
Script para probar los endpoints con los valores correctos
obtenidos del código decompilado
"""
import requests
import json
from datetime import datetime
# 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 500 chars):")
print(json.dumps(result, indent=2, ensure_ascii=False)[:500])
if len(json.dumps(result)) > 500:
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 CON VALORES CORRECTOS DEL CÓDIGO DECOMPILADO")
print("=" * 70)
results = {}
# Test 1: Salidas con State correcto (BOTH en lugar de ALL)
print("\n\n### TEST 1: Departures con State=BOTH ###")
results['departures_both'] = test_endpoint(
"Salidas - Madrid Atocha (State=BOTH, TrafficType=ALL)",
"POST",
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/departures/traffictype/",
HEADERS_CIRCULATION,
{
"commercialService": "BOTH", # Correcto: BOTH (no ALL)
"commercialStopType": "BOTH", # Correcto: BOTH (no ALL)
"destinationStationCode": None,
"originStationCode": None,
"page": {
"pageNumber": 0 # Correcto: pageNumber (no page+size)
},
"stationCode": "10200", # Madrid Atocha
"trafficType": "ALL" # Correcto: ALL existe en TrafficType
}
)
# Test 2: Salidas con State YES y NOT
print("\n\n### TEST 2: Departures con State=YES ###")
results['departures_yes'] = test_endpoint(
"Salidas - Madrid Atocha (State=YES)",
"POST",
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/departures/traffictype/",
HEADERS_CIRCULATION,
{
"commercialService": "YES", # Correcto: YES
"commercialStopType": "NOT", # Correcto: NOT (no NO)
"destinationStationCode": None,
"originStationCode": None,
"page": {
"pageNumber": 0
},
"stationCode": "10200",
"trafficType": "CERCANIAS"
}
)
# Test 3: Prueba con TrafficType AVLDMD (correcto)
print("\n\n### TEST 3: Departures con TrafficType=AVLDMD ###")
results['departures_avldmd'] = test_endpoint(
"Salidas - Madrid Atocha (TrafficType=AVLDMD)",
"POST",
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpaths/departures/traffictype/",
HEADERS_CIRCULATION,
{
"commercialService": "BOTH",
"commercialStopType": "BOTH",
"destinationStationCode": None,
"originStationCode": None,
"page": {
"pageNumber": 0
},
"stationCode": "10200",
"trafficType": "AVLDMD" # Correcto: AVLDMD (no LARGA_DISTANCIA)
}
)
# Test 4: Station Observations con stationCodes (array)
print("\n\n### TEST 4: Station Observations (stationCodes array) ###")
results['station_observations'] = test_endpoint(
"Observaciones de Estación (array)",
"POST",
f"{BASE_STATIONS}/portroyalmanager/secure/stationsobservations/",
HEADERS_STATIONS,
{
"stationCodes": ["10200", "10302"] # Correcto: stationCodes (array, no stationCode)
}
)
# Test 5: OneOrSeveralPaths
print("\n\n### TEST 5: OneOrSeveralPaths ###")
results['onepaths'] = test_endpoint(
"Detalles de Ruta Específica",
"POST",
f"{BASE_CIRCULATION}/portroyalmanager/secure/circulationpathdetails/onepaths/",
HEADERS_CIRCULATION,
{
"allControlPoints": True,
"commercialNumber": None,
"destinationStationCode": "71801", # Barcelona Sants
"launchingDate": None,
"originStationCode": "10200" # Madrid Atocha
}
)
# Test 6: Between Stations
print("\n\n### TEST 6: Between Stations ###")
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", # Barcelona Sants
"originStationCode": "10200", # Madrid Atocha
"page": {
"pageNumber": 0
},
"stationCode": None,
"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! La documentación es correcta.")
else:
print(f"\n⚠️ {failed} prueba(s) fallaron. Revisar los errores arriba.")
if __name__ == "__main__":
main()