2020-09-22 12:57:36 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-10-07 09:52:23 +02:00
|
|
|
import importlib
|
2021-06-17 18:52:18 +02:00
|
|
|
from halfapi.lib.domain import VERBS, gen_routes, gen_router_routes, MissingAclError
|
|
|
|
|
|
|
|
from types import FunctionType
|
2020-09-22 12:57:36 +02:00
|
|
|
|
2020-09-25 01:06:21 +02:00
|
|
|
|
|
|
|
def test_gen_router_routes():
|
2020-09-22 12:57:36 +02:00
|
|
|
from .dummy_domain import routers
|
2021-06-17 18:52:18 +02:00
|
|
|
for path, verb, fct, params in gen_router_routes(routers, ['dummy_domain']):
|
2020-10-04 17:26:36 +02:00
|
|
|
assert isinstance(path, str)
|
2021-06-17 18:52:18 +02:00
|
|
|
assert verb in VERBS
|
|
|
|
assert len(params) > 0
|
|
|
|
assert hasattr(fct, '__call__')
|
|
|
|
|
|
|
|
def test_gen_routes():
|
|
|
|
from .dummy_domain.routers.abc.alphabet import TEST_uuid
|
|
|
|
try:
|
|
|
|
gen_routes(
|
|
|
|
TEST_uuid,
|
|
|
|
'get',
|
|
|
|
['abc', 'alphabet', 'TEST_uuid', ''],
|
|
|
|
[])
|
|
|
|
except MissingAclError:
|
|
|
|
assert True
|
|
|
|
|
|
|
|
fct, params = gen_routes(
|
|
|
|
TEST_uuid,
|
|
|
|
'get',
|
|
|
|
['abc', 'alphabet', 'TEST_uuid', ''],
|
|
|
|
TEST_uuid.ACLS['GET'])
|
|
|
|
|
|
|
|
assert isinstance(fct, FunctionType)
|
|
|
|
assert isinstance(params, list)
|
|
|
|
assert len(TEST_uuid.ACLS['GET']) == len(params)
|
|
|
|
|