-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_endpoints.py
More file actions
40 lines (33 loc) · 956 Bytes
/
test_endpoints.py
File metadata and controls
40 lines (33 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import subprocess
import time
import urllib.request
import os
from dotenv import load_dotenv
load_dotenv()
p = subprocess.Popen(
[sys.executable, "-m", "uvicorn", "app.main:app", "--port", "8003"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True
)
time.sleep(3)
def fetch(url):
try:
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as response:
print(response.status, response.read().decode())
except urllib.error.HTTPError as e:
print(e.code, e.read().decode())
except Exception as e:
print(e)
print("Testing /api/v1/hardware/")
fetch("http://127.0.0.1:8003/api/v1/hardware/")
print("Testing /api/v1/virtual-machines/")
fetch("http://127.0.0.1:8003/api/v1/virtual-machines/")
print("Testing /api/v1/runbooks/")
fetch("http://127.0.0.1:8003/api/v1/runbooks/")
p.terminate()
p.wait()
print("--- UVICORN LOGS ---")
print(p.stdout.read())