Improved tests with a real Schema

This commit is contained in:
Syrus Akbary 2015-10-15 22:18:08 -07:00
parent 71c6022b9e
commit 9b2b6ebd06
3 changed files with 20 additions and 19 deletions

View File

@ -1,13 +1,6 @@
from py.test import raises from py.test import raises
from collections import namedtuple from collections import namedtuple
from pytest import raises from pytest import raises
from graphene.core.fields import (
Field,
StringField,
NonNullField
)
from graphene.core.options import Options
from graphql.core.type import ( from graphql.core.type import (
GraphQLField, GraphQLField,
@ -18,6 +11,15 @@ from graphql.core.type import (
GraphQLID, 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): class ObjectType(object):
_meta = Options() _meta = Options()
@ -36,9 +38,6 @@ ot = ObjectType()
ObjectType._meta.contribute_to_class(ObjectType, '_meta') ObjectType._meta.contribute_to_class(ObjectType, '_meta')
class Schema(object):
pass
schema = Schema() schema = Schema()
@ -94,19 +93,16 @@ def test_field_resolve():
def test_field_resolve_type_custom(): def test_field_resolve_type_custom():
class MyCustomType(object): class MyCustomType(ObjectType):
pass pass
class Schema(object): class OtherType(ObjectType):
pass
def get_type(self, name):
if name == 'MyCustomType':
return MyCustomType
s = Schema() s = Schema()
f = Field('MyCustomType') f = Field('MyCustomType')
f.contribute_to_class(ot, 'field_name') f.contribute_to_class(OtherType, 'field_name')
field_type = f.get_object_type(s) field_type = f.get_object_type(s)
assert field_type == MyCustomType assert field_type == MyCustomType

View File

@ -17,6 +17,7 @@ from graphene.core.types import (
Interface, Interface,
ObjectType ObjectType
) )
from graphene.core.schema import Schema
class Character(Interface): class Character(Interface):
@ -42,13 +43,16 @@ class Human(Character):
# def resolve_friends(self, *args, **kwargs): # def resolve_friends(self, *args, **kwargs):
# return 'HEY YOU!' # return 'HEY YOU!'
schema = object()
schema = Schema()
Human_type = Human.internal_type(schema) Human_type = Human.internal_type(schema)
def test_type(): def test_type():
assert Human._meta.fields_map['name'].resolve(Human(object()), 1, 2) == 'Peter' assert Human._meta.fields_map['name'].resolve(Human(object()), 1, 2) == 'Peter'
def test_query(): def test_query():
schema = GraphQLSchema(query=Human_type) schema = GraphQLSchema(query=Human_type)
query = ''' query = '''

View File

@ -16,6 +16,7 @@ from graphql.core.type import (
from graphene.core.types import ( from graphene.core.types import (
Interface Interface
) )
from graphene.core.schema import Schema
class Character(Interface): class Character(Interface):
@ -33,7 +34,7 @@ class Human(Character):
class Meta: class Meta:
type_name = 'core_Human' type_name = 'core_Human'
schema = object() schema = Schema()
def test_interface(): def test_interface():