def _do_test_large_course_deletion(self, store, load_factor): """ Test that deleting items from a course works even when present within a very large course """ def id_list(top_parent_object): """ private function to get ids from object down the tree """ list_of_ids = [unicode(top_parent_object.location)] for child in top_parent_object.get_children(): list_of_ids.extend(id_list(child)) return list_of_ids course, course_size = create_large_course(store, load_factor) self.course_id = unicode(course.id) # index full course CoursewareSearchIndexer.do_course_reindex(store, course.id) self.assert_search_count(course_size) # reload course to allow us to delete one single unit course = store.get_course(course.id, depth=1) # delete the first chapter chapter_to_delete = course.get_children()[0] self.delete_item(store, chapter_to_delete.location) # index and check correctness CoursewareSearchIndexer.do_course_reindex(store, course.id) deleted_count = 1 + load_factor + (load_factor ** 2) + (load_factor ** 3) self.assert_search_count(course_size - deleted_count)
def test_indexing_responses(self): """ Test do_course_reindex response with real data """ # results are indexed because they are published from ItemFactory response = perform_search( "unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response['total'], 1) # Start manual reindex CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id) # Check results are the same following reindex response = perform_search( "unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response['total'], 1)
def handle(self, *args, **options): """ By convention set by Django developers, this method actually executes command's actions. So, there could be no better docstring than emphasize this once again. """ course_ids = options['course_ids'] all_option = options['all'] setup_option = options['setup'] index_all_courses_option = all_option or setup_option if (not len(course_ids) and not index_all_courses_option) or \ (len(course_ids) and index_all_courses_option): raise CommandError( "reindex_course requires one or more <course_id>s OR the --all or --setup flags." ) store = modulestore() if index_all_courses_option: index_name = CoursewareSearchIndexer.INDEX_NAME doc_type = CoursewareSearchIndexer.DOCUMENT_TYPE if setup_option: try: # try getting the ElasticSearch engine searcher = SearchEngine.get_search_engine(index_name) except exceptions.ElasticsearchException as exc: logging.exception(u'Search Engine error - %s', exc) return index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access doc_type_exists = searcher._es.indices.exists_type( # pylint: disable=protected-access index=index_name, doc_type=doc_type) index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access index=index_name, doc_type=doc_type ) if index_exists and doc_type_exists else {} if index_exists and index_mapping: return # if reindexing is done during devstack setup step, don't prompt the user if setup_option or query_yes_no(self.CONFIRMATION_PROMPT, default="no"): # in case of --setup or --all, get the list of course keys from all courses # that are stored in the modulestore course_keys = [ course.id for course in modulestore().get_courses() ] else: return else: # in case course keys are provided as arguments course_keys = list(map(self._parse_course_key, course_ids)) for course_key in course_keys: CoursewareSearchIndexer.do_course_reindex(store, course_key)
def test_indexing_no_item(self, mock_get_course): """ Test system logs an error if no item found. """ # set mocked exception response err = ItemNotFoundError mock_get_course.return_value = err # Start manual reindex and check error in response with self.assertRaises(SearchIndexingError): CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id)
def handle(self, *args, **options): """ By convention set by Django developers, this method actually executes command's actions. So, there could be no better docstring than emphasize this once again. """ course_ids = options['course_ids'] all_option = options['all'] setup_option = options['setup'] index_all_courses_option = all_option or setup_option if (not len(course_ids) and not index_all_courses_option) or \ (len(course_ids) and index_all_courses_option): raise CommandError("reindex_course requires one or more <course_id>s OR the --all or --setup flags.") store = modulestore() if index_all_courses_option: index_name = CoursewareSearchIndexer.INDEX_NAME doc_type = CoursewareSearchIndexer.DOCUMENT_TYPE if setup_option: try: # try getting the ElasticSearch engine searcher = SearchEngine.get_search_engine(index_name) except exceptions.ElasticsearchException as exc: logging.exception(u'Search Engine error - %s', exc) return index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access doc_type_exists = searcher._es.indices.exists_type( # pylint: disable=protected-access index=index_name, doc_type=doc_type ) index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access index=index_name, doc_type=doc_type ) if index_exists and doc_type_exists else {} if index_exists and index_mapping: return # if reindexing is done during devstack setup step, don't prompt the user if setup_option or query_yes_no(self.CONFIRMATION_PROMPT, default="no"): # in case of --setup or --all, get the list of course keys from all courses # that are stored in the modulestore course_keys = [course.id for course in modulestore().get_courses()] else: return else: # in case course keys are provided as arguments course_keys = map(self._parse_course_key, course_ids) for course_key in course_keys: CoursewareSearchIndexer.do_course_reindex(store, course_key)
def test_indexing_seq_error_responses(self, mock_index_dictionary): """ Test do_course_reindex response with mocked error data for sequence """ # results are indexed because they are published from ItemFactory response = perform_search("unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response["total"], 1) # set mocked exception response err = Exception mock_index_dictionary.return_value = err # Start manual reindex and check error in response with self.assertRaises(SearchIndexingError): CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id)
def test_indexing_seq_error_responses(self, mock_index_dictionary): """ Test do_course_reindex response with mocked error data for sequence """ # results are indexed because they are published from ItemFactory response = perform_search("unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response['total'], 1) # set mocked exception response err = Exception mock_index_dictionary.return_value = err # Start manual reindex and check error in response with self.assertRaises(SearchIndexingError): CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id)
def test_indexing_responses(self): """ Test do_course_reindex response with real data """ # results are indexed because they are published from ItemFactory response = perform_search("unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response['total'], 1) # Start manual reindex CoursewareSearchIndexer.do_course_reindex(modulestore(), self.course.id) # Check results are the same following reindex response = perform_search("unique", user=self.user, size=10, from_=0, course_id=unicode(self.course.id)) self.assertEqual(response['total'], 1)
def reindex_course(self, store): """ kick off complete reindex of the course """ return CoursewareSearchIndexer.do_course_reindex(store, self.course.id)