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_requests_exception(self, api_client):
"""Error is displayed on requests library exception."""
runner = CliRunner()
expected = "API error: \n"
api_client.filter.side_effect = RequestException("")
result = runner.invoke(subcommand.filter, input="some text")
assert result.exit_code == -1
assert result.output == expected
def test_help(self):
"""Get help."""
runner = CliRunner()
expected_output = "Usage: greynoise [OPTIONS] COMMAND [ARGS]..."
result = runner.invoke(
subcommand.help_, parent=Context(main, info_name="greynoise")
)
assert result.exit_code == 0
assert expected_output in result.output
def test_no_ip_address_passed(self, api_client):
"""Usage is returned if no IP address or input file is passed."""
runner = CliRunner()
with patch("greynoise.cli.helper.sys") as sys:
sys.stdin.isatty.return_value = True
result = runner.invoke(
subcommand.quick, parent=Context(main, info_name="greynoise")
)
assert result.exit_code == -1
assert "Usage: greynoise quick" in result.output
api_client.quick.assert_not_called()
def test_input_file(self, api_client, ip_address, expected_response):
"""Report IP address as "interesting" from input file."""
runner = CliRunner()
api_client.interesting.return_value = expected_response
result = runner.invoke(subcommand.interesting, ["-i", StringIO(ip_address)])
assert result.exit_code == 0
assert result.output == ""
api_client.interesting.assert_called_with(ip_address=ip_address)
def test_not_implemented(self, api_client):
"""Not implemented error message returned."""
runner = CliRunner()
expected_output = "Error: 'alerts' subcommand is not implemented yet.\n"
api_client.not_implemented.side_effect = RequestFailure(501)
result = runner.invoke(subcommand.alerts)
api_client.not_implemented.assert_called_with("alerts")
assert result.exit_code == 1
assert result.output == expected_output
def test_not_implemented(self, api_client):
"""Not implemented error message returned."""
runner = CliRunner()
expected_output = "Error: 'account' subcommand is not implemented yet.\n"
api_client.not_implemented.side_effect = RequestFailure(501)
result = runner.invoke(subcommand.account)
api_client.not_implemented.assert_called_with("account")
assert result.exit_code == 1
assert result.output == expected_output
def test_missing_api_key(self):
"""Setup fails when api_key is not passed."""
runner = CliRunner()
expected_error = 'Error: Missing option "-k" / "--api-key"'
result = runner.invoke(subcommand.setup, [])
assert result.exit_code == 2
assert expected_error in result.output
def test_requests_exception(self, api_client):
"""Error is displayed on requests library exception."""
runner = CliRunner()
expected = "API error: \n"
api_client.analyze.side_effect = RequestException("")
result = runner.invoke(subcommand.analyze, input="some text")
assert result.exit_code == -1
assert result.output == expected
def test_not_implemented(self, api_client):
"""Not implemented error message returned."""
runner = CliRunner()
expected_output = "Error: 'signature' subcommand is not implemented yet.\n"
api_client.not_implemented.side_effect = RequestFailure(501)
result = runner.invoke(subcommand.signature)
api_client.not_implemented.assert_called_with("signature")
assert result.exit_code == 1
assert result.output == expected_output
def test_quick_check_failure(self):
"""Quick check subcommand fails if ip address validation fails."""
with pytest.raises(SystemExit):
parse_arguments(["quick_check", ""])