def test_standard_operation(self):
    job_id = activity_jobs_one_off.IndexAllActivitiesJobManager.create_new()
    activity_jobs_one_off.IndexAllActivitiesJobManager.enqueue(job_id)
    self.assertEqual(self.count_jobs_in_mapreduce_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
    indexed_docs = []

    def mock_add_documents_to_index(docs, index):
        indexed_docs.extend(docs)
        self.assertIn(index, (search_services.SEARCH_INDEX_EXPLORATIONS, search_services.SEARCH_INDEX_COLLECTIONS))
    add_docs_swap = self.swap(gae_search_services, 'add_documents_to_index', mock_add_documents_to_index)
    with add_docs_swap:
        self.process_and_flush_pending_mapreduce_tasks()
    ids = [doc['id'] for doc in indexed_docs]
    titles = [doc['title'] for doc in indexed_docs]
    categories = [doc['category'] for doc in indexed_docs]
    for index in python_utils.RANGE(5):
        self.assertIn(('%s' % index), ids)
        self.assertIn(('title %d' % index), titles)
        self.assertIn(('category%d' % index), categories)
    self.assertIsNone(activity_jobs_one_off.IndexAllActivitiesJobManager.reduce('key', 'value'))
def test_standard_operation(self):
    job_id = activity_jobs_one_off.IndexAllActivitiesJobManager.create_new()
    activity_jobs_one_off.IndexAllActivitiesJobManager.enqueue(job_id)
    self.assertEqual(self.count_jobs_in_mapreduce_taskqueue(taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
    indexed_docs = []

    def mock_add_documents_to_index(docs, index):
        indexed_docs.extend(docs)
        self.assertIn(index, (search_services.SEARCH_INDEX_EXPLORATIONS, search_services.SEARCH_INDEX_COLLECTIONS))
    add_docs_swap = self.swap(gae_search_services, 'add_documents_to_index', mock_add_documents_to_index)
    with add_docs_swap:
        self.process_and_flush_pending_mapreduce_tasks()
    ids = [doc['id'] for doc in indexed_docs]
    titles = [doc['title'] for doc in indexed_docs]
    categories = [doc['category'] for doc in indexed_docs]
    for index in python_utils.RANGE(5):
        self.assertIn(('%s' % index), ids)
        self.assertIn(('title %d' % index), titles)
        self.assertIn(('category%d' % index), categories)
    self.assertIsNone(activity_jobs_one_off.IndexAllActivitiesJobManager.reduce('key', 'value'))