Skip to content

Commit

Permalink
Validation for --port, closes #1226
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 18, 2021
1 parent d2d53a5 commit 36a44bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions datasette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ def plugins(all, plugins_dir):
"-p",
"--port",
default=8001,
type=click.IntRange(1, 65535),
help="Port to run the server on, defaults to 8001",
)
@click.option("--title", help="Title for metadata")
Expand Down Expand Up @@ -329,6 +330,7 @@ def uninstall(packages, yes):
"-p",
"--port",
default=8001,
type=click.IntRange(0, 65535),
help="Port for server, defaults to 8001. Use -p 0 to automatically assign an available port.",
)
@click.option(
Expand Down
8 changes: 8 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ def test_version():
assert result.output == f"cli, version {__version__}\n"


@pytest.mark.parametrize("invalid_port", ["-1", "0.5", "dog", "65536"])
def test_serve_invalid_ports(ensure_eventloop, invalid_port):
runner = CliRunner(mix_stderr=False)
result = runner.invoke(cli, ["--port", invalid_port])
assert result.exit_code == 2
assert "Invalid value for '-p'" in result.stderr


def test_setting(ensure_eventloop):
runner = CliRunner()
result = runner.invoke(
Expand Down

0 comments on commit 36a44bf

Please sign in to comment.