[lib.router] forbid extra-keys in routes dict (no more FQTN at same level of methods)
This commit is contained in:
parent
a37c2356d6
commit
c1bb637be7
@ -27,19 +27,13 @@ def read_router(m_router: ModuleType) -> Dict:
|
|||||||
acls = getattr(m_router, 'ACLS') if hasattr(m_router, 'ACLS') else None
|
acls = getattr(m_router, 'ACLS') if hasattr(m_router, 'ACLS') else None
|
||||||
|
|
||||||
if acls is not None:
|
if acls is not None:
|
||||||
for verb in VERBS:
|
for method in acls.keys():
|
||||||
if not hasattr(m_router, verb.lower()):
|
if method not in VERBS:
|
||||||
# verb in function names are lowercase
|
raise Exception(
|
||||||
continue
|
'This method is not handled: {}'.format(method))
|
||||||
|
|
||||||
""" There is a "verb" route in the router
|
routes[''][method] = []
|
||||||
"""
|
routes[''][method] = acls[method].copy()
|
||||||
|
|
||||||
if verb.upper() not in acls:
|
|
||||||
continue
|
|
||||||
|
|
||||||
routes[''][verb.upper()] = []
|
|
||||||
routes[''][verb.upper()] = acls[verb.upper()].copy()
|
|
||||||
|
|
||||||
routes['']['SUBROUTES'] = []
|
routes['']['SUBROUTES'] = []
|
||||||
if hasattr(m_router, '__path__'):
|
if hasattr(m_router, '__path__'):
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
import pytest
|
||||||
|
from schema import SchemaError
|
||||||
from halfapi.lib.router import read_router
|
from halfapi.lib.router import read_router
|
||||||
|
from halfapi.lib.constants import ROUTER_SCHEMA, ROUTER_ACLS_SCHEMA
|
||||||
|
|
||||||
def test_read_router_routers():
|
def test_read_router_routers():
|
||||||
from .dummy_domain import routers
|
from .dummy_domain import routers
|
||||||
@ -29,6 +32,16 @@ def test_read_router_alphabet():
|
|||||||
assert 'SUBROUTES' in router_d['']
|
assert 'SUBROUTES' in router_d['']
|
||||||
assert isinstance(router_d['']['SUBROUTES'], list)
|
assert isinstance(router_d['']['SUBROUTES'], list)
|
||||||
|
|
||||||
|
ROUTER_SCHEMA.validate(router_d)
|
||||||
|
|
||||||
|
with pytest.raises(SchemaError):
|
||||||
|
""" Test that we cannot specify wrong method in ROUTES or ACLS
|
||||||
|
|
||||||
|
TODO: Write more errors
|
||||||
|
"""
|
||||||
|
router_d['']['TEG'] = {}
|
||||||
|
ROUTER_SCHEMA.validate(router_d)
|
||||||
|
|
||||||
def test_read_router_TEST():
|
def test_read_router_TEST():
|
||||||
from .dummy_domain.routers.abc.alphabet import TEST_uuid
|
from .dummy_domain.routers.abc.alphabet import TEST_uuid
|
||||||
router_d = read_router(TEST_uuid)
|
router_d = read_router(TEST_uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user