Skip to content

Commit 8630a23

Browse files
committed
new: Add test case for type register order
1 parent b78c8a3 commit 8630a23

File tree

4 files changed

+115
-1
lines changed

4 files changed

+115
-1
lines changed

graphene_mongo/tests/models.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,25 @@ class ProfessorVector(Document):
9898
meta = {'collection': 'test_professor_vector'}
9999
vec = ListField(FloatField())
100100
metadata = EmbeddedDocumentField(ProfessorMetadata)
101+
102+
103+
class ParentWithRelationship(Document):
104+
105+
meta = {'collection': 'test_parent_reference'}
106+
before_child = ReferenceField("ChildRegisteredBefore")
107+
after_child = ReferenceField("ChildRegisteredAfter")
108+
name = StringField()
109+
110+
111+
class ChildRegisteredBefore(Document):
112+
113+
meta = {'collection': 'test_child_before_reference'}
114+
parent = ReferenceField(ParentWithRelationship)
115+
name = StringField()
116+
117+
118+
class ChildRegisteredAfter(Document):
119+
120+
meta = {'collection': 'test_child_after_reference'}
121+
parent = ReferenceField(ParentWithRelationship)
122+
name = StringField()

graphene_mongo/tests/setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from .models import (
33
Article, Editor, EmbeddedArticle, Player,
44
Reporter, Child, ProfessorMetadata, ProfessorVector,
5+
ChildRegisteredBefore, ChildRegisteredAfter,
6+
ParentWithRelationship
57
)
68

79

@@ -105,3 +107,22 @@ def fixtures():
105107
metadata=professor_metadata
106108
)
107109
professor_vector.save()
110+
111+
ParentWithRelationship.drop_collection()
112+
ChildRegisteredAfter.drop_collection()
113+
ChildRegisteredBefore.drop_collection()
114+
115+
# This is one messed up family
116+
117+
# She'd better have presence this time
118+
child3 = ChildRegisteredBefore(name="Akari")
119+
child4 = ChildRegisteredAfter(name="Kyouko")
120+
child3.save()
121+
child4.save()
122+
123+
parent = ParentWithRelationship(name="Yui", before_child=child3, after_child=child4)
124+
parent.save()
125+
126+
child3.parent = child4.parent = parent
127+
child3.save()
128+
child4.save()

graphene_mongo/tests/test_relay_query.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
EditorNode,
1111
PlayerNode,
1212
ReporterNode,
13-
ChildNode,)
13+
ChildNode,
14+
ParentWithRelationshipNode)
1415
from ..fields import MongoengineConnectionField
1516

1617

@@ -648,3 +649,53 @@ class Query(graphene.ObjectType):
648649
assert not result.errors
649650
assert json.dumps(result.data, sort_keys=True) == json.dumps(
650651
expected, sort_keys=True)
652+
653+
654+
def test_should_lazy_reference(fixtures):
655+
656+
class Query(graphene.ObjectType):
657+
node = Node.Field()
658+
parents = MongoengineConnectionField(ParentWithRelationshipNode)
659+
660+
schema = graphene.Schema(query=Query)
661+
662+
query = """
663+
query {
664+
parents {
665+
edges {
666+
node {
667+
beforeChild {
668+
name,
669+
parent { name }
670+
},
671+
afterChild {
672+
name,
673+
parent { name }
674+
}
675+
}
676+
}
677+
}
678+
}
679+
"""
680+
681+
expected = {
682+
"parents": {
683+
"edges": [
684+
{"node": {
685+
"beforeChild": {
686+
"name": "Akari",
687+
"parent": {"name": "Yui"}
688+
},
689+
"afterChild": {
690+
"name": "Kyouko",
691+
"parent": {"name": "Yui"}
692+
}
693+
}}
694+
]
695+
}
696+
}
697+
698+
result = schema.execute(query)
699+
assert not result.errors
700+
assert json.dumps(result.data, sort_keys=True) == json.dumps(
701+
expected, sort_keys=True)

graphene_mongo/tests/types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from .models import (
55
Article, Editor, EmbeddedArticle, Player, Reporter,
66
Parent, Child, ProfessorMetadata, ProfessorVector,
7+
ParentWithRelationship, ChildRegisteredBefore,
8+
ChildRegisteredAfter
79
)
810

911

@@ -107,3 +109,21 @@ class ChildNode(MongoengineObjectType):
107109
class Meta:
108110
model = Child
109111
interfaces = (Node,)
112+
113+
114+
class ChildRegisteredBeforeNode(MongoengineObjectType):
115+
class Meta:
116+
model = ChildRegisteredBefore
117+
interfaces = (Node, )
118+
119+
120+
class ParentWithRelationshipNode(MongoengineObjectType):
121+
class Meta:
122+
model = ParentWithRelationship
123+
interfaces = (Node, )
124+
125+
126+
class ChildRegisteredAfterNode(MongoengineObjectType):
127+
class Meta:
128+
model = ChildRegisteredAfter
129+
interfaces = (Node, )

0 commit comments

Comments
 (0)