From ad6877a7e9cb6a7707f444509dd036c98bf90ae8 Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Tue, 23 Nov 2021 13:53:08 +0100 Subject: [PATCH] [run] add arguments for config --- halfapi/cli/run.py | 15 ++++++++++++--- tests/cli/test_cli_run.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 tests/cli/test_cli_run.py diff --git a/halfapi/cli/run.py b/halfapi/cli/run.py index cbc7cb7..f699f25 100644 --- a/halfapi/cli/run.py +++ b/halfapi/cli/run.py @@ -11,15 +11,24 @@ from .cli import cli from .domain import list_api_routes from ..conf import (PROJECT_NAME, HOST, PORT, PRODUCTION, LOGLEVEL, DOMAINSDICT) +from ..logging import logger -@click.option('--host', default=None) -@click.option('--port', default=None) +@click.option('--host', default=HOST) +@click.option('--port', default=PORT) @click.option('--reload', default=False) +@click.option('--secret', default=False) +@click.option('--production', default=True) +@click.option('--loglevel', default=LOGLEVEL) +@click.option('--prefix', default='') +@click.argument('schema', type=click.File('r'), required=False) @cli.command() -def run(host, port, reload): +def run(host, port, reload, secret, production, loglevel, prefix, schema): """ The "halfapi run" command """ + logger.debug('[run] host=%s port=%s reload=%s secret=%s production=%s loglevel=%s prefix=%s schema=%s', + host, port, reload, secret, production, loglevel, prefix, schema + ) if not host: host = HOST diff --git a/tests/cli/test_cli_run.py b/tests/cli/test_cli_run.py new file mode 100644 index 0000000..8fd736c --- /dev/null +++ b/tests/cli/test_cli_run.py @@ -0,0 +1,23 @@ +from click.testing import CliRunner +from halfapi.cli.cli import cli +import os +from unittest.mock import patch + + +def test_run_noproject(cli_runner): + with cli_runner.isolated_filesystem(): + result = cli_runner.invoke(cli, ['run']) + assert result.exit_code == 1 + +""" +def test_run_empty_project(cli_runner): + with cli_runner.isolated_filesystem(): + os.mkdir('dummy_domain') + result = cli_runner.invoke(cli, ['run', './dummy_domain']) + assert result.exit_code == 1 + +def test_run_dummy_project(project_runner): + with patch('uvicorn.run', autospec=True) as runMock: + result = project_runner.invoke(cli, ['run']) + runMock.assert_called_once() +"""