def testQuery_repeatedKeyProperty(self): tk1 = Tag(name="t1").put() tk2 = Tag(name="t2").put() tk3 = Tag(name="t3").put() tk4 = Tag(name="t4").put() Article(headline="h1", summary="s1", tags=[tk1, tk2, tk3, tk4]).put() result = schema.execute(''' query ArticleWithAuthorID { articles { headline authorId tagIds tags { name } } } ''') self.assertEmpty(result.errors) article = dict(result.data['articles'][0]) self.assertListEqual( map(lambda k: to_global_id('TagType', k.urlsafe()), [tk1, tk2, tk3, tk4]), article['tagIds']) self.assertLength(article['tags'], 4) for i in range(0, 3): self.assertEqual(article['tags'][i]['name'], 't%s' % (i + 1))
def test_keyProperty(self): Article( headline="Test1", summary="1", author_key=Author(name="John Dow", email="*****@*****.**").put(), tags=[ Tag(name="tag1").put(), Tag(name="tag2").put(), Tag(name="tag3").put(), ] ).put() result = schema.execute(""" query Articles { articles(first:2) { edges { cursor, node { headline, summary, author { name }, tags { name } } } } } """) self.assertEmpty(result.errors, msg=str(result.errors)) articles = result.data.get('articles', {}).get('edges', []) self.assertLength(articles, 1) article = articles[0]['node'] self.assertEqual(article['headline'], 'Test1') self.assertEqual(article['summary'], '1') author = article['author'] self.assertLength(author.keys(), 1) self.assertEqual(author['name'], 'John Dow') tags = article['tags'] tag_names = [t['name'] for t in tags] self.assertListEqual(tag_names, ['tag1', 'tag2', 'tag3'])