

def testUpdateAverageRatingNonBatch1(self):
    'Test non-batch mode avg ratings updating.'
    models.Category.buildAllCategories()
    product = docs.Product.buildProduct(PRODUCT_PARAMS)
    self.assertEqual(product.avg_rating, 0)
    config.BATCH_RATINGS_UPDATE = False
    review = models.Review(product_key=product.key, username='bob', rating=4, comment='comment')
    review.put()
    utils.updateAverageRating(review.key)
    review = models.Review(product_key=product.key, username='bob2', rating=1, comment='comment')
    review.put()
    utils.updateAverageRating(review.key)
    product = models.Product.get_by_id(product.pid)
    self.assertEqual(product.avg_rating, 2.5)
    taskq = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    tasks = taskq.GetTasks('default')
    taskq.FlushQueue('default')
    while tasks:
        for task in tasks:
            deferred.run(base64.b64decode(task['body']))
        tasks = taskq.GetTasks('default')
        taskq.FlushQueue('default')
    sq = search.Query(query_string='ar:2.5')
    res = docs.Product.getIndex().search(sq)
    self.assertEqual(res.number_found, 1)
    for doc in res:
        self.assertEqual(doc.doc_id, product.doc_id)

dataset/ETHPy150Open GoogleCloudPlatform/appengine-search-python-java/product_search_python/tests/test_search.py FTSTestCase.testUpdateAverageRatingNonBatch1/original