'Ensure that queries are properly formed for use in exec_js.'

def test_exec_js_query(self):

    class BlogPost(Document, ):
        hits = IntField()
        published = BooleanField()
    BlogPost.drop_collection()
    post1 = BlogPost(hits=1, published=False)
    post1.save()
    post2 = BlogPost(hits=1, published=True)
    post2.save()
    post3 = BlogPost(hits=1, published=True)
    post3.save()
    js_func = '\n                                                function(hitsField)    {\n                                                                var    count    =    0;\n                                                                db[collection].find(query).forEach(function(doc)    {\n                                                                                count    +=    doc[hitsField];\n                                                                });\n                                                                return    count;\n                                                }\n                                '
    c = BlogPost.objects(published=True).exec_js(js_func, 'hits')
    self.assertEqual(c, 2)
    c = BlogPost.objects(published=False).exec_js(js_func, 'hits')
    self.assertEqual(c, 1)
    BlogPost.drop_collection()
