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)
Ejemplo n.º 2
0
def test_validate_single_message_no_data():
    """Test the function validate_single_message."""
    schema = Schema({})

    # try to validate JSON file that does not exists
    result = validate_single_message(schema, "this_does_not_exists.json", 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
Ejemplo n.º 3
0
def test_validate_single_message_error_data():
    """Test the function validate_single_message."""
    schema = Schema({})
    path_to_payload = path_to_json("error.json")

    # try to validate JSON file containing errors
    result = validate_single_message(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"] == 1
    assert result["error"] == 0