Example #1
0
def test_when_no_argument_then_error(cli_runner):
    with cli_runner.isolated_filesystem():
        no_args_command_result = cli_runner.invoke(
            cli, [start_monitor_command.name])

        assert no_args_command_result.exit_code == exit_codes.INVALID_ARGUMENT_EXIT_CODE
        assert string_contains(
            no_args_command_result.output,
            f" Invalid value for \"{start_monitor_command.config_file.short_name}\" / \"{start_monitor_command.config_file.long_name}\": The supplied config file path must exist and not be a directory."
        )
Example #2
0
 def verify_exception(self, exception, message_substring):
     try:
         self.function()
     except exception as e:
         assert string_contains(
             e.args[0], message_substring
         ), f"Expected exception message to contain string '{message_substring}', but got '{e.args[0]}'!"
         return
     raise Exception(
         f"Expected function to raise exception of type '{exception.__name__}', but function did not raise exception!"
     )
Example #3
0
def test_when_config_file_does_not_adhere_to_schema_then_error(cli_runner):
    config_file_name = 'my-config-file.json'
    with cli_runner.isolated_filesystem():
        create_file(config_file_name, '{}')
        command_result = cli_runner.invoke(cli, [
            start_monitor_command.name,
            start_monitor_command.config_file.short_name, config_file_name
        ])
        assert command_result.exit_code == exit_codes.INVALID_ARGUMENT_EXIT_CODE
        assert string_contains(
            command_result.output,
            f"Error parsing config file at '{os.path.abspath(config_file_name)}', path '[]': "
            f"'\'monitors\' is a required property'.")
Example #4
0
def test_when_config_file_exists_and_is_empty_then_error(cli_runner):
    config_file_name = 'my-config-file.json'
    with cli_runner.isolated_filesystem():
        create_empty_file(config_file_name)
        command_result = cli_runner.invoke(cli, [
            start_monitor_command.name,
            start_monitor_command.config_file.short_name, config_file_name
        ])
        assert command_result.exit_code == exit_codes.INVALID_ARGUMENT_EXIT_CODE
        assert string_contains(
            command_result.output, f"Could not parse JSON file at "
            f"'{os.path.abspath(config_file_name)}'. Failure at line '1', column '1':"
        )
Example #5
0
 def verify_json_schema_exception(self, exception, message_substring,
                                  absolute_path):
     try:
         self.function()
     except exception as e:
         assert string_contains(
             e.args[0], message_substring
         ), f"Expected exception message to contain string '{message_substring}', but got '{e.args[0]}'!"
         assert list(
             e.absolute_path
         ) == absolute_path, f"Expected exception to have occurred at object path '{absolute_path}', but got exception at object path '{e.absolute_path}'!"
         return
     raise Exception(
         f"Expected function to raise exception of type '{exception.__name__}', but function did not raise exception!"
     )