2020-09-22 12:57:36 +02:00
|
|
|
#!/usr/bin/env python3
|
2020-10-07 09:52:23 +02:00
|
|
|
import importlib
|
2021-11-30 18:31:40 +01:00
|
|
|
from halfapi.lib.domain import VERBS, gen_routes, gen_router_routes, \
|
|
|
|
MissingAclError, domain_schema_dict, domain_schema_list
|
2021-06-17 18:53:23 +02:00
|
|
|
|
|
|
|
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-11-22 20:06:12 +01:00
|
|
|
for path, verb, m_router, 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:53:23 +02:00
|
|
|
assert verb in VERBS
|
|
|
|
assert len(params) > 0
|
|
|
|
assert hasattr(fct, '__call__')
|
2021-11-22 20:06:12 +01:00
|
|
|
assert len(m_router.__file__) > 0
|
|
|
|
|
2021-06-17 18:53:23 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2021-11-30 18:31:40 +01:00
|
|
|
def test_domain_schema_dict():
|
|
|
|
from .dummy_domain import routers
|
|
|
|
d_res = domain_schema_dict(routers)
|
|
|
|
|
|
|
|
assert isinstance(d_res, dict)
|
|
|
|
|
|
|
|
def test_domain_schema_list():
|
|
|
|
from .dummy_domain import routers
|
|
|
|
res = domain_schema_list(routers)
|
|
|
|
|
|
|
|
assert isinstance(res, list)
|
|
|
|
assert len(res) > 0
|