예제 #1
0
def test_user_binary_file():
    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema(chr(4))
    assert str(i.value) == "Invalid YAML at []"
    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert (str(ir) == """Invalid YAML
```
unacceptable character #x0004: special characters are not allowed
  in "<unicode string>", position 0
```""")
    assert ir.get_annotations(".mergify.yml") == []
예제 #2
0
def config_validator():
    try:
        rules.validate_user_config(flask.request.files['data'].stream)
    except Exception as e:
        status = 400
        message = str(rules.InvalidRules(str(e)))
        if hasattr(e, 'problem_mark'):
            message += " (position %s:%s)" % (e.problem_mark.line + 1,
                                              e.problem_mark.column + 1)
    else:
        status = 200
        message = "The configuration is valid"

    return flask.Response(message, status=status, mimetype="text/plain")
예제 #3
0
def voluptuous_error(error):
    if error.path:
        if error.path[0] == "mergify.yml":
            error.path.pop(0)
    return str(rules.InvalidRules(error, ""))
예제 #4
0
def test_user_configuration_schema():
    with pytest.raises(voluptuous.Invalid) as exc_info:
        rules.UserConfigurationSchema("- no\n* way")
    assert str(exc_info.value) == "Invalid YAML at [line 2, column 2]"

    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema("""
            pull_request_rules:
              - name: ahah
                key: not really what we expected
            """)
    assert (str(i.value) ==
            "extra keys not allowed @ data['pull_request_rules'][0]['key']")

    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert str(ir) == (
        "* extra keys not allowed @ pull_request_rules → item 0 → key\n"
        "* required key not provided @ pull_request_rules → item 0 → actions\n"
        "* required key not provided @ pull_request_rules → item 0 → conditions"
    )
    assert [] == ir.get_annotations(".mergify.yml")

    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema("""invalid:
- *yaml
""")
    assert str(i.value) == "Invalid YAML at [line 2, column 3]"

    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert (str(ir) == """Invalid YAML @ line 2, column 3
```
found undefined alias 'yaml'
  in "<unicode string>", line 2, column 3:
    - *yaml
      ^
```""")
    assert [{
        "annotation_level":
        "failure",
        "end_column":
        3,
        "end_line":
        2,
        "message":
        "found undefined alias 'yaml'\n"
        '  in "<unicode string>", line 2, column 3:\n'
        "    - *yaml\n"
        "      ^",
        "path":
        ".mergify.yml",
        "start_column":
        3,
        "start_line":
        2,
        "title":
        "Invalid YAML",
    }] == ir.get_annotations(".mergify.yml")

    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema("""
pull_request_rules:
""")
    assert (str(
        i.value
    ) == "expected a list for dictionary value @ data['pull_request_rules']")
    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert str(
        ir) == "expected a list for dictionary value @ pull_request_rules"

    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema("")
    assert str(i.value) == "expected a dictionary"
    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert str(ir) == "expected a dictionary"

    with pytest.raises(voluptuous.Invalid) as i:
        rules.UserConfigurationSchema("""
            pull_request_rules:
              - name: add label
                conditions:
                  - conflict
                actions:
                  label:
                    add:
                      - conflict:
            """)
    assert (
        str(i.value) ==
        "expected str @ data['pull_request_rules'][0]['actions']['label']['add'][0]"
    )
    ir = rules.InvalidRules(i.value, ".mergify.yml")
    assert (
        str(ir) ==
        "expected str @ pull_request_rules → item 0 → actions → label → add → item 0"
    )