def tearDown(self):

        from django.conf import settings

        for searcher in get_available_search_engines():
            searcher.clear_cache()
        shutil.rmtree(settings.WIRECLOUD_INDEX_DIR, ignore_errors=True)
Exemple #2
0
    def test_resetsearchindexes_command_existing_dir_other_indexes(
            self, getdefaultlocale_mock):
        self.options["interactive"] = False

        os.mkdir(self.new_index_dir)
        index.create_in(self.new_index_dir, fields.Schema(content=fields.TEXT),
                        'other_index')
        self.assertTrue(os.path.exists(self.new_index_dir))

        with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
            try:
                call_command('resetsearchindexes', **self.options)
            except SystemExit:
                raise CommandError('')

        self.options['stdout'].seek(0)
        self.assertEqual(self.options['stdout'].read(), '')
        self.options['stderr'].seek(0)
        self.assertEqual(self.options['stderr'].read(), '')
        self.assertTrue(os.path.exists(self.new_index_dir))
        self.assertTrue(
            index.exists_in(self.new_index_dir, indexname='other_index'))
        for search_index in get_available_search_engines():
            self.assertTrue(
                index.exists_in(self.new_index_dir,
                                indexname=search_index.indexname))
Exemple #3
0
    def tearDown(self):

        from django.conf import settings

        for searcher in get_available_search_engines():
            searcher.clear_cache()
        shutil.rmtree(settings.WIRECLOUD_INDEX_DIR, ignore_errors=True)
    def tearDown(self):

        from django.conf import settings

        for searcher in get_available_search_engines():
            searcher.clear_cache()
        shutil.rmtree(settings.WIRECLOUD_INDEX_DIR, ignore_errors=True)

        LiveServerTestCase.tearDown.im_func(self)
        WirecloudRemoteTestCase.tearDown.im_func(self)
Exemple #5
0
    def tearDown(self):

        from django.conf import settings

        for searcher in get_available_search_engines():
            searcher.clear_cache()
        shutil.rmtree(settings.WIRECLOUD_INDEX_DIR, ignore_errors=True)

        LiveServerTestCase.tearDown(self)
        WirecloudRemoteTestCase.tearDown(self)
    def _handle(self, *args, **options):

        self.interactive = options['interactive']
        self.verbosity = int(options.get('verbosity', 1))

        from django.conf import settings

        dirname = settings.WIRECLOUD_INDEX_DIR
        if options['indexes'] == '':
            indexes = [
                search_engine.indexname
                for search_engine in get_available_search_engines()
            ]
        else:
            indexes = options['indexes'].split(',')

            nonavailable_indexes = []
            for index in indexes:
                if not is_available(index):
                    nonavailable_indexes.append(index)

            if len(nonavailable_indexes) > 0:
                raise CommandError(self.nonavailable_indexes_message %
                                   nonavailable_indexes)

        if os.path.exists(dirname):
            message = ['\n']
            message.append(
                ugettext(
                    'You have requested to reset indexes found in the location\n'
                    'specified in your settings:\n\n'
                    '    %s\n\n' % dirname))
            message.append(ugettext('This will DELETE EXISTING FILES!\n'))
            message.append(
                ugettext('Are you sure you want to do this?\n\n'
                         "Type 'yes' to continue, or 'no' to cancel: "))

            if self.interactive and input(''.join(message)) != 'yes':
                raise CommandError(_("Reset search indexes cancelled."))

        else:
            os.mkdir(dirname)

        for indexname in indexes:

            self.log(self.update_start_message % indexname)

            search_engine = get_search_engine(indexname)
            search_engine.clear_index()

            for resource in search_engine.get_model().objects.all():
                self.log('    ' + _('Adding %s\n') % resource)
                search_engine.add_resource(resource)

            self.log(self.update_success_message % indexname)
    def _handle_noargs(self, **options):

        self.interactive = options['interactive']
        self.verbosity = int(options.get('verbosity', 1))

        from django.conf import settings

        dirname = settings.WIRECLOUD_INDEX_DIR
        if options['indexes'] == '':
            indexes = [search_engine.indexname for search_engine in get_available_search_engines()]
        else:
            indexes = options['indexes'].split(',')

            nonavailable_indexes = []
            for index in indexes:
                if not is_available(index):
                    nonavailable_indexes.append(index)

            if len(nonavailable_indexes) > 0:
                raise CommandError(self.nonavailable_indexes_message % nonavailable_indexes)

        if os.path.exists(dirname):
            message = ['\n']
            message.append(
                'You have requested to reset indexes found in the location\n'
                'specified in your settings:\n\n'
                '    %s\n\n' % dirname
            )
            message.append('This will DELETE EXISTING FILES!\n')
            message.append(
                'Are you sure you want to do this?\n\n'
                "Type 'yes' to continue, or 'no' to cancel: "
            )

            if self.interactive and input(''.join(message)) != 'yes':
                raise CommandError("Reset search indexes cancelled.")

        else:
            os.mkdir(dirname)

        for indexname in indexes:

            self.log(self.update_start_message % indexname)

            search_engine = get_search_engine(indexname)
            search_engine.clear_index()

            for resource in search_engine.get_model().objects.all():
                self.log('    ' + _('Adding %s\n') % resource)
                search_engine.add_resource(resource)

            self.log(self.update_success_message % indexname)
    def test_resetsearchindexes_command_individual_index(self, getdefaultlocale_mock):
        self.options['indexes'] = 'user'

        with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
            call_command('resetsearchindexes', **self.options)

        self.options['stdout'].seek(0)
        self.options['stderr'].seek(0)

        for search_index in get_available_search_engines():
            if search_index.indexname != 'user':
                self.assertFalse(index.exists_in(self.new_index_dir, indexname=search_index.indexname))

        self.assertTrue(index.exists_in(self.new_index_dir, indexname='user'))
