From 9b2b6ebd06ac321c98128d023994a3c1b53812bf Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 15 Oct 2015 22:18:08 -0700 Subject: [PATCH] Improved tests with a real Schema --- tests/core/test_fields.py | 30 +++++++++++++----------------- tests/core/test_query.py | 6 +++++- tests/core/test_types.py | 3 ++- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/core/test_fields.py b/tests/core/test_fields.py index bb644306..c499d5b9 100644 --- a/tests/core/test_fields.py +++ b/tests/core/test_fields.py @@ -1,13 +1,6 @@ from py.test import raises from collections import namedtuple from pytest import raises -from graphene.core.fields import ( - Field, - StringField, - NonNullField -) - -from graphene.core.options import Options from graphql.core.type import ( GraphQLField, @@ -18,6 +11,15 @@ from graphql.core.type import ( GraphQLID, ) +from graphene.core.fields import ( + Field, + StringField, + NonNullField +) +from graphene.core.options import Options +from graphene.core.schema import Schema +from graphene.core.types import ObjectType + class ObjectType(object): _meta = Options() @@ -36,9 +38,6 @@ ot = ObjectType() ObjectType._meta.contribute_to_class(ObjectType, '_meta') -class Schema(object): - pass - schema = Schema() @@ -94,19 +93,16 @@ def test_field_resolve(): def test_field_resolve_type_custom(): - class MyCustomType(object): + class MyCustomType(ObjectType): pass - class Schema(object): - - def get_type(self, name): - if name == 'MyCustomType': - return MyCustomType + class OtherType(ObjectType): + pass s = Schema() f = Field('MyCustomType') - f.contribute_to_class(ot, 'field_name') + f.contribute_to_class(OtherType, 'field_name') field_type = f.get_object_type(s) assert field_type == MyCustomType diff --git a/tests/core/test_query.py b/tests/core/test_query.py index 473bc3d4..2f46f534 100644 --- a/tests/core/test_query.py +++ b/tests/core/test_query.py @@ -17,6 +17,7 @@ from graphene.core.types import ( Interface, ObjectType ) +from graphene.core.schema import Schema class Character(Interface): @@ -42,13 +43,16 @@ class Human(Character): # def resolve_friends(self, *args, **kwargs): # return 'HEY YOU!' -schema = object() + +schema = Schema() Human_type = Human.internal_type(schema) + def test_type(): assert Human._meta.fields_map['name'].resolve(Human(object()), 1, 2) == 'Peter' + def test_query(): schema = GraphQLSchema(query=Human_type) query = ''' diff --git a/tests/core/test_types.py b/tests/core/test_types.py index b9414131..9e3037e9 100644 --- a/tests/core/test_types.py +++ b/tests/core/test_types.py @@ -16,6 +16,7 @@ from graphql.core.type import ( from graphene.core.types import ( Interface ) +from graphene.core.schema import Schema class Character(Interface): @@ -33,7 +34,7 @@ class Human(Character): class Meta: type_name = 'core_Human' -schema = object() +schema = Schema() def test_interface():