def test_remove_all_libraries(self): """ Test if remove_all_libraries() deletes all libraries """ self._create_library(slug="test-lib-rm-all-1", title="Title 1", description="Description") self._create_library(slug="test-lib-rm-all-2", title="Title 2", description="Description") response = self.searcher.search(doc_type=ContentLibraryIndexer.LIBRARY_DOCUMENT_TYPE, filter_dictionary={}) self.assertEqual(response['total'], 2) ContentLibraryIndexer.remove_all_libraries() response = self.searcher.search(doc_type=ContentLibraryIndexer.LIBRARY_DOCUMENT_TYPE, filter_dictionary={}) self.assertEqual(response['total'], 0)
def handle(self, *args, **options): if options['clear-all']: if options['force'] or query_yes_no(self.CONFIRMATION_PROMPT_CLEAR, default="no"): logging.info("Removing all libraries from the index") ContentLibraryIndexer.remove_all_libraries() return if options['all']: if options['force'] or query_yes_no(self.CONFIRMATION_PROMPT_ALL, default="no"): logging.info("Indexing all libraries") library_keys = [library.library_key for library in ContentLibrary.objects.all()] else: return else: logging.info("Indexing libraries: {}".format(options['library_ids'])) library_keys = list(map(LibraryLocatorV2.from_string, options['library_ids'])) ContentLibraryIndexer.index_libraries(library_keys)
def setUp(self): super().setUp() ContentLibraryIndexer.remove_all_libraries() self.searcher = SearchEngine.get_search_engine(ContentLibraryIndexer.INDEX_NAME)