Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_args_with_incomplete_env_vars(limited_env, capsys):
parser = create_parser()
with pytest.raises(SystemExit):
parser.parse_args(["connect"])
captured = capsys.readouterr()
assert "the following arguments are required: --client-secret" in captured.err
def test_parse_args_with_only_config_file(mock_parse_config, clean_env):
parser = create_parser()
mock_parse_config.return_value = {
"base_url": "BASE_URL_CONFIG",
"client_id": "CLIENT_ID_CONFIG",
"client_secret": "CLIENT_SECRET_CONFIG",
}
args = parser.parse_args(["connect", "--config-file", "config.yml"])
assert args.base_url == "BASE_URL_CONFIG"
assert args.client_id == "CLIENT_ID_CONFIG"
assert args.client_secret == "CLIENT_SECRET_CONFIG"
def test_parse_args_with_mutually_exclusive_args_commit_ref(env, capsys):
parser = create_parser()
with pytest.raises(SystemExit):
parser.parse_args(["sql", "--remote-reset", "--commit-ref", "abc123"])
captured = capsys.readouterr()
assert (
"argument --commit-ref: not allowed with argument --remote-reset"
in captured.err
)
def test_arg_precedence(mock_parse_config, limited_env):
parser = create_parser()
# Precedence: command line > environment variables > config files
mock_parse_config.return_value = {
"base_url": "BASE_URL_CONFIG",
"client_id": "CLIENT_ID_CONFIG",
"client_secret": "CLIENT_SECRET_CONFIG",
}
args = parser.parse_args(
["connect", "--config-file", "config.yml", "--base-url", "BASE_URL_CLI"]
)
assert args.base_url == "BASE_URL_CLI"
assert args.client_id == "CLIENT_ID_ENV_VAR"
assert args.client_secret == "CLIENT_SECRET_CONFIG"
def test_env_var_override_argparse_default(env):
parser = create_parser()
args = parser.parse_args(["connect"])
assert args.port == 8080
def test_config_override_argparse_default(mock_parse_config, clean_env):
parser = create_parser()
mock_parse_config.return_value = {
"base_url": "BASE_URL_CONFIG",
"client_id": "CLIENT_ID_CONFIG",
"client_secret": "CLIENT_SECRET_CONFIG",
"port": 8080,
}
args = parser.parse_args(["connect", "--config-file", "config.yml"])
assert args.port == 8080
def test_parse_args_with_only_cli(clean_env):
parser = create_parser()
args = parser.parse_args(
[
"connect",
"--base-url",
"BASE_URL_CLI",
"--client-id",
"CLIENT_ID_CLI",
"--client-secret",
"CLIENT_SECRET_CLI",
]
)
assert args.base_url == "BASE_URL_CLI"
assert args.client_id == "CLIENT_ID_CLI"
assert args.client_secret == "CLIENT_SECRET_CLI"
def test_parse_args_with_no_arguments_supplied(clean_env, capsys):
parser = create_parser()
with pytest.raises(SystemExit):
parser.parse_args(["connect"])
captured = capsys.readouterr()
assert (
"the following arguments are required: --base-url, --client-id, --client-secret"
in captured.err
)
def test_parse_args_with_incomplete_config_file(mock_parse_config, clean_env, capsys):
parser = create_parser()
mock_parse_config.return_value = {
"base_url": "BASE_URL_CONFIG",
"client_id": "CLIENT_ID_CONFIG",
}
with pytest.raises(SystemExit):
parser.parse_args(["connect", "--config-file", "config.yml"])
captured = capsys.readouterr()
assert "the following arguments are required: --client-secret" in captured.err
def test_parse_args_with_only_env_vars(env):
parser = create_parser()
args = parser.parse_args(["connect"])
assert args.base_url == "BASE_URL_ENV_VAR"
assert args.client_id == "CLIENT_ID_ENV_VAR"
assert args.client_secret == "CLIENT_SECRET_ENV_VAR"