You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
2.3 KiB

from mock import patch
from graphene import Interface, ObjectType, Schema
from graphene.relay import Node
from ..registry import reset_global_registry
from ..types import DjangoObjectType
from .models import Article as ArticleModel
from .models import Reporter as ReporterModel
class Reporter(DjangoObjectType):
'''Reporter description'''
class Meta:
model = ReporterModel
class Article(DjangoObjectType):
'''Article description'''
class Meta:
model = ArticleModel
interfaces = (Node, )
class RootQuery(ObjectType):
node = Node.Field()
schema = Schema(query=RootQuery, types=[Article, Reporter])
def test_django_interface():
assert issubclass(Node, Interface)
assert issubclass(Node, Node)
@patch('graphene_django.tests.models.Article.objects.get', return_value=Article(id=1))
def test_django_get_node(get):
article = Article.get_node(1, None, None)
assert == 1
def test_django_objecttype_map_correct_fields():
fields = Reporter._meta.fields
assert list(fields.keys()) == ['id', 'first_name', 'last_name', 'email', 'pets', 'a_choice', 'articles', 'films']
def test_django_objecttype_with_node_have_correct_fields():
fields = Article._meta.fields
assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'lang', 'importance']
def test_schema_representation():
expected = """
schema {
query: RootQuery
type Article implements Node {
id: ID!
headline: String
pubDate: DateTime
reporter: Reporter
lang: ArticleLang
importance: ArticleImportance
type ArticleConnection {
pageInfo: PageInfo!
edges: [ArticleEdge]
type ArticleEdge {
node: Article
cursor: String!
enum ArticleImportance {
enum ArticleLang {
scalar DateTime
interface Node {
id: ID!
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
type Reporter {
id: ID
firstName: String
lastName: String
email: String
pets: [Reporter]
aChoice: ReporterA_choice
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
enum ReporterA_choice {
type RootQuery {
node(id: ID!): Node
assert str(schema) == expected