def test_field_orders_wrong_type(): field = Field(None) try: assert not field < 1 except TypeError: # Fix exception raising in Python3+ pass
def test_field_none_type_raises_error(): s = Schema() f = Field(None) f.contribute_to_class(MyOt, 'field_name') with raises(Exception) as excinfo: s.T(f) assert str( excinfo.value) == "Internal type for field MyOt.field_name is None"
def test_field_added_in_meta(): opt = Options(Meta) class ObjectType(object): pass opt.contribute_to_class(ObjectType, '_meta') f = Field(None) f.attname = 'string_field' opt.add_field(f) assert f in opt.fields
class Human(Character): friends = List(Character) pet = Field(Pet) def resolve_name(self, *args): return 'Peter' def resolve_friend(self, *args): return Human(object()) def resolve_pet(self, *args): return Pet(object())
def test_field_resolve_type_custom(): class MyCustomType(ObjectType): pass f = Field('MyCustomType') class OtherType(ObjectType): field_name = f s = Schema() s.query = OtherType s.register(MyCustomType) assert s.T(f).type == s.T(MyCustomType)
class Query(ObjectType): f = Field(Character) def resolve_f(self, args, info): return Human()
def test_field_name_use_name_if_exists(): f = Field(GraphQLString, name='my_custom_name') f.contribute_to_class(MyOt, 'field_name') assert f.name == 'my_custom_name'
def test_field_name_automatic_camelcase(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert f.name == 'fieldName'
def test_field_type(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert isinstance(schema.T(f), GraphQLField) assert schema.T(f).type == GraphQLString
def test_field_no_contributed_raises_error(): f = Field(GraphQLString) with raises(Exception): schema.T(f)
def test_field_hash(): f1 = Field(None) f2 = Field(None) assert hash(f1) != hash(f2)
def test_field_eq_wrong_type(): field = Field(None) assert field != 1
def test_field_eq(): f1 = Field(None) f2 = Field(None) assert f1 != f2
def test_field_orders(): f1 = Field(None) f2 = Field(None) assert f1 < f2
def test_field_name(): f = Field(GraphQLString) f.contribute_to_class(MyOt, 'field_name') assert f.name is None assert f.attname == 'field_name'