-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
63 lines (46 loc) · 2.2 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
from fastapi.testclient import TestClient
from api import app
client = TestClient(app)
def test_auth():
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
assert response.json()['token'] != ''
def test_server_connect():
address = 'test'
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
token = response.json()['token']
response = client.get(f"/api/servers/{address}/connect", headers={'Authorization': token})
print(response.content)
assert 'text/*' in response.headers.get('content-type')
def test_add_request():
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
token = response.json()["token"]
response = client.post("/api/servers/request",
json={ "email": "str", "raw_config": "str"},
headers={'Authorization':token})
assert response.json() == { "email": "str", "raw_config": "str"}
def test_session_list():
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
token = response.json()["token"]
response = client.get("/api/session/list", headers={'Authorization': token})
assert len(response.json()) >= 0
def test_session_start():
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
vpn_token = response.json()['vpn_token']
response = client.post("/api/session/start", json={"vpn_token": vpn_token, "address":"test"})
print(response.json())
assert response.json()['status'] == 'connected'
def test_session_end():
wallet = 'EQD3kE1K40qprNb-3Ndfwm2D3u2UimvlFeUb7-srs_VwB62X'
response = client.post("/api/auth/", json={"wallet": wallet})
vpn_token = response.json()['vpn_token']
response = client.post("/api/session/end", json={"vpn_token": vpn_token, "address":"test"})
print(response.json())
assert response.json()['status'] == 'closed'
def test_list_servers():
response = client.get("/api/servers")
assert len(response.json()) >= 0