2020-07-10 12:58:53 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import pytest
|
|
|
|
from starlette.authentication import UnauthenticatedUser
|
|
|
|
from starlette.testclient import TestClient
|
2021-12-01 12:20:01 +01:00
|
|
|
import subprocess
|
2020-09-25 01:06:21 +02:00
|
|
|
import json
|
2021-12-01 12:20:01 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from halfapi.lib.constants import API_SCHEMA
|
2020-07-10 12:58:53 +02:00
|
|
|
|
|
|
|
|
2021-12-01 12:20:01 +01:00
|
|
|
def test_routes(application_debug):
|
|
|
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
|
|
|
# So we use a single function with fixture "application debug"
|
|
|
|
|
2021-06-17 18:53:23 +02:00
|
|
|
c = TestClient(application_debug)
|
2021-10-04 20:12:43 +02:00
|
|
|
r = c.get('/halfapi/whoami')
|
2020-09-25 01:06:21 +02:00
|
|
|
assert r.status_code == 200
|
2021-03-12 18:59:30 +01:00
|
|
|
r = c.get('/halfapi/log')
|
|
|
|
assert r.status_code == 200
|
|
|
|
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
|
2021-12-01 12:20:01 +01:00
|
|
|
r = c.get('/')
|
|
|
|
d_r = r.json()
|
|
|
|
assert isinstance(d_r, dict)
|
2021-12-03 09:41:00 +01:00
|
|
|
# assert API_SCHEMA.validate(d_r)
|
2021-03-12 18:59:30 +01:00
|
|
|
|
2021-12-01 12:20:01 +01:00
|
|
|
"""
|
|
|
|
TODO: Find a way to test exception raising
|
2021-03-12 18:59:30 +01:00
|
|
|
try:
|
|
|
|
r = c.get('/halfapi/exception')
|
|
|
|
assert r.status_code == 500
|
|
|
|
except Exception:
|
|
|
|
print('exception')
|
2021-12-01 12:20:01 +01:00
|
|
|
"""
|