def test_given_field_arg_has_default_when_field_arg_is_not_set_then_default_is_used(): Root = schema.ObjectType( "Root", fields=( schema.field("one", type=schema.Int, params=[ schema.param("arg0", type=schema.Int, default=None), schema.param("arg1", type=schema.Int, default=42), ]), ), ) field_query = Root.fields.one() assert_that(field_query.args, has_attrs( arg0=None, arg1=42, ))
def test_object_type_has_field_param_types_in_child_types(self): User = schema.ObjectType("User", fields=lambda: ( schema.field("name", type=schema.String, params=( schema.param("long", type=schema.Boolean), )), )) collected_types = schema.collect_types((User, )) assert_that(collected_types, includes(schema.Boolean))
def test_given_field_arg_has_no_default_when_field_arg_is_not_set_then_error_is_raised(): Root = schema.ObjectType( "Root", fields=( schema.field("one", type=schema.Int, params=[ schema.param("arg0", type=schema.Int), ]), ), ) error = pytest.raises(ValueError, lambda: Root.fields.one()) assert_that(str(error.value), equal_to("missing value for arg0"))
def test_arguments_are_coerced(): Root = schema.ObjectType( "Root", fields=( schema.field("one", type=schema.Int, params=[ schema.param("arg", type=schema.Int), ]), ), ) error = pytest.raises(GraphError, lambda: Root.fields.one(Root.fields.one.params.arg(None))) assert_that(str(error.value), equal_to("cannot coerce None to Int"))
def test_field_query_string_includes_args(self): Book = schema.ObjectType("Book", fields=( schema.field("title", schema.String, params=( schema.param("truncate", schema.Int), )), )) query = schema.key("title", Book.fields.title(Book.fields.title.params.truncate(42))) assert_that(query.to_string(Book), equal_to(dedent(""" FieldQuery( key="title", field=Book.fields.title, type_query=scalar_query, args=( Book.fields.title.params.truncate(42), ), ) """)))
def test_params_are_accessible_with_trailing_underscore(): params = schema.Params("book", ( schema.param("class", type=schema.String), )) assert_that(params.class_, equal_to(getattr(params, "class")))