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_save_api_key(self, key_option):
"""Save API key to configuration file."""
runner = CliRunner()
api_key = ""
expected_config = {
"api_key": api_key,
"api_server": DEFAULT_CONFIG["api_server"],
"timeout": DEFAULT_CONFIG["timeout"],
}
expected_output = "Configuration saved to {!r}\n".format(CONFIG_FILE)
with patch("greynoise.cli.subcommand.save_config") as save_config:
result = runner.invoke(subcommand.setup, [key_option, api_key])
assert result.exit_code == 0
assert result.output == expected_output
save_config.assert_called_with(expected_config)
def test_setup(self, api_key_option):
"""Setup subcommand called."""
args = parse_arguments(["setup", api_key_option, ""])
assert args.func == setup
parser.add_argument("-k", "--api-key", help="Key to include in API requests")
parser.add_argument(
"-f",
"--format",
choices=["json", "xml"],
default="json",
help="Output format (%(default)s by default",
)
subparsers = parser.add_subparsers(help="Subcommands")
setup_parser = subparsers.add_parser("setup", help=setup.__doc__.rstrip("."))
setup_parser.add_argument(
"-k", "--api-key", required=True, help="Key to include in API requests"
)
setup_parser.set_defaults(func=setup)
noise_parser = subparsers.add_parser("noise", help=noise.__doc__.rstrip("."))
noise_parser.add_argument(
"-d",
"--date",
type=date_parameter,
help="Date to use as filter (format: YYYY-MM-DD)",
)
noise_parser.set_defaults(func=noise)
context_parser = subparsers.add_parser("context", help=context.__doc__.rstrip("."))
context_parser.add_argument(
"ip_address", type=ip_address_parameter, help="IP address"
)
context_parser.set_defaults(func=context)
def parse_arguments(argv):
"""Parse command line arguments."""
parser = ArgumentParser(description=__doc__)
parser.set_defaults(func=lambda args: parser.print_help())
parser.add_argument("-k", "--api-key", help="Key to include in API requests")
parser.add_argument(
"-f",
"--format",
choices=["json", "xml"],
default="json",
help="Output format (%(default)s by default",
)
subparsers = parser.add_subparsers(help="Subcommands")
setup_parser = subparsers.add_parser("setup", help=setup.__doc__.rstrip("."))
setup_parser.add_argument(
"-k", "--api-key", required=True, help="Key to include in API requests"
)
setup_parser.set_defaults(func=setup)
noise_parser = subparsers.add_parser("noise", help=noise.__doc__.rstrip("."))
noise_parser.add_argument(
"-d",
"--date",
type=date_parameter,
help="Date to use as filter (format: YYYY-MM-DD)",
)
noise_parser.set_defaults(func=noise)
context_parser = subparsers.add_parser("context", help=context.__doc__.rstrip("."))
context_parser.add_argument(