mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 18:54:08 +00:00
Show an error if both --alias and --host are defined (#513)
Display an error if both --alias and --host are defined to avoid ambiguous target device: ``` ❯ kasa --host 123 --alias 123 state Usage: kasa [OPTIONS] COMMAND [ARGS]... Try 'kasa --help' for help. Error: Use either --alias or --host, not both. ``` Also, use `click.BadOptionUsage` consistently for other errors, like when only `--username` or `--password` is given.
This commit is contained in:
@@ -183,9 +183,9 @@ async def test_credentials(discovery_data: dict, mocker):
|
||||
|
||||
@pytest.mark.parametrize("auth_param", ["--username", "--password"])
|
||||
async def test_invalid_credential_params(auth_param):
|
||||
"""Test for handling only one of username or password supplied."""
|
||||
runner = CliRunner()
|
||||
|
||||
# Test for handling only one of username or passowrd supplied.
|
||||
res = await runner.invoke(
|
||||
cli,
|
||||
[
|
||||
@@ -197,7 +197,25 @@ async def test_invalid_credential_params(auth_param):
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
assert res.exit_code == 0
|
||||
assert res.exit_code == 2
|
||||
assert (
|
||||
res.output == "Using authentication requires both --username and --password\n"
|
||||
"Error: Using authentication requires both --username and --password"
|
||||
in res.output
|
||||
)
|
||||
|
||||
|
||||
async def test_duplicate_target_device():
|
||||
"""Test that defining both --host or --alias gives an error."""
|
||||
runner = CliRunner()
|
||||
|
||||
res = await runner.invoke(
|
||||
cli,
|
||||
[
|
||||
"--host",
|
||||
"127.0.0.1",
|
||||
"--alias",
|
||||
"foo",
|
||||
],
|
||||
)
|
||||
assert res.exit_code == 2
|
||||
assert "Error: Use either --alias or --host, not both." in res.output
|
||||
|
Reference in New Issue
Block a user