<s> import pytest <EOL> import graphene <EOL> from graphene . contrib . django import DjangoConnectionField , DjangoNode <EOL> from graphene . contrib . django . utils import DJANGO_FILTER_INSTALLED <EOL> from ... tests . models import Reporter <EOL> from . . plugin import DjangoDebugPlugin <EOL> pytestmark = pytest . mark . django_db <EOL> def test_should_query_field ( ) : <EOL> r1 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r1 . save ( ) <EOL> r2 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r2 . save ( ) <EOL> class ReporterType ( DjangoNode ) : <EOL> class Meta : <EOL> model = Reporter <EOL> class Query ( graphene . ObjectType ) : <EOL> reporter = graphene . Field ( ReporterType ) <EOL> def resolve_reporter ( self , * args , ** kwargs ) : <EOL> return Reporter . objects . first ( ) <EOL> query = '''<STR_LIT>''' <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : str ( Reporter . objects . order_by ( '<STR_LIT>' ) [ : <NUM_LIT:1> ] . query ) <EOL> } ] <EOL> } <EOL> } <EOL> schema = graphene . Schema ( query = Query , plugins = [ DjangoDebugPlugin ( ) ] ) <EOL> result = schema . execute ( query ) <EOL> assert not result . errors <EOL> assert result . data == expected <EOL> def test_should_query_list ( ) : <EOL> r1 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r1 . save ( ) <EOL> r2 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r2 . save ( ) <EOL> class ReporterType ( DjangoNode ) : <EOL> class Meta : <EOL> model = Reporter <EOL> class Query ( graphene . ObjectType ) : <EOL> all_reporters = ReporterType . List ( ) <EOL> def resolve_all_reporters ( self , * args , ** kwargs ) : <EOL> return Reporter . objects . all ( ) <EOL> query = '''<STR_LIT>''' <EOL> expected = { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ] , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : str ( Reporter . objects . all ( ) . query ) <EOL> } ] <EOL> } <EOL> } <EOL> schema = graphene . Schema ( query = Query , plugins = [ DjangoDebugPlugin ( ) ] ) <EOL> result = schema . execute ( query ) <EOL> assert not result . errors <EOL> assert result . data == expected <EOL> def test_should_query_connection ( ) : <EOL> r1 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r1 . save ( ) <EOL> r2 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r2 . save ( ) <EOL> class ReporterType ( DjangoNode ) : <EOL> class Meta : <EOL> model = Reporter <EOL> class Query ( graphene . ObjectType ) : <EOL> all_reporters = DjangoConnectionField ( ReporterType ) <EOL> def resolve_all_reporters ( self , * args , ** kwargs ) : <EOL> return Reporter . objects . all ( ) <EOL> query = '''<STR_LIT>''' <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ] <EOL> } , <EOL> } <EOL> schema = graphene . Schema ( query = Query , plugins = [ DjangoDebugPlugin ( ) ] ) <EOL> result = schema . execute ( query ) <EOL> assert not result . errors <EOL> assert result . data [ '<STR_LIT>' ] == expected [ '<STR_LIT>' ] <EOL> assert '<STR_LIT>' in result . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> query = str ( Reporter . objects . all ( ) [ : <NUM_LIT:1> ] . query ) <EOL> assert result . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] == query <EOL> @ pytest . mark . skipif ( not DJANGO_FILTER_INSTALLED , <EOL> reason = "<STR_LIT>" ) <EOL> def test_should_query_connectionfilter ( ) : <EOL> from graphene . contrib . django . filter import DjangoFilterConnectionField <EOL> r1 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r1 . save ( ) <EOL> r2 = Reporter ( last_name = '<STR_LIT>' ) <EOL> r2 . save ( ) <EOL> class ReporterType ( DjangoNode ) : <EOL> class Meta : <EOL> model = Reporter <EOL> class Query ( graphene . ObjectType ) : <EOL> all_reporters = DjangoFilterConnectionField ( ReporterType ) <EOL> def resolve_all_reporters ( self , * args , ** kwargs ) : <EOL> return Reporter . objects . all ( ) <EOL> query = '''<STR_LIT>''' <EOL> expected = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> } ] <EOL> } , <EOL> } <EOL> schema = graphene . Schema ( query = Query , plugins = [ DjangoDebugPlugin ( ) ] ) <EOL> result = schema . execute ( query ) <EOL> assert not result . errors <EOL> assert result . data [ '<STR_LIT>' ] == expected [ '<STR_LIT>' ] <EOL> assert '<STR_LIT>' in result . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> query = str ( Reporter . objects . all ( ) [ : <NUM_LIT:1> ] . query ) <EOL> assert result . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] == query </s>
