From b3b32b47f852447177d5aebeb75e2145e6820b5f Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 30 Nov 2021 10:42:00 +0100 Subject: [PATCH] [cli.run] halfapi run SCHEMA.csv --- halfapi/cli/run.py | 11 +++++++++-- tests/test_halfapi.py | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/test_halfapi.py diff --git a/halfapi/cli/run.py b/halfapi/cli/run.py index f1e6e5c..ae3fec6 100644 --- a/halfapi/cli/run.py +++ b/halfapi/cli/run.py @@ -12,6 +12,7 @@ from .domain import list_api_routes from ..conf import (PROJECT_NAME, HOST, PORT, SCHEMA, PRODUCTION, LOGLEVEL, DOMAINSDICT, CONFIG) from ..logging import logger +from ..lib.schemas import schema_csv_dict @click.option('--host', default=HOST) @click.option('--port', default=PORT) @@ -20,9 +21,10 @@ from ..logging import logger @click.option('--production', default=True) @click.option('--loglevel', default=LOGLEVEL) @click.option('--prefix', default='') +@click.option('--check', default=True) @click.argument('schema', type=click.File('r'), required=False) @cli.command() -def run(host, port, reload, secret, production, loglevel, prefix, schema): +def run(host, port, reload, secret, production, loglevel, prefix, check, schema): """ The "halfapi run" command """ @@ -48,7 +50,12 @@ def run(host, port, reload, secret, production, loglevel, prefix, schema): sys.path.insert(0, os.getcwd()) - list_api_routes() + if schema: + # Populate the SCHEMA global with the data from the given file + for key, val in schema_csv_dict(schema).items(): + SCHEMA[key] = val + + # list_api_routes() click.echo(f'uvicorn.run("halfapi.app:application"\n' \ f'host: {host}\n' \ diff --git a/tests/test_halfapi.py b/tests/test_halfapi.py new file mode 100644 index 0000000..adea751 --- /dev/null +++ b/tests/test_halfapi.py @@ -0,0 +1,7 @@ +from halfapi.halfapi import HalfAPI + +def test_methods(): + assert 'application' in dir(HalfAPI) + assert 'routes' in dir(HalfAPI) + assert 'version' in dir(HalfAPI) + assert 'version_async' in dir(HalfAPI)