Exemple #9
0
    def test_resetsearchindexes_command_nonavailable_index(
            self, getdefaultlocale_mock):
        self.options['indexes'] = 'user,nonavailable'

        with self.assertRaises(CommandError):
            with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
                call_command('resetsearchindexes', **self.options)

        self.options['stdout'].seek(0)
        self.options['stderr'].seek(0)

        for search_index in get_available_search_engines():
            self.assertFalse(
                index.exists_in(self.new_index_dir,
                                indexname=search_index.indexname))

        self.assertFalse(
            index.exists_in(self.new_index_dir, indexname='nonavailable'))
Exemple #10
0
    def test_resetsearchindexes_command_multiple_index(self,
                                                       getdefaultlocale_mock):
        self.options['indexes'] = 'user,group'

        with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
            call_command('resetsearchindexes', **self.options)

        self.options['stdout'].seek(0)
        self.options['stderr'].seek(0)

        for search_index in get_available_search_engines():
            if search_index.indexname not in ('user', 'group'):
                self.assertFalse(
                    index.exists_in(self.new_index_dir,
                                    indexname=search_index.indexname))

        self.assertTrue(index.exists_in(self.new_index_dir, indexname='user'))
        self.assertTrue(index.exists_in(self.new_index_dir, indexname='group'))
Exemple #11
0
    def check_resetsearchindexes_command_interactive_cancel(self):
        self.options["interactive"] = True

        os.mkdir(self.new_index_dir)
        self.assertTrue(os.path.exists(self.new_index_dir))

        with patch('wirecloud.commons.management.commands.resetsearchindexes.input', return_value='no'):
            with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
                with self.assertRaises(CommandError):
                    call_command('resetsearchindexes', **self.options)

        self.options['stdout'].seek(0)
        self.assertEqual(self.options['stdout'].read(), '')
        self.options['stderr'].seek(0)
        self.assertEqual(self.options['stderr'].read(), '')
        self.assertTrue(os.path.exists(self.new_index_dir))
        for search_index in get_available_search_engines():
            self.assertFalse(index.exists_in(self.new_index_dir, indexname=search_index.indexname))
    def test_resetsearchindexes_command_existing_dir(self, getdefaultlocale_mock):
        self.options["interactive"] = False

        os.mkdir(self.new_index_dir)
        index.create_in(self.new_index_dir, fields.Schema(content = fields.TEXT), 'resource')
        self.assertTrue(os.path.exists(self.new_index_dir))

        with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
            try:
                call_command('resetsearchindexes', **self.options)
            except SystemExit:
                raise CommandError('')

        self.options['stdout'].seek(0)
        self.assertEqual(self.options['stdout'].read(), '')
        self.options['stderr'].seek(0)
        self.assertEqual(self.options['stderr'].read(), '')
        self.assertTrue(os.path.exists(self.new_index_dir))
        for search_index in get_available_search_engines():
            self.assertTrue(index.exists_in(self.new_index_dir, indexname=search_index.indexname))
Exemple #13
0
    def check_resetsearchindexes_command_interactive_cancel(self):
        self.options["interactive"] = True

        os.mkdir(self.new_index_dir)
        self.assertTrue(os.path.exists(self.new_index_dir))

        with patch(
                'wirecloud.commons.management.commands.resetsearchindexes.input',
                return_value='no'):
            with self.settings(WIRECLOUD_INDEX_DIR=self.new_index_dir):
                with self.assertRaises(CommandError):
                    call_command('resetsearchindexes', **self.options)

        self.options['stdout'].seek(0)
        self.assertEqual(self.options['stdout'].read(), '')
        self.options['stderr'].seek(0)
        self.assertEqual(self.options['stderr'].read(), '')
        self.assertTrue(os.path.exists(self.new_index_dir))
        for search_index in get_available_search_engines():
            self.assertFalse(
                index.exists_in(self.new_index_dir,
                                indexname=search_index.indexname))
 def tearDownClass(cls):
     shutil.rmtree(cls.tmp_dir, ignore_errors=True)
     for searcher in get_available_search_engines():
         searcher.clear_cache()
Exemple #15
0
 def tearDownClass(cls):
     shutil.rmtree(cls.tmp_dir, ignore_errors=True)
     for searcher in get_available_search_engines():
         searcher.clear_cache()