Refactored Django tests

This commit is contained in:
Syrus Akbary 2016-06-21 23:56:38 -07:00
parent 91be6ac51e
commit 24cb8306c0
3 changed files with 39 additions and 39 deletions

View File

@ -0,0 +1,37 @@
import graphene
from graphene import Schema
from ..types import DjangoNode, DjangoObjectType
from .models import Article, Reporter
class Character(DjangoNode, DjangoObjectType):
class Meta:
model = Reporter
def get_node(self, id, context, info):
pass
class Human(DjangoNode, DjangoObjectType):
raises = graphene.String()
class Meta:
model = Article
def resolve_raises(self, *args):
raise Exception("This field should raise exception")
def get_node(self, id):
pass
class Query(graphene.ObjectType):
human = graphene.Field(Human)
def resolve_human(self, args, context, info):
return Human()
schema = Schema(query=Query)

View File

@ -5,7 +5,7 @@ from six import StringIO
@patch('graphene_django.management.commands.graphql_schema.Command.save_file')
def test_generate_file_on_call_graphql_schema(savefile_mock, settings):
settings.GRAPHENE_SCHEMA = 'graphene_django.tests.urls'
settings.GRAPHENE_SCHEMA = 'graphene_django.tests.schema'
out = StringIO()
management.call_command('graphql_schema', schema='', stdout=out)
assert "Successfully dumped GraphQL schema to schema.json" in out.getvalue()

View File

@ -1,44 +1,7 @@
from django.conf.urls import url
import graphene
from graphene import Schema
from ..types import DjangoNode, DjangoObjectType
from ..views import GraphQLView
from .models import Article, Reporter
class Character(DjangoNode, DjangoObjectType):
class Meta:
model = Reporter
def get_node(self, id, context, info):
pass
class Human(DjangoNode, DjangoObjectType):
raises = graphene.String()
class Meta:
model = Article
def resolve_raises(self, *args):
raise Exception("This field should raise exception")
def get_node(self, id):
pass
class Query(graphene.ObjectType):
human = graphene.Field(Human)
def resolve_human(self, args, context, info):
return Human()
schema = Schema(query=Query)
from .schema import schema
urlpatterns = [
url(r'^graphql', GraphQLView.as_view(schema=schema)),