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
|
2021-12-08 13:08:22 +01:00
|
|
|
import pprint
|
2023-08-01 20:31:17 +02:00
|
|
|
import openapi_spec_validator
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
|
|
|
|
2021-12-01 12:20:01 +01:00
|
|
|
from halfapi.lib.constants import API_SCHEMA
|
2020-07-10 12:58:53 +02:00
|
|
|
|
|
|
|
|
2021-12-13 12:40:40 +01:00
|
|
|
def test_halfapi_whoami(application_debug):
|
2021-12-01 12:20:01 +01:00
|
|
|
# @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)
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/halfapi/whoami')
|
2020-09-25 01:06:21 +02:00
|
|
|
assert r.status_code == 200
|
2021-12-13 12:40:40 +01:00
|
|
|
|
|
|
|
def test_halfapi_log(application_debug):
|
|
|
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
|
|
|
# So we use a single function with fixture "application debug"
|
|
|
|
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/halfapi/log')
|
2021-03-12 18:59:30 +01:00
|
|
|
assert r.status_code == 200
|
2021-12-13 12:40:40 +01:00
|
|
|
|
|
|
|
def test_halfapi_error_400(application_debug):
|
|
|
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
|
|
|
# So we use a single function with fixture "application debug"
|
|
|
|
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/halfapi/error/400')
|
2021-03-12 18:59:30 +01:00
|
|
|
assert r.status_code == 400
|
2021-12-13 12:40:40 +01:00
|
|
|
|
|
|
|
def test_halfapi_error_404(application_debug):
|
|
|
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
|
|
|
# So we use a single function with fixture "application debug"
|
|
|
|
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/halfapi/error/404')
|
2021-03-12 18:59:30 +01:00
|
|
|
assert r.status_code == 404
|
2021-12-13 12:40:40 +01:00
|
|
|
|
|
|
|
def test_halfapi_error_500(application_debug):
|
|
|
|
# @TODO : If we use isolated filesystem multiple times that creates a bug.
|
|
|
|
# So we use a single function with fixture "application debug"
|
|
|
|
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/halfapi/error/500')
|
2021-03-12 18:59:30 +01:00
|
|
|
assert r.status_code == 500
|
2021-12-13 12:40:40 +01:00
|
|
|
|
|
|
|
def test_schema(application_debug):
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
|
2023-01-14 11:10:13 +01:00
|
|
|
r = c.request('get', '/')
|
2023-08-01 20:31:17 +02:00
|
|
|
schema = r.json()
|
|
|
|
assert isinstance(schema, dict)
|
|
|
|
openapi_spec_validator.validate_spec(schema)
|