Exemplo n.º 1
0
def test_missing_non_nullable_arg_without_default():
    arg = Argument("foo", NonNullType(Int))
    field = Field("test", Int, [arg])
    node = _test_node()
    with pytest.raises(CoercionError) as exc_info:
        coerce_argument_values(field, node)
    assert (
        str(exc_info.value)
        == 'Argument "foo" of required type "Int!" was not provided'
    )
Exemplo n.º 2
0
def test_provided_unknown_variable_without_default_non_nullable():
    arg = Argument("foo", NonNullType(Int))
    field = Field("test", Int, [arg])
    node = _test_node(_var("bar"))
    with pytest.raises(CoercionError) as exc_info:
        coerce_argument_values(field, node)
    assert str(exc_info.value) == (
        'Argument "foo" of required type "Int!" was provided the missing '
        'variable "$bar"'
    )
Exemplo n.º 3
0
def test_provided_invalid_value():
    arg = Argument("foo", Int)
    field = Field("test", Int, [arg])
    node = _test_node(_ast.StringValue(value="foo"))
    with pytest.raises(CoercionError) as exc_info:
        assert coerce_argument_values(field, node)
    assert str(exc_info.value) == (
        'Argument "foo" of type "Int" was provided invalid value "foo" '
        "(Invalid literal StringValue)"
    )
Exemplo n.º 4
0
def test_custom_python_name_in_input_object():
    arg = Argument(
        "foo",
        NonNullType(
            InputObjectType(
                "Foo",
                [InputField("field", NonNullType(Int), python_name="value")],
            )
        ),
    )
    field = Field("test", Int, [arg])
    node = _test_node(parse_value("{ field: 42 }"))
    assert coerce_argument_values(field, node) == {"foo": {"value": 42}}
Exemplo n.º 5
0
def test_provided_unknown_variable_without_default_nullable():
    arg = Argument("foo", Int)
    field = Field("test", Int, [arg])
    node = _test_node(_var("bar"))
    assert coerce_argument_values(field, node) == {}
Exemplo n.º 6
0
def test_provided_known_variable():
    arg = Argument("foo", Int)
    field = Field("test", Int, [arg])
    node = _test_node(_var("bar"))
    assert coerce_argument_values(field, node, {"bar": 42}) == {"foo": 42}
Exemplo n.º 7
0
def test_provided_value():
    arg = Argument("foo", Int)
    field = Field("test", Int, [arg])
    node = _test_node(_ast.IntValue(value="42"))
    assert coerce_argument_values(field, node) == {"foo": 42}
Exemplo n.º 8
0
def test_missing_non_nullable_arg_with_default():
    arg = Argument("foo", NonNullType(Int), default_value=42)
    field = Field("test", Int, [arg])
    node = _test_node()
    assert coerce_argument_values(field, node) == {"foo": 42}
Exemplo n.º 9
0
def test_missing_nullable_arg_without_default():
    arg = Argument("foo", Int)
    field = Field("test", Int, [arg])
    node = _test_node()
    assert coerce_argument_values(field, node) == {}
Exemplo n.º 10
0
def test_custom_python_name():
    arg = Argument("foo", NonNullType(Int), python_name="other_name")
    field = Field("test", Int, [arg])
    node = _test_node(_ast.IntValue(value="42"))
    assert coerce_argument_values(field, node) == {"other_name": 42}