2020-10-07 09:52:23 +02:00
|
|
|
import subprocess
|
|
|
|
from pprint import pprint
|
|
|
|
from starlette.testclient import TestClient
|
|
|
|
from starlette.authentication import (
|
|
|
|
AuthenticationBackend, AuthenticationError, BaseUser, AuthCredentials,
|
|
|
|
UnauthenticatedUser)
|
|
|
|
|
|
|
|
from halfapi.lib.schemas import schema_dict_dom
|
2021-06-17 19:14:39 +02:00
|
|
|
from halfapi import __version__
|
2020-10-07 09:52:23 +02:00
|
|
|
|
|
|
|
def test_schemas_dict_dom():
|
2021-05-28 22:30:48 +02:00
|
|
|
from .dummy_domain import routers
|
2020-10-07 09:52:23 +02:00
|
|
|
schema = schema_dict_dom({
|
2021-05-28 22:30:48 +02:00
|
|
|
'dummy_domain':routers})
|
2020-10-07 09:52:23 +02:00
|
|
|
assert isinstance(schema, dict)
|
|
|
|
|
2021-06-17 18:53:23 +02:00
|
|
|
def test_get_api_routes(project_runner, application_debug):
|
|
|
|
c = TestClient(application_debug)
|
2020-10-07 09:52:23 +02:00
|
|
|
r = c.get('/')
|
|
|
|
d_r = r.json()
|
2020-10-07 15:51:24 +02:00
|
|
|
assert isinstance(d_r, dict)
|
2021-06-17 18:53:23 +02:00
|
|
|
|
2021-06-17 19:14:39 +02:00
|
|
|
def test_get_schema_route(project_runner, application_debug):
|
|
|
|
c = TestClient(application_debug)
|
|
|
|
r = c.get('/halfapi/schema')
|
|
|
|
d_r = r.json()
|
|
|
|
assert isinstance(d_r, dict)
|
|
|
|
assert 'openapi' in d_r.keys()
|
|
|
|
assert 'info' in d_r.keys()
|
|
|
|
assert d_r['info']['title'] == 'HalfAPI'
|
|
|
|
assert d_r['info']['version'] == __version__
|
|
|
|
assert 'paths' in d_r.keys()
|
|
|
|
|
2021-06-17 18:53:23 +02:00
|
|
|
|
|
|
|
def test_get_api_dummy_domain_routes(application_domain, routers):
|
|
|
|
c = TestClient(application_domain)
|
|
|
|
r = c.get('/dummy_domain')
|
|
|
|
assert r.status_code == 200
|
|
|
|
d_r = r.json()
|
|
|
|
assert isinstance(d_r, dict)
|
|
|
|
assert 'abc/alphabet' in d_r
|
|
|
|
assert 'GET' in d_r['abc/alphabet']
|
|
|
|
assert len(d_r['abc/alphabet']['GET']) > 0
|
2021-11-29 05:43:51 +01:00
|
|
|
assert 'acls' in d_r['abc/alphabet']['GET']
|