File size: 815 Bytes
abd2333
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import asyncio
import httpx
from httpx import AsyncClient, ASGITransport
from server.app import app

async def run_test():
    # To run lifespan, we must use ASGITransport and standard AsyncClient won't auto-trigger it until httpx 0.28.
    # A reliable way is via httpx ASGITransport's own lifespan context or simple starlette TestClient
    from fastapi.testclient import TestClient
    
    with TestClient(app) as client:
        # Reset creates the env
        r = client.post("/reset")
        print("Reset:", r.status_code, r.json())
        
        # Auto-attack
        req = {"strategy_type": "roleplay", "target_category": "privacy"}
        r = client.post("/auto-attack", json=req)
        print("Auto-attack:", r.status_code, r.json())
        
if __name__ == "__main__":
    asyncio.run(run_test())