Files
SmartUp/backend/test_upstream.py
T
SmartUp Developer 5c60627fb6 fix: Vite type declaration, non-idempotent retry, hardcoded test IP
- Add frontend/src/vite-env.d.ts (reference vite/client) to fix vue-tsc build
- Restrict axios-retry to GET/HEAD/OPTIONS only (avoid replaying mutations)
- Convert test_upstream.py to accept URL via CLI args instead of hardcoded IP
2026-05-17 11:56:49 +08:00

44 lines
1.4 KiB
Python

import json
import sys
import logging
from app.services.upstream_client import UpstreamClient
logging.basicConfig(level=logging.DEBUG)
def main():
# Usage: python test_upstream.py <base_url> [api_prefix] [auth_type] [token]
# Example: python test_upstream.py http://localhost:8000 "" bearer "sk-xxx"
import sys
base_url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:8000"
api_prefix = sys.argv[2] if len(sys.argv) > 2 else ""
auth_type = sys.argv[3] if len(sys.argv) > 3 else "bearer"
token = sys.argv[4] if len(sys.argv) > 4 else ""
with UpstreamClient(
base_url=base_url,
api_prefix=api_prefix,
auth_type=auth_type,
auth_config={"token": token},
timeout=10.0,
) as client:
try:
groups = client.get_available_groups("/api/group/")
print("Groups:", groups)
except Exception as e:
print("Groups Error:", e)
try:
rates = client.get_group_rates("/api/option/?key=GroupRatio")
print("Rates:", rates)
except Exception as e:
print("Rates Error:", e)
try:
from app.services.upstream_client import _extract_rates_map, _unwrap_list
print("Unwrapped Groups:", _unwrap_list(groups))
print("Extracted Rates:", _extract_rates_map(rates))
except Exception as e:
pass
if __name__ == "__main__":
main()