[config][wip][nf] removal of "domains" and "domain" section

This commit is contained in:
Maxime Alves LIRMM@home 2021-12-03 09:41:00 +01:00
parent 3dc951c81e
commit d06857bf49
8 changed files with 31 additions and 41 deletions

View File

@ -9,16 +9,18 @@ import click
from .cli import cli
from ..conf import CONFIG
DOMAIN_CONF_STR="""
[domain]
name = {name}
router = {router}
"""
CONF_STR="""
[project]
name = {project_name}
host = {host}
port = {port}
production = {production}
[domain]
name = {domain_name}
router = {router}
"""
@ -27,4 +29,4 @@ def config():
"""
Lists config parameters and their values
"""
click.echo(CONF_STR)
click.echo(CONF_STR.format(**CONFIG))

View File

@ -50,7 +50,8 @@ def run(host, port, reload, secret, production, loglevel, prefix, check, dryrun,
click.echo(f'Launching application {PROJECT_NAME}')
CONFIG.get('domain')['name'] = domain
if secret:
CONFIG['secret'] = secret
if schema:
# Populate the SCHEMA global with the data from the given file

View File

@ -146,15 +146,4 @@ CONFIG = {
'host': HOST,
'port': PORT,
'dryrun': DRYRUN,
'domain': {
'name': None,
'router': None
},
'domain_config': {}
}
for domain in DOMAINS:
if domain not in config.sections():
continue
CONFIG['domain_config'][domain] = dict(config.items(domain))

View File

@ -54,35 +54,20 @@ class HalfAPI:
CONFIG = config.get('config', {})
DRYRUN = config.get('dryrun', False)
domain = config.get('domain')['name']
router = config.get('domain').get('router', None)
if not (domain):
raise NoDomainsException()
self.PRODUCTION = PRODUCTION
self.CONFIG = CONFIG
self.SECRET = SECRET
self.__application = None
m_domain = m_domain_router = m_domain_acl = None
if domain:
m_domain = importlib.import_module(domain)
if not router:
router = getattr('__router__', domain, '.routers')
m_domain_router = importlib.import_module(router, domain)
m_domain_acl = importlib.import_module(f'{domain}.acl')
if not(m_domain and m_domain_router and m_domain_acl):
raise Exception('Cannot import domain')
self.schema = domain_schema(m_domain)
routes = [ Route('/', JSONRoute(self.schema)) ]
""" HalfAPI routes (if not PRODUCTION, includes debug routes)
"""
routes = []
routes.append(
Route('/', JSONRoute({}))
)
routes.append(
Mount('/halfapi', routes=list(self.routes()))
)
@ -93,8 +78,11 @@ class HalfAPI:
for route in gen_schema_routes(routes_dict):
routes.append(route)
else:
"""
for route in gen_domain_routes(m_domain_router):
routes.append(route)
"""
pass
startup_fcts = []
@ -116,11 +104,13 @@ class HalfAPI:
on_startup=startup_fcts
)
"""
self.__application.add_middleware(
DomainMiddleware,
domain=domain,
config=CONFIG
)
"""
if SECRET:
self.SECRET = SECRET

View File

@ -81,7 +81,8 @@ def test_init_project(runner):
assert cp.has_option('project', 'name')
assert cp.get('project', 'name') == PROJNAME
assert cp.get('project', 'halfapi_version') == __version__
assert cp.has_section('domain')
# removal of domain section (0.6)
# assert cp.has_section('domain')
except AssertionError as exc:
subprocess.run(['tree', '-a', os.getcwd()])
raise exc

View File

@ -7,4 +7,3 @@ def test_config(cli_runner):
cp = ConfigParser()
cp.read_string(result.output)
assert cp.has_section('project')
assert cp.has_section('domain')

View File

@ -6,8 +6,16 @@ from unittest.mock import patch
def test_run_noproject(cli_runner):
with cli_runner.isolated_filesystem():
result = cli_runner.invoke(cli, ['config'])
print(result.stdout)
assert result.exit_code == 0
result = cli_runner.invoke(cli, ['run'])
assert result.exit_code == 1
try:
assert result.exit_code == 1
except AssertionError as exc:
print(result.stdout)
raise exc
"""
def test_run_empty_project(cli_runner):

View File

@ -27,7 +27,7 @@ def test_routes(application_debug):
r = c.get('/')
d_r = r.json()
assert isinstance(d_r, dict)
assert API_SCHEMA.validate(d_r)
# assert API_SCHEMA.validate(d_r)
"""
TODO: Find a way to test exception raising