mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 11:33:55 +03:00
Refactored Django tests
This commit is contained in:
parent
91be6ac51e
commit
24cb8306c0
37
graphene-django/graphene_django/tests/schema.py
Normal file
37
graphene-django/graphene_django/tests/schema.py
Normal 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)
|
|
@ -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()
|
||||
|
|
|
@ -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)),
|
||||
|
|
Loading…
Reference in New Issue
Block a user