def main():
    """Entry point to this script."""
    # Parse all CLI arguments.
    args = cli_arguments()
    verbose = args.verbose
    multiple = args.multiple
    input_file = args.input

    if multiple:
        # process multiple messages stored in one input file
        report = validate_multiple_messages(schema, input_file, verbose)
    else:
        # process single message stored in one input file
        report = validate_single_message(schema, input_file, verbose)

    # print report from schema validation
    print_report(report, args.nocolors)
Example #2
0
def test_validate_multiple_nonexistent_file():
    """Test the function validate_multiple_messages."""
    schema = Schema({})
    path_to_payload = "this_does_not_exists"

    # try to validate JSON file without errors
    result = validate_multiple_messages(schema, path_to_payload, True)

    # validate result
    assert result is not None
    assert "processed" in result
    assert "valid" in result
    assert "invalid" in result
    assert "error" in result

    # validate counters
    assert result["processed"] == 0
    assert result["valid"] == 0
    assert result["invalid"] == 0
    assert result["error"] == 1
Example #3
0
def test_validate_multiple_messages_wrong_file():
    """Test the function validate_multiple_messages."""
    schema = Schema({})
    path_to_payload = path_to_json("error.json")

    # try to validate JSON file without errors
    result = validate_multiple_messages(schema, path_to_payload, True)

    # validate result
    assert result is not None
    assert "processed" in result
    assert "valid" in result
    assert "invalid" in result
    assert "error" in result

    # validate counters
    assert result["processed"] == 1
    assert result["valid"] == 0
    assert result["invalid"] == 1
    assert result["error"] == 0