Skip to content

Commit

Permalink
Merge pull request #311 from victor-torres/cli-host-option
Browse files Browse the repository at this point in the history
Receiving --host or -H option via CLI and writing test cases.
  • Loading branch information
hjacobs committed Oct 10, 2016
2 parents c3ab17d + 22a0db3 commit 5892feb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions connexion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def main():
@click.argument('spec_file')
@click.argument('base_module_path', required=False)
@click.option('--port', '-p', default=5000, type=int, help='Port to listen.')
@click.option('--host', '-H', type=str, help='Host interface to bind on.')
@click.option('--wsgi-server', '-w', default='flask',
type=click.Choice(['flask', 'gevent', 'tornado']),
callback=validate_wsgi_server_requirements,
Expand Down Expand Up @@ -79,6 +80,7 @@ def main():
def run(spec_file,
base_module_path,
port,
host,
wsgi_server,
stub,
mock,
Expand Down Expand Up @@ -141,6 +143,7 @@ def run(spec_file,
**api_extra_args)

app.run(port=port,
host=host,
server=wsgi_server,
debug=debug)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def test_run_simple_spec(mock_app_run, spec_file):
app_instance = mock_app_run()
app_instance.run.assert_called_with(
port=default_port,
host=None,
server=None,
debug=False)


def test_run_spec_with_host(mock_app_run, spec_file):
default_port = 5000
runner = CliRunner()
runner.invoke(main, ['run', spec_file, '--host', 'custom.host'], catch_exceptions=False)

app_instance = mock_app_run()
app_instance.run.assert_called_with(
port=default_port,
host='custom.host',
server=None,
debug=False)

Expand Down

0 comments on commit 5892feb

Please sign in to comment.