tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_client.py (1229B)


      1 import json
      2 import logging
      3 import urllib.parse
      4 
      5 import asyncio
      6 import websockets
      7 
      8 
      9 logging.basicConfig(level=logging.WARNING)
     10 
     11 # Uncomment this line to make only websockets more verbose.
     12 # logging.getLogger('websockets').setLevel(logging.DEBUG)
     13 
     14 
     15 SERVER = "ws://127.0.0.1:8642"
     16 AGENT = "websockets"
     17 
     18 
     19 async def get_case_count(server):
     20    uri = f"{server}/getCaseCount"
     21    async with websockets.connect(uri) as ws:
     22        msg = ws.recv()
     23    return json.loads(msg)
     24 
     25 
     26 async def run_case(server, case, agent):
     27    uri = f"{server}/runCase?case={case}&agent={agent}"
     28    async with websockets.connect(uri, max_size=2 ** 25, max_queue=1) as ws:
     29        async for msg in ws:
     30            await ws.send(msg)
     31 
     32 
     33 async def update_reports(server, agent):
     34    uri = f"{server}/updateReports?agent={agent}"
     35    async with websockets.connect(uri):
     36        pass
     37 
     38 
     39 async def run_tests(server, agent):
     40    cases = await get_case_count(server)
     41    for case in range(1, cases + 1):
     42        print(f"Running test case {case} out of {cases}", end="\r")
     43        await run_case(server, case, agent)
     44    print(f"Ran {cases} test cases               ")
     45    await update_reports(server, agent)
     46 
     47 
     48 asyncio.run(run_tests(SERVER, urllib.parse.quote(AGENT)))