fastapi-dls/test/main.py

86 lines
1.9 KiB
Python
Raw Normal View History

2022-12-23 15:42:02 +03:00
from uuid import uuid4
from jose import jwt
2022-12-23 09:35:37 +03:00
from starlette.testclient import TestClient
import sys
2022-12-23 13:24:40 +03:00
# add relative path to use packages as they were in the app/ dir
sys.path.append('../')
sys.path.append('../app')
2022-12-23 09:35:37 +03:00
2022-12-23 13:24:40 +03:00
from app import main
2022-12-23 09:35:37 +03:00
client = TestClient(main.app)
2022-12-23 15:42:02 +03:00
ORIGIN_REF = str(uuid4())
2022-12-23 09:35:37 +03:00
def test_index():
response = client.get('/')
assert response.status_code == 200
def test_status():
response = client.get('/status')
assert response.status_code == 200
assert response.json()['status'] == 'up'
2022-12-23 09:48:47 +03:00
def test_client_token():
response = client.get('/client-token')
assert response.status_code == 200
def test_auth_v1_origin():
payload = {
"registration_pending": False,
"environment": {
"guest_driver_version": "guest_driver_version",
"hostname": "myhost",
"ip_address_list": ["192.168.1.123"],
"os_version": "os_version",
"os_platform": "os_platform",
"fingerprint": {"mac_address_list": ["ff:ff:ff:ff:ff:ff"]},
"host_driver_version": "host_driver_version"
},
"update_pending": False,
2022-12-23 15:42:02 +03:00
"candidate_origin_ref": ORIGIN_REF,
2022-12-23 09:48:47 +03:00
}
2022-12-23 15:42:02 +03:00
2022-12-23 09:48:47 +03:00
response = client.post('/auth/v1/origin', json=payload)
assert response.status_code == 200
2022-12-23 15:42:02 +03:00
assert response.json()['origin_ref'] == ORIGIN_REF
2022-12-23 09:48:47 +03:00
def test_auth_v1_code():
2022-12-23 15:42:02 +03:00
payload = {
"code_challenge": "0wmaiAMAlTIDyz4Fgt2/j0tXnGv72TYbbLs4ISRCZlY",
"origin_ref": ORIGIN_REF,
}
response = client.post('/auth/v1/code', json=payload)
assert response.status_code == 200
payload = jwt.get_unverified_claims(token=response.json()['auth_code'])
assert payload['origin_ref'] == ORIGIN_REF
2022-12-23 09:48:47 +03:00
def test_auth_v1_token():
pass
def test_leasing_v1_lessor():
pass
def test_leasing_v1_lessor_lease():
pass
def test_leasing_v1_lease_renew():
pass
def test_leasing_v1_lessor_lease_remove():
pass