def testUpdateAverageRatingNonBatch1(self):
    models.Category.buildAllCategories()
    product = docs.Product.buildProduct(PRODUCT_PARAMS)
    self.assertEqual(product.avg_rating, 0)
    config.BATCH_RATINGS_UPDATE = False

    # Create a review object and invoke updateAverageRating.
    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)
    # check that the parent product rating average has been updated based on the
    # two reviews
    self.assertEqual(product.avg_rating, 2.5)
    # with BATCH_RATINGS_UPDATE = False, the product document's average rating
    # field ('ar') should be updated to match its associated product
    # entity.

    # run the task queue tasks
    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)
Test non-batch mode avg ratings updating.
dataset/ETHPy150Open GoogleCloudPlatform/appengine-search-python-java/product_search_python/tests/test_search.py/FTSTestCase.testUpdateAverageRatingNonBatch1