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 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

View File

@ -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 = '''

View File

@ -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():