-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
85 lines (61 loc) · 1.91 KB
/
test.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
import uvicorn
from fastapi.testclient import TestClient
from API import router as _api_router
from app.services import Server
from app.services.info import Info
log_config = uvicorn.config.LOGGING_CONFIG
app = Server(
ctx="",
host="127.0.0.1",
port=8080,
title=Info.get_name(),
description=Info.get_description(),
fast_api_debug=True,
asgi_debug=False,
log_config=log_config,
)
app.include_router(_api_router)
client = TestClient(app)
cluster_id = "crongcloud"
def test_host_list():
response = client.get("/v1/" + cluster_id + "/host/list")
assert response.status_code == 200
print("OK")
def test_vm_list():
response = client.get("/v1/" + cluster_id + "/vm/list")
assert response.status_code == 200
print("OK")
def test_vdi_list():
response = client.get("/v1/" + cluster_id + "/vdi/list")
assert response.status_code == 200
print("OK")
if __name__ == "__main__":
from pyfiglet import Figlet
figlet = Figlet()
print(figlet.renderText("XenXenXenSe"))
print(
"Project XenXenXenSe : a RESTful API implementation for Citrix Hypervisor® and XCP-ng"
)
print("Unit Test Script")
print()
print("Copyright (c) Stella IT.")
print("This software is distributed under MIT License.")
print()
print("Warning: This software is supposed to be used with GitHub Actions.")
print(
" This software is supposed to test against Stella IT's Internal Cloud Infrastructure Test Servers."
)
print()
print()
try:
print("Testing /host/list against test cluster ...", end="")
test_host_list()
print("Testing /vm/list against test cluster ...", end="")
test_vm_list()
print("Testing /vdi/list against test cluster ...", end="")
test_vdi_list()
print("Test success!")
except Exception:
print("test failed!!!!")
sys.exit(1)