From 2c446658e56245a83d7c76c36aebfe0e8864c649 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 7 Aug 2016 17:01:09 -0700 Subject: [PATCH] Improved tests --- .../graphene_sqlalchemy/registry.py | 5 ++- graphene/relay/tests/test_node_custom.py | 40 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/graphene-sqlalchemy/graphene_sqlalchemy/registry.py b/graphene-sqlalchemy/graphene_sqlalchemy/registry.py index e194529c..5062f1ab 100644 --- a/graphene-sqlalchemy/graphene_sqlalchemy/registry.py +++ b/graphene-sqlalchemy/graphene_sqlalchemy/registry.py @@ -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): diff --git a/graphene/relay/tests/test_node_custom.py b/graphene/relay/tests/test_node_custom.py index 73a17fc9..f6020381 100644 --- a/graphene/relay/tests/test_node_custom.py +++ b/graphene/relay/tests/test_node_custom.py @@ -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 = ''' {