Пример #1
0
    def testQuery_keyProperty(self):
        author_key = Author(name="john dow", email="*****@*****.**").put()
        article_key = Article(headline="h1",
                              summary="s1",
                              author_key=author_key).put()

        result = schema.execute('''
            query ArticleWithAuthorID {
                articles {
                    ndbId
                    headline
                    authorId
                    authorNdbId: authorId(ndb: true)
                    author {
                        name, email
                    }
                }
            }
        ''')

        self.assertEmpty(result.errors)

        article = dict(result.data['articles'][0])
        self.assertEqual(article['ndbId'], str(article_key.id()))
        self.assertEqual(article['authorNdbId'], str(author_key.id()))

        author = dict(article['author'])
        self.assertDictEqual(author, {
            'name': u'john dow',
            'email': u'*****@*****.**'
        })
        self.assertEqual('h1', article['headline'])
        self.assertEqual(to_global_id('AuthorType', author_key.urlsafe()),
                         article['authorId'])
Пример #2
0
    def testQuery_keyProperty(self):
        author_key = Author(name="john dow", email="*****@*****.**").put()
        article_key = Article(headline="h1", summary="s1", author_key=author_key).put()

        result = schema.execute('''
            query ArticleWithAuthorID {
                articles {
                    ndbId
                    headline
                    authorId
                    authorNdbId: authorId(ndb: true)
                    author {
                        name, email
                    }
                }
            }
        ''')

        self.assertEmpty(result.errors)

        article = dict(result.data['articles'][0])
        self.assertEqual(article['ndbId'], str(article_key.id()))
        self.assertEqual(article['authorNdbId'], str(author_key.id()))

        author = dict(article['author'])
        self.assertDictEqual(author, {'name': u'john dow', 'email': u'*****@*****.**'})
        self.assertEqual('h1', article['headline'])
        self.assertEqual(to_global_id('AuthorType', author_key.urlsafe()), article['authorId'])
Пример #3
0
    def test_save_and_insert(self):
        author = Author(name='test author 6')
        author.save()

        post = Post(title='test title 6', content='test content 6', pub_date=datetime.now(), author_id='6')
        post.save()

        c = db.execute('select * from author where id=6;')
        self.assertEqual(len(c.fetchall()), 1)
        c = db.execute('select * from my_post where id=6;')
        self.assertEqual(len(c.fetchall()), 1)
Пример #4
0
    def test_save_and_insert(self):
        author = Author(name='test author 6')
        author.save()

        post = Post(title='test title 6',
                    content='test content 6',
                    pub_date=datetime.now(),
                    author_id='6')
        post.save()

        c = db.execute('select * from author where id=6;')
        self.assertEqual(len(c.fetchall()), 1)
        c = db.execute('select * from my_post where id=6;')
        self.assertEqual(len(c.fetchall()), 1)
Пример #5
0
    def testQuery_structuredProperty(self):
        mobile = PhoneNumber(area="650", number="12345678")
        author_key = Author(name="John Dow",
                            email="*****@*****.**",
                            mobile=mobile).put()
        Article(headline="Test1", author_key=author_key).put()

        result = schema.execute("""
            query Articles {
                articles {
                    headline,
                    authorId
                    author {
                        name
                        email
                        mobile { area, number }
                    }
                }
            }
        """)
        self.assertEmpty(result.errors, msg=str(result.errors))

        article = result.data['articles'][0]
        self.assertEqual(article["headline"], "Test1")

        author = article['author']
        self.assertEqual(author["name"], "John Dow")
        self.assertEqual(author["email"], "*****@*****.**")
        self.assertDictEqual(dict(area="650", number="12345678"),
                             dict(author["mobile"]))
Пример #6
0
    def setUp(self):
        # Create 10 articles with 10 authors each.
        authors = Author.objects.bulk_create(
            Author(id=i, name=str(i)) for i in range(10))
        authors = Author.objects.all()

        for i in range(10):
            article = Article(title=str(i))
            article.authors = authors
            article.save()
Пример #7
0
    def testNdbNode_getNode_validID_entityDoes_shouldReturnEntity(self):
        article_key = Article(
            headline="TestGetNode",
            summary="1",
            author_key=Author(name="John Dow", email="*****@*****.**").put(),
        ).put()

        result = ArticleType.get_node(None, article_key.urlsafe())
        article = article_key.get()

        self.assertIsNotNone(result)
        self.assertEqual(result.headline, article.headline)
        self.assertEqual(result.summary, article.summary)
Пример #8
0
    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'])
Пример #9
0
    def testQuery_structuredProperty_repeated(self):
        address1 = Address(address1="address1",
                           address2="apt 1",
                           city="Mountain View")
        address2 = Address(address1="address2",
                           address2="apt 2",
                           city="Mountain View")
        author_key = Author(name="John Dow",
                            email="*****@*****.**",
                            addresses=[address1, address2]).put()
        Article(headline="Test1", author_key=author_key).put()

        result = schema.execute("""
            query Articles {
                articles {
                    headline,
                    author {
                        name
                        email
                        addresses {
                            address1
                            address2
                            city
                        }
                    }
                }
            }
        """)
        self.assertEmpty(result.errors)

        article = result.data['articles'][0]
        self.assertEqual(article["headline"], "Test1")

        author = article['author']
        self.assertEqual(author["name"], "John Dow")
        self.assertEqual(author["email"], "*****@*****.**")
        self.assertLength(author["addresses"], 2)

        addresses = [dict(d) for d in author["addresses"]]
        self.assertIn(address1.to_dict(), addresses)
        self.assertIn(address2.to_dict(), addresses)
Пример #10
0
 def test_foreignkeyfields(self):
     posts = Author.get(id=5).posts.all()
     self.assertEqual(len(posts), 1)
     self.assertEqual(posts[0].id, 5)
Пример #11
0
 def test_foreignkeyfields(self):
     posts = Author.get(id=5).posts.all()
     self.assertEqual(len(posts), 1)
     self.assertEqual(posts[0].id, 5)