2020-07-10 12:58:53 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import pytest
|
|
|
|
from starlette.authentication import UnauthenticatedUser
|
|
|
|
from starlette.testclient import TestClient
|
2020-09-25 01:06:21 +02:00
|
|
|
from halfapi.app import application
|
|
|
|
import json
|
2020-07-10 12:58:53 +02:00
|
|
|
|
2020-09-28 17:22:27 +02:00
|
|
|
def test_get_api_routes():
|
2020-09-25 01:06:21 +02:00
|
|
|
c = TestClient(application)
|
2020-09-28 17:22:27 +02:00
|
|
|
r = c.get('/')
|
|
|
|
d_r = r.json()
|
|
|
|
assert isinstance(d_r, dict)
|
2020-07-10 12:58:53 +02:00
|
|
|
|
2020-09-25 01:06:21 +02:00
|
|
|
|
2020-09-28 17:22:27 +02:00
|
|
|
def test_current_user():
|
2020-09-25 01:06:21 +02:00
|
|
|
c = TestClient(application)
|
2020-09-28 17:22:27 +02:00
|
|
|
r = c.get('/halfapi/current_user')
|
2020-09-25 01:06:21 +02:00
|
|
|
assert r.status_code == 200
|
2021-03-12 18:59:30 +01:00
|
|
|
|
|
|
|
def test_log():
|
|
|
|
c = TestClient(application)
|
|
|
|
r = c.get('/halfapi/log')
|
|
|
|
assert r.status_code == 200
|
|
|
|
|
|
|
|
def test_error():
|
|
|
|
c = TestClient(application)
|
|
|
|
r = c.get('/halfapi/error/400')
|
|
|
|
assert r.status_code == 400
|
|
|
|
r = c.get('/halfapi/error/404')
|
|
|
|
assert r.status_code == 404
|
|
|
|
r = c.get('/halfapi/error/500')
|
|
|
|
assert r.status_code == 500
|
|
|
|
|
|
|
|
def test_exception():
|
|
|
|
c = TestClient(application)
|
|
|
|
try:
|
|
|
|
r = c.get('/halfapi/exception')
|
|
|
|
assert r.status_code == 500
|
|
|
|
except Exception:
|
|
|
|
print('exception')
|