Skip to content

Commit 41dc694

Browse files
committed
test: Add test_relay_query.test_should_get_node_by_id
Add Reporter.id as the primary key and assign it in fixtures.
1 parent 69bf0d4 commit 41dc694

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

graphene_mongo/tests/fixtures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setup_fixtures():
1717
article2.save()
1818

1919
Reporter.drop_collection()
20-
reporter = Reporter(first_name='Allen', last_name='Iverson',
20+
reporter = Reporter(id='1', first_name='Allen', last_name='Iverson',
2121
email='[email protected]', awards=['2010-mvp'])
2222
reporter.articles = [article1, article2]
2323
embedded_article1 = EmbeddedArticle(

graphene_mongo/tests/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EmbeddedArticle(EmbeddedDocument):
4545
class Reporter(Document):
4646
meta = {'collection': 'test_repoter'}
4747

48+
id = StringField(primary_key=True)
4849
first_name = StringField(required=True)
4950
last_name = StringField(required=True)
5051
email = EmailField()

graphene_mongo/tests/test_relay_query.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class Mutation(graphene.ObjectType):
189189
schema = graphene.Schema(query=Query, mutation=Mutation)
190190
result = schema.execute(query)
191191
assert not result.errors
192-
# assert result.data == expected
192+
assert result.data == expected
193193

194194
def test_should_filter():
195195

@@ -231,6 +231,33 @@ class Query(graphene.ObjectType):
231231
assert result.data == expected
232232

233233

234+
def test_should_get_node_by_id():
235+
class Query(graphene.ObjectType):
236+
node = Node.Field()
237+
reporters = MongoengineConnectionField(ReporterNode)
238+
239+
query = '''
240+
query ReportersQuery {
241+
reporter: node(id: "UmVwb3J0ZXJOb2RlOjE=") {
242+
id,
243+
... on ReporterNode {
244+
firstName
245+
}
246+
}
247+
}
248+
'''
249+
expected = {
250+
'reporter': {
251+
'id': 'UmVwb3J0ZXJOb2RlOjE=',
252+
'firstName': 'Allen'
253+
}
254+
}
255+
schema = graphene.Schema(query=Query)
256+
result = schema.execute(query)
257+
assert not result.errors
258+
assert result.data == expected
259+
260+
234261
def test_should_first_n():
235262

236263
class Query(graphene.ObjectType):

0 commit comments

Comments
 (0)