[tests][testfail] add default routes testing, /halfapi/acls fail
This commit is contained in:
parent
d54dcd641d
commit
96f78e76c5
|
@ -55,3 +55,12 @@ class HalfDomain(Starlette):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def acls(domain):
|
||||||
|
""" Returns the ACLS constant for the given domain
|
||||||
|
"""
|
||||||
|
m_acl = importlib.import_module(f'{domain}.acl')
|
||||||
|
try:
|
||||||
|
return getattr(m_acl, 'ACLS')
|
||||||
|
except AttributeError:
|
||||||
|
raise Exception(f'Missing acl.ACLS constant in {domain} module')
|
||||||
|
|
|
@ -4,8 +4,11 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
from starlette.testclient import TestClient
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
from ..cli.cli import cli
|
from ..cli.cli import cli
|
||||||
|
from ..halfapi import HalfAPI
|
||||||
|
from ..half_domain import HalfDomain
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
class TestDomain(TestCase):
|
class TestDomain(TestCase):
|
||||||
|
@ -53,3 +56,34 @@ class TestDomain(TestCase):
|
||||||
self.assertEqual(result.exit_code, 0)
|
self.assertEqual(result.exit_code, 0)
|
||||||
|
|
||||||
return result_d
|
return result_d
|
||||||
|
|
||||||
|
def check_routes(self):
|
||||||
|
halfapi = HalfAPI({
|
||||||
|
'domain': {
|
||||||
|
'dummy_domain': {
|
||||||
|
'name': 'dummy_domain',
|
||||||
|
'router': 'dummy_domain.routers',
|
||||||
|
'prefix': False,
|
||||||
|
'config': {
|
||||||
|
'test': True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
client = TestClient(halfapi.application)
|
||||||
|
r = client.get('/')
|
||||||
|
assert r.status_code == 200
|
||||||
|
d_r = r.json()
|
||||||
|
assert isinstance(d_r, dict)
|
||||||
|
r = client.get('/halfapi/acls')
|
||||||
|
assert r.status_code == 200
|
||||||
|
d_r = r.json()
|
||||||
|
assert isinstance(d_r, dict)
|
||||||
|
|
||||||
|
ACLS = HalfDomain.acls(self.DOMAIN)
|
||||||
|
assert len(ACLS) == len(d_r.keys())
|
||||||
|
for acl_name in ACLS:
|
||||||
|
assert acl_name in d_r.keys()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,3 +8,6 @@ class TestDummyDomain(TestDomain):
|
||||||
|
|
||||||
def test_domain(self):
|
def test_domain(self):
|
||||||
self.check_domain()
|
self.check_domain()
|
||||||
|
|
||||||
|
def test_routes(self):
|
||||||
|
self.check_routes()
|
||||||
|
|
Loading…
Reference in New Issue