Python click.testing.CliRunner() Examples
The following are 30
code examples of click.testing.CliRunner().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click.testing
, or try the search function
.
Example #1
Source File: test_cloud.py From Paradrop with Apache License 2.0 | 7 votes |
def test_simple_cloud_commands(ControllerClient, format_result): commands = [ ["claim-node", "token"], ["create-node", "test"], ["delete-node", "test"], ["describe-node", "test"], ["group-add-node", "group", "node"], ["help"], ["list-groups"], ["list-nodes"], ["login"], ["logout"], ["rename-node", "node", "node"] ] format_result.return_value = "result" runner = CliRunner() for command in commands: result = runner.invoke(cloud.root, command, obj={}) print("Command {} exit code {}".format(command[0], result.exit_code)) assert result.exit_code == 0
Example #2
Source File: test_subcommand.py From pygreynoise with MIT License | 6 votes |
def test_input_file_invalid_ip_addresses_passsed(self, api_client): """Error returned if only invalid IP addresses are passed in input file.""" runner = CliRunner() expected = ( "Error: at least one valid IP address must be passed either as an " "argument (IP_ADDRESS) or through the -i/--input_file option." ) result = runner.invoke( subcommand.ip, ["-i", StringIO("not-an-ip")], parent=Context(main, info_name="greynoise"), ) assert result.exit_code == -1 assert "Usage: greynoise ip" in result.output assert expected in result.output api_client.ip.assert_not_called()
Example #3
Source File: test_subcommand.py From pygreynoise with MIT License | 6 votes |
def test_empty_input_file(self, api_client): """Error is returned if empty input fle is passed.""" runner = CliRunner() expected = ( "Error: at least one query must be passed either as an argument " "(QUERY) or through the -i/--input_file option." ) result = runner.invoke( subcommand.query, ["-i", StringIO()], parent=Context(main, info_name="greynoise"), ) assert result.exit_code == -1 assert "Usage: greynoise query" in result.output assert expected in result.output api_client.query.assert_not_called()
Example #4
Source File: test_subcommand.py From pygreynoise with MIT License | 6 votes |
def test_input_file_invalid_ip_addresses_passsed(self, api_client): """Error returned if only invalid IP addresses are passed in input file.""" runner = CliRunner() expected = ( "Error: at least one valid IP address must be passed either as an " "argument (IP_ADDRESS) or through the -i/--input_file option." ) result = runner.invoke( subcommand.interesting, ["-i", StringIO("not-an-ip")], parent=Context(main, info_name="greynoise"), ) assert result.exit_code == -1 assert "Usage: greynoise interesting" in result.output assert expected in result.output api_client.interesting.assert_not_called()
Example #5
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_not_implemented(self, api_client): """Not implemented error message returned.""" runner = CliRunner() expected_output = "Error: 'pcap' subcommand is not implemented yet.\n" api_client.not_implemented.side_effect = RequestFailure(501) result = runner.invoke(subcommand.pcap) api_client.not_implemented.assert_called_with("pcap") assert result.exit_code == 1 assert result.output == expected_output
Example #6
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
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
Example #7
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_interesting(self, api_client, ip_address, expected_response): """Report IP address as "interesting".""" runner = CliRunner() api_client.interesting.return_value = expected_response result = runner.invoke(subcommand.interesting, [ip_address]) assert result.exit_code == 0 assert result.output == "" api_client.interesting.assert_called_with(ip_address=ip_address)
Example #8
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
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)
Example #9
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_stdin_input(self, api_client, ip_address, expected_response): """Report IP address as "interesting" from stdin.""" runner = CliRunner() api_client.interesting.return_value = expected_response result = runner.invoke(subcommand.interesting, input=ip_address) assert result.exit_code == 0 assert result.output == "" api_client.interesting.assert_called_with(ip_address=ip_address)
Example #10
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_request_failure(self, api_client): """Error is displayed on API request failure.""" runner = CliRunner() api_client.query.side_effect = RequestFailure( 401, {"error": "forbidden", "status": "error"} ) expected = "API error: forbidden" result = runner.invoke(subcommand.query, ["<query>"]) assert result.exit_code == -1 assert expected in result.output
Example #11
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_api_key_not_found(self): """Error is displayed if API key is not found.""" runner = CliRunner() with patch("greynoise.cli.decorator.load_config") as load_config: load_config.return_value = {"api_key": ""} result = runner.invoke( subcommand.filter, input="some text", parent=Context(main, info_name="greynoise"), ) assert result.exit_code == -1 assert "Error: API key not found" in result.output
Example #12
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_query(self, api_client): """Run query.""" runner = CliRunner() query = "<query>" api_client.query.return_value = [] expected = json.dumps([[]], indent=4, sort_keys=True) result = runner.invoke(subcommand.query, ["-f", "json", query]) assert result.exit_code == 0 assert result.output.strip("\n") == expected api_client.query.assert_called_with(query=query)
Example #13
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_input_file(self, api_client): """Run query from input file.""" runner = CliRunner() query = "<query>" api_client.query.return_value = [] expected = json.dumps([[]], indent=4, sort_keys=True) result = runner.invoke(subcommand.query, ["-f", "json", "-i", StringIO(query)]) assert result.exit_code == 0 assert result.output.strip("\n") == expected api_client.query.assert_called_with(query=query)
Example #14
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_no_query_passed(self, api_client): """Usage is returned if no query 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.query, parent=Context(main, info_name="greynoise") ) assert result.exit_code == -1 assert "Usage: greynoise query" in result.output api_client.query.assert_not_called()
Example #15
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_quick(self, api_client, ip_address, output_format, expected): """Quickly check IP address.""" runner = CliRunner() api_client.quick.return_value = [ OrderedDict((("ip", ip_address), ("noise", True))) ] result = runner.invoke(subcommand.quick, ["-f", output_format, ip_address]) assert result.exit_code == 0 assert result.output.strip("\n") == expected api_client.quick.assert_called_with(ip_addresses=[ip_address])
Example #16
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
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()
Example #17
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_stdin_input(self, api_client, ip_addresses, mock_response, expected): """Quickly check IP address from stdin.""" runner = CliRunner() api_client.quick.return_value = mock_response result = runner.invoke( subcommand.quick, ["-f", "json"], input="\n".join(ip_addresses) ) assert result.exit_code == 0 assert result.output.strip("\n") == expected api_client.quick.assert_called_with(ip_addresses=ip_addresses)
Example #18
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_requests_exception(self, api_client): """Error is displayed on requests library exception.""" runner = CliRunner() expected = "API error: <error message>\n" api_client.interesting.side_effect = RequestException("<error message>") result = runner.invoke(subcommand.interesting, ["0.0.0.0"]) assert result.exit_code == -1 assert result.output == expected
Example #19
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_request_failure(self, api_client): """Error is displayed on API request failure.""" runner = CliRunner() api_client.filter.side_effect = RequestFailure( 401, {"error": "forbidden", "status": "error"} ) expected = "API error: forbidden\n" result = runner.invoke(subcommand.filter, input="some text") assert result.exit_code == -1 assert result.output == expected
Example #20
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_explicit_stdin_input(self, api_client, text, expected_output): """Filter text with IP addresses from stdin passed explicitly.""" runner = CliRunner() api_client.filter.return_value = expected_output result = runner.invoke(subcommand.filter, ["-i", "-"], input=text) assert result.exit_code == 0 assert result.output == "".join(expected_output) assert api_client.filter.call_args[0][0].read() == text assert api_client.filter.call_args[1] == {"noise_only": False}
Example #21
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_noise_only(self, api_client, text, expected_output): """Filter text with IP addresses from stdin using noise only flag.""" runner = CliRunner() api_client.filter.return_value = expected_output result = runner.invoke(subcommand.filter, ["--noise-only"], input=text) assert result.exit_code == 0 assert result.output == "".join(expected_output) assert api_client.filter.call_args[0][0].read() == text assert api_client.filter.call_args[1] == {"noise_only": True}
Example #22
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_stdin_input(self, api_client, text, expected_output): """Filter text with IP addresses from stdin.""" runner = CliRunner() api_client.filter.return_value = expected_output result = runner.invoke(subcommand.filter, input=text) assert result.exit_code == 0 assert result.output == "".join(expected_output) assert api_client.filter.call_args[0][0].read() == text assert api_client.filter.call_args[1] == {"noise_only": False}
Example #23
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_input_file(self, api_client, text, expected_output): """Filter text with IP addresses from file.""" runner = CliRunner() input_text = StringIO(text) api_client.filter.return_value = expected_output result = runner.invoke(subcommand.filter, ["-i", input_text]) assert result.exit_code == 0 assert result.output == "".join(expected_output) api_client.filter.assert_called_with(input_text, noise_only=False)
Example #24
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_not_implemented(self, api_client): """Not implemented error message returned.""" runner = CliRunner() expected_output = "Error: 'feedback' subcommand is not implemented yet.\n" api_client.not_implemented.side_effect = RequestFailure(501) result = runner.invoke(subcommand.feedback) api_client.not_implemented.assert_called_with("feedback") assert result.exit_code == 1 assert result.output == expected_output
Example #25
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_api_key_not_found(self): """Error is displayed if API key is not found.""" runner = CliRunner() with patch("greynoise.cli.decorator.load_config") as load_config: load_config.return_value = {"api_key": ""} result = runner.invoke( subcommand.analyze, input="some text", parent=Context(main, info_name="greynoise"), ) assert result.exit_code == -1 assert "Error: API key not found" in result.output
Example #26
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_requests_exception(self, api_client): """Error is displayed on requests library exception.""" runner = CliRunner() expected = "API error: <error message>\n" api_client.analyze.side_effect = RequestException("<error message>") result = runner.invoke(subcommand.analyze, input="some text") assert result.exit_code == -1 assert result.output == expected
Example #27
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_explicit_stdin_input(self, api_client, text): """Analyze text with IP addresses from stdin passed explicitly.""" runner = CliRunner() api_client.analyze.return_value = self.DEFAULT_API_RESPONSE result = runner.invoke(subcommand.analyze, ["-i", "-"], input=text) assert result.exit_code == 0 assert result.output == self.DEFAULT_OUTPUT assert api_client.analyze.call_args[0][0].read() == text
Example #28
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_stdin_input(self, api_client, text): """Analyze text with IP addresses from stdin.""" runner = CliRunner() api_client.analyze.return_value = self.DEFAULT_API_RESPONSE result = runner.invoke(subcommand.analyze, input=text) assert result.exit_code == 0 assert result.output == self.DEFAULT_OUTPUT assert api_client.analyze.call_args[0][0].read() == text
Example #29
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
def test_no_input_file(self, api_client, expected_output): """No input text passed.""" runner = CliRunner() api_client.analyze.return_value = expected_output with patch("greynoise.cli.subcommand.sys") as sys: sys.stdin.isatty.return_value = True result = runner.invoke(subcommand.analyze) assert result.exit_code == -1 assert expected_output in result.output api_client.analyze.assert_not_called()
Example #30
Source File: test_subcommand.py From pygreynoise with MIT License | 5 votes |
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