TraceStudio-dev/server/tests/run_execute_test.py

35 lines
1.1 KiB
Python
Raw Normal View History

import json
import time
import urllib.request
import urllib.error
URL = "http://127.0.0.1:8000/api/graph/execute"
PAYLOAD_FILE = "server/tests/payload_execute.json"
def post_payload():
with open(PAYLOAD_FILE, 'rb') as f:
data = f.read()
req = urllib.request.Request(URL, data=data, headers={"Content-Type": "application/json"}, method='POST')
try:
with urllib.request.urlopen(req, timeout=30) as resp:
body = resp.read().decode('utf-8')
print(f"Status: {resp.status}")
print("Response body:\n", body)
return resp.status, body
except urllib.error.HTTPError as e:
body = e.read().decode('utf-8') if e.fp else ''
print(f"HTTPError {e.code}: {e.reason}")
print("Response body:\n", body)
return e.code, body
except Exception as e:
print(f"Request failed: {e}")
return None, str(e)
if __name__ == '__main__':
print('Posting payload first time...')
post_payload()
time.sleep(1)
print('\nPosting payload second time (cache disabled test)...')
post_payload()