1+ from graphene_gae .ndb .fields import NdbKeyStringField
2+ from graphql_relay import to_global_id
13from tests .base_test import BaseTest
24
35import graphene
@@ -103,6 +105,27 @@ def resolve_articles(self):
103105
104106 self .assertIn ("Model 'bar' is not accessible by the schema." , str (context .exception .message ))
105107
108+ def testNdbObjectType_keyProperty_stringRepresentation_kindDoesntExist_raisesException (self ):
109+ with self .assertRaises (Exception ) as context :
110+ class ArticleType (NdbObjectType ):
111+ class Meta :
112+ model = Article
113+ only_fields = ('prop' ,)
114+
115+ prop = NdbKeyStringField ('foo' , 'bar' )
116+
117+ class QueryType (graphene .ObjectType ):
118+ articles = graphene .List (ArticleType )
119+
120+ @graphene .resolve_only_args
121+ def resolve_articles (self ):
122+ return Article .query ()
123+
124+ schema = graphene .Schema (query = QueryType )
125+ schema .execute ('query test { articles { prop } }' )
126+
127+ self .assertIn ("Model 'bar' is not accessible by the schema." , str (context .exception .message ))
128+
106129 def testQuery_excludedField (self ):
107130 Article (headline = "h1" , summary = "s1" ).put ()
108131
@@ -280,7 +303,7 @@ def testQuery_keyProperty(self):
280303 query ArticleWithAuthorID {
281304 articles {
282305 headline
283- authorKey
306+ authorId
284307 author {
285308 name, email
286309 }
@@ -293,7 +316,8 @@ def testQuery_keyProperty(self):
293316 article = dict (result .data ['articles' ][0 ])
294317 author = dict (article ['author' ])
295318 self .
assertDictEqual (
author , {
'name' :
u'john dow' ,
'email' :
u'[email protected] ' })
296- self .assertDictContainsSubset (dict (headline = 'h1' , authorKey = author_key .urlsafe ()), article )
319+ self .assertEqual ('h1' , article ['headline' ])
320+ self .assertEqual (to_global_id ('AuthorType' , author_key .urlsafe ()), article ['authorId' ])
297321
298322 def testQuery_repeatedKeyProperty (self ):
299323 tk1 = Tag (name = "t1" ).put ()
@@ -302,14 +326,12 @@ def testQuery_repeatedKeyProperty(self):
302326 tk4 = Tag (name = "t4" ).put ()
303327 Article (headline = "h1" , summary = "s1" , tags = [tk1 , tk2 , tk3 , tk4 ]).put ()
304328
305- print str (schema )
306-
307329 result = schema .execute ('''
308330 query ArticleWithAuthorID {
309331 articles {
310332 headline
311- authorKey
312- tagKeys
333+ authorId
334+ tagIds
313335 tags {
314336 name
315337 }
@@ -320,7 +342,7 @@ def testQuery_repeatedKeyProperty(self):
320342 self .assertEmpty (result .errors )
321343
322344 article = dict (result .data ['articles' ][0 ])
323- self .assertListEqual (map (lambda k : k .urlsafe (), [tk1 , tk2 , tk3 , tk4 ]), article ['tagKeys ' ])
345+ self .assertListEqual (map (lambda k : to_global_id ( 'TagType' , k .urlsafe ()) , [tk1 , tk2 , tk3 , tk4 ]), article ['tagIds ' ])
324346
325347 self .assertLength (article ['tags' ], 4 )
326348 for i in range (0 , 3 ):
0 commit comments