[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
|
||||
|
||||
if acls is not None:
|
||||
for verb in VERBS:
|
||||
if not hasattr(m_router, verb.lower()):
|
||||
# verb in function names are lowercase
|
||||
continue
|
||||
for method in acls.keys():
|
||||
if method not in VERBS:
|
||||
raise Exception(
|
||||
'This method is not handled: {}'.format(method))
|
||||
|
||||
""" There is a "verb" route in the router
|
||||
"""
|
||||
|
||||
if verb.upper() not in acls:
|
||||
continue
|
||||
|
||||
routes[''][verb.upper()] = []
|
||||
routes[''][verb.upper()] = acls[verb.upper()].copy()
|
||||
routes[''][method] = []
|
||||
routes[''][method] = acls[method].copy()
|
||||
|
||||
routes['']['SUBROUTES'] = []
|
||||
if hasattr(m_router, '__path__'):
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
import os
|
||||
import pytest
|
||||
from schema import SchemaError
|
||||
from halfapi.lib.router import read_router
|
||||
from halfapi.lib.constants import ROUTER_SCHEMA, ROUTER_ACLS_SCHEMA
|
||||
|
||||
def test_read_router_routers():
|
||||
from .dummy_domain import routers
|
||||
|
@ -29,6 +32,16 @@ def test_read_router_alphabet():
|
|||
assert 'SUBROUTES' in router_d['']
|
||||
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():
|
||||
from .dummy_domain.routers.abc.alphabet import TEST_uuid
|
||||
router_d = read_router(TEST_uuid)
|
||||
|
|
Loading…
Reference in New Issue