halfapi/tests/test_lib_routes.py

32 lines
992 B
Python
Raw Normal View History

from starlette.routing import Route
from halfapi.lib.routes import gen_starlette_routes, api_routes, gen_router_routes
def test_gen_starlette_routes():
2021-05-28 22:30:48 +02:00
from .dummy_domain import routers
for route in gen_starlette_routes({
2021-05-28 22:30:48 +02:00
'dummy_domain': routers }):
assert isinstance(route, Route)
def test_api_routes():
from . import dummy_domain
d_res, d_acls = api_routes(dummy_domain)
assert isinstance(d_res, dict)
assert isinstance(d_acls, dict)
yielded = False
for path, verb, m_router, fct, params in gen_router_routes(dummy_domain, []):
if not yielded:
yielded = True
assert path in d_res
assert verb in d_res[path]
assert 'docs' in d_res[path][verb]
assert 'acls' in d_res[path][verb]
assert isinstance(d_res[path][verb]['docs'], dict)
assert isinstance(d_res[path][verb]['acls'], list)
assert len(d_res[path][verb]['acls']) == len(params)
assert yielded is True