[conf][testfail] add SCHEMA dictionary to globals

This commit is contained in:
Maxime Alves LIRMM@home 2021-11-29 06:21:19 +01:00
parent 4dae2f3676
commit ac4aadc2df
4 changed files with 37 additions and 14 deletions

View File

@ -1,9 +1,8 @@
from .halfapi import HalfAPI from .halfapi import HalfAPI
from .conf import PRODUCTION, SECRET, DOMAINS, CONFIG from .conf import CONFIG, SCHEMA
from .logging import logger
application = HalfAPI({ logger.info('CONFIG: %s', CONFIG)
'PRODUCTION': PRODUCTION, logger.info('SCHEMA: %s', SCHEMA)
'SECRET': SECRET,
'DOMAINS': DOMAINS, application = HalfAPI(CONFIG, SCHEMA or None).application
'CONFIG': CONFIG,
}).application

View File

@ -9,8 +9,8 @@ import uvicorn
from .cli import cli from .cli import cli
from .domain import list_api_routes from .domain import list_api_routes
from ..conf import (PROJECT_NAME, HOST, PORT, from ..conf import (PROJECT_NAME, HOST, PORT, SCHEMA,
PRODUCTION, LOGLEVEL, DOMAINSDICT) PRODUCTION, LOGLEVEL, DOMAINSDICT, CONFIG)
from ..logging import logger from ..logging import logger
@click.option('--host', default=HOST) @click.option('--host', default=HOST)

View File

@ -53,6 +53,7 @@ HOST = '127.0.0.1'
PORT = '3000' PORT = '3000'
SECRET = '' SECRET = ''
CONF_FILE = os.environ.get('HALFAPI_CONF_FILE', '.halfapi/config') CONF_FILE = os.environ.get('HALFAPI_CONF_FILE', '.halfapi/config')
SCHEMA = {}
config = ConfigParser(allow_no_value=True) config = ConfigParser(allow_no_value=True)

View File

@ -2,21 +2,44 @@ from halfapi.halfapi import HalfAPI
def test_conf_production_default(): def test_conf_production_default():
halfapi = HalfAPI({ halfapi = HalfAPI({
'DOMAINS': {'test': True} 'domains': {'test': True}
}) })
assert halfapi.PRODUCTION is True assert halfapi.PRODUCTION is True
def test_conf_production_true(): def test_conf_production_true():
halfapi = HalfAPI({ halfapi = HalfAPI({
'PRODUCTION': True, 'production': True,
'DOMAINS': {'test': True} 'domains': {'test': True}
}) })
assert halfapi.PRODUCTION is True assert halfapi.PRODUCTION is True
def test_conf_production_false(): def test_conf_production_false():
halfapi = HalfAPI({ halfapi = HalfAPI({
'PRODUCTION': False, 'production': False,
'DOMAINS': {'test': True} 'domains': {'test': True}
}) })
assert halfapi.PRODUCTION is False assert halfapi.PRODUCTION is False
def test_conf_variables():
from halfapi.conf import (
CONFIG,
SCHEMA,
SECRET,
DOMAINSDICT,
PROJECT_NAME,
HOST,
PORT,
CONF_DIR
)
assert isinstance(CONFIG, dict)
assert isinstance(SCHEMA, dict)
assert isinstance(SECRET, str)
assert isinstance(DOMAINSDICT(), dict)
assert isinstance(PROJECT_NAME, str)
assert isinstance(HOST, str)
assert isinstance(PORT, str)
assert str(int(PORT)) == PORT
PORT = 'abc'
assert str(int(PORT)) == PORT
assert isinstance(CONF_DIR, str)