Added test for node connection edge.

This commit is contained in:
Markus Padourek 2016-09-12 15:28:13 +01:00
parent 94d46f7960
commit 73945fb569
2 changed files with 36 additions and 2 deletions

View File

@ -92,6 +92,16 @@ def test_edge_with_bases():
assert edge_fields['other'].type == String
def test_edge_on_node():
Edge = MyObject.Connection.Edge
assert Edge._meta.name == 'MyObjectEdge'
edge_fields = Edge._meta.fields
assert list(edge_fields.keys()) == ['node', 'cursor']
assert isinstance(edge_fields['node'], Field)
assert edge_fields['node'].type == MyObject
def test_pageinfo():
assert PageInfo._meta.name == 'PageInfo'
fields = PageInfo._meta.fields

View File

@ -1,15 +1,26 @@
from collections import OrderedDict
import pytest
from ...types import (Argument, Field, InputField, InputObjectType, ObjectType,
Schema, AbstractType, NonNull)
from ...types.scalars import String
from ..connection import Connection
from ..mutation import ClientIDMutation
from ..node import Node
class SharedFields(AbstractType):
shared = String()
class MyNode(ObjectType):
class Meta:
interfaces = (Node, )
name = String()
class SaySomething(ClientIDMutation):
class Input:
@ -28,12 +39,16 @@ class OtherMutation(ClientIDMutation):
additional_field = String()
name = String()
my_node_edge = Field(MyNode.Connection.Edge)
@classmethod
def mutate_and_get_payload(cls, args, context, info):
shared = args.get('shared', '')
additionalField = args.get('additionalField', '')
return SaySomething(name=shared + additionalField)
edge_type = MyNode.Connection.Edge
return OtherMutation(name=shared + additionalField,
my_node_edge=edge_type(
cursor='1', node=MyNode(name='name')))
class RootQuery(ObjectType):
@ -81,7 +96,7 @@ def test_mutation_input():
def test_subclassed_mutation():
fields = OtherMutation._meta.fields
assert list(fields.keys()) == ['name']
assert list(fields.keys()) == ['name', 'my_node_edge']
assert isinstance(fields['name'], Field)
field = OtherMutation.Field()
assert field.type == OtherMutation
@ -110,3 +125,12 @@ def test_subclassed_mutation_input():
# )
# assert not executed.errors
# assert executed.data == {'say': {'phrase': 'hello'}}
def test_edge_query():
executed = schema.execute(
'mutation a { other(input: {clientMutationId:"1"}) { myNodeEdge { cursor node { name }} } }'
)
assert not executed.errors
assert executed.data == OrderedDict(
{'other': OrderedDict({'myNodeEdge': OrderedDict({'cursor': '1', 'node': OrderedDict({'name': 'name'})})})}
)