Exemplo n.º 1
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_items()
                LibraryBlockIndexer.remove_all_items()
            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_items(library_keys)

        for library_key in library_keys:
            ref = ContentLibrary.objects.get_by_key(library_key)
            lib_bundle = LibraryBundle(library_key,
                                       ref.bundle_uuid,
                                       draft_name=DRAFT_NAME)
            LibraryBlockIndexer.index_items(lib_bundle.get_all_usages())
    def test_remove_all_libraries(self):
        """
        Test if remove_all_items() deletes all libraries
        """
        lib1 = self._create_library(slug="test-lib-rm-all-1", title="Title 1", description="Description")
        lib2 = self._create_library(slug="test-lib-rm-all-2", title="Title 2", description="Description")
        library_key1 = LibraryLocatorV2.from_string(lib1['id'])
        library_key2 = LibraryLocatorV2.from_string(lib2['id'])

        self.assertEqual(len(ContentLibraryIndexer.get_items([library_key1, library_key2])), 2)

        ContentLibraryIndexer.remove_all_items()
        self.assertEqual(len(ContentLibraryIndexer.get_items()), 0)
Exemplo n.º 3
0
 def setUp(self):
     super().setUp()
     if settings.ENABLE_ELASTICSEARCH_FOR_TESTS:
         ContentLibraryIndexer.remove_all_items()
         LibraryBlockIndexer.remove_all_items()
Exemplo n.º 4
0
 def setUp(self):
     super().setUp()
     ContentLibraryIndexer.remove_all_items()
     LibraryBlockIndexer.remove_all_items()
     self.searcher = SearchEngine.get_search_engine(
         LibraryBlockIndexer.INDEX_NAME)