Improved tests

This commit is contained in:
Syrus Akbary 2016-08-07 17:01:09 -07:00
parent 27a0d4147f
commit 2c446658e5
2 changed files with 41 additions and 4 deletions

View File

@ -7,7 +7,10 @@ class Registry(object):
from .types import SQLAlchemyObjectType from .types import SQLAlchemyObjectType
assert issubclass(cls, SQLAlchemyObjectType), 'Only SQLAlchemyObjectType can be registered, received "{}"'.format(cls.__name__) assert issubclass(cls, SQLAlchemyObjectType), 'Only SQLAlchemyObjectType can be registered, received "{}"'.format(cls.__name__)
assert cls._meta.registry == self, 'Registry for a Model have to match.' assert cls._meta.registry == self, 'Registry for a Model have to match.'
assert cls._meta.model not in self._registry, 'SQLAlchemy model "{}" already associated with another type "{}".'.format(cls._meta.model, self._registry[cls._meta.model]) assert self.get_type_for_model(cls._meta.model) in [None, cls], (
'SQLAlchemy model "{}" already associated with '
'another type "{}".'
).format(cls._meta.model, self._registry[cls._meta.model])
self._registry[cls._meta.model] = cls self._registry[cls._meta.model] = cls
def get_type_for_model(self, model): def get_type_for_model(self, model):

View File

@ -1,6 +1,6 @@
from graphql import graphql from graphql import graphql
from ...types import ObjectType, Schema from ...types import ObjectType, Interface, Schema
from ...types.scalars import Int, String from ...types.scalars import Int, String
from ..node import Node from ..node import Node
@ -20,12 +20,16 @@ class CustomNode(Node):
return photo_data.get(id) return photo_data.get(id)
class BasePhoto(Interface):
width = Int()
class User(CustomNode, ObjectType): class User(CustomNode, ObjectType):
name = String() name = String()
class Photo(CustomNode, ObjectType): class Photo(CustomNode, BasePhoto, ObjectType):
width = Int() pass
user_data = { user_data = {
@ -45,6 +49,36 @@ class RootQuery(ObjectType):
schema = Schema(query=RootQuery, types=[User, Photo]) schema = Schema(query=RootQuery, types=[User, Photo])
def test_str_schema_correct():
print str(schema)
assert str(schema) == '''schema {
query: RootQuery
}
interface BasePhoto {
width: Int
}
interface Node {
id: ID!
}
type Photo implements Node, BasePhoto {
id: ID!
width: Int
}
type RootQuery {
node(id: ID!): Node
}
type User implements Node {
id: ID!
name: String
}
'''
def test_gets_the_correct_id_for_users(): def test_gets_the_correct_id_for_users():
query = ''' query = '''
{ {