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
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.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
def get_type_for_model(self, model):

View File

@ -1,6 +1,6 @@
from graphql import graphql
from ...types import ObjectType, Schema
from ...types import ObjectType, Interface, Schema
from ...types.scalars import Int, String
from ..node import Node
@ -20,12 +20,16 @@ class CustomNode(Node):
return photo_data.get(id)
class BasePhoto(Interface):
width = Int()
class User(CustomNode, ObjectType):
name = String()
class Photo(CustomNode, ObjectType):
width = Int()
class Photo(CustomNode, BasePhoto, ObjectType):
pass
user_data = {
@ -45,6 +49,36 @@ class RootQuery(ObjectType):
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():
query = '''
{