Beispiel #1
0
class PluginIndexingTests(TestCase):
    def setUp(self):
        placeholder = Placeholder(id=1235)
        instance = CMSPlugin(plugin_type="NotIndexedPlugin",
                             placeholder=placeholder)
        instance.cmsplugin_ptr = instance
        instance.pk = 1234  # otherwise plugin_meta_context_processor() crashes
        self.instance = instance
        self.index = TitleIndex()
        self.request = get_request_for_search(language='en')

    def test_plugin_indexing_is_enabled_by_default(self):
        self.assertEqual(
            "i am rendered: %s " % NotIndexedPlugin.INDEXED_MESSAGE,
            self.index.get_plugin_search_text(self.instance, self.request))

    def test_plugin_indexing_can_be_disabled_on_model(self):
        self.instance.search_fulltext = False
        self.assertEqual(
            '', self.index.get_plugin_search_text(self.instance, self.request))

    def test_plugin_indexing_can_be_disabled_on_plugin(self):
        NotIndexedPlugin.search_fulltext = False

        try:
            self.assertEqual(
                '',
                self.index.get_plugin_search_text(self.instance, self.request))
        finally:
            del NotIndexedPlugin.search_fulltext
Beispiel #2
0
class PluginIndexingTests(TestCase):

    def setUp(self):
        placeholder = Placeholder(id=1235)
        instance = CMSPlugin(
            plugin_type="NotIndexedPlugin",
            placeholder=placeholder
        )
        instance.cmsplugin_ptr = instance
        instance.pk = 1234 # otherwise plugin_meta_context_processor() crashes
        self.instance = instance
        self.index = TitleIndex()
        self.request = get_request_for_search(language='en')

    def test_plugin_indexing_is_enabled_by_default(self):
        self.assertEqual("i am rendered: %s " % NotIndexedPlugin.INDEXED_MESSAGE,
            self.index.get_plugin_search_text(self.instance, self.request))

    def test_plugin_indexing_can_be_disabled_on_model(self):
        self.instance.search_fulltext = False
        self.assertEqual('', self.index.get_plugin_search_text(self.instance, self.request))

    def test_plugin_indexing_can_be_disabled_on_plugin(self):
        NotIndexedPlugin.search_fulltext = False

        try:
            self.assertEqual('', self.index.get_plugin_search_text(self.instance, self.request))
        finally:
            del NotIndexedPlugin.search_fulltext
Beispiel #3
0
class PluginIndexingTests(BaseTestCase):
    def setUp(self):
        self.index = TitleIndex()
        self.request = get_request(language='en')

    def get_plugin(self):
        instance = CMSPlugin(language='en',
                             plugin_type="NotIndexedPlugin",
                             placeholder=Placeholder(id=1235))
        instance.cmsplugin_ptr = instance
        instance.pk = 1234  # otherwise plugin_meta_context_processor() crashes
        return instance

    def test_plugin_indexing_is_enabled_by_default(self):
        cms_plugin = self.get_plugin()
        indexed_content = self.index.get_plugin_search_text(
            cms_plugin, self.request)
        self.assertEqual(NotIndexedPlugin.plugin_content, indexed_content)

    def test_plugin_indexing_can_be_disabled_on_model(self):
        cms_plugin = self.get_plugin()
        cms_plugin.search_fulltext = False
        indexed_content = self.index.get_plugin_search_text(
            cms_plugin, self.request)
        self.assertEqual('', indexed_content)

    def test_plugin_indexing_can_be_disabled_on_plugin(self):
        NotIndexedPlugin.search_fulltext = False

        try:
            self.assertEqual(
                '',
                self.index.get_plugin_search_text(self.get_plugin(),
                                                  self.request))
        finally:
            del NotIndexedPlugin.search_fulltext

    def test_page_title_is_indexed_using_prepare(self):
        """This tests the indexing path way used by update_index mgmt command"""
        page = create_page(title="home", template="page.html", language="en")
        index = self.get_title_index()

        title = Title.objects.get(pk=page.title_set.all()[0].pk)
        index.index_queryset(DEFAULT_ALIAS)  # initialises index._backend_alias
        indexed = index.prepare(title)
        self.assertEqual('home', indexed['title'])
        self.assertEqual('home', indexed['text'])

    def test_page_title_is_indexed_using_update_object(self):
        """This tests the indexing path way used by the RealTimeSignalProcessor"""
        page = create_page(title="home", template="page.html", language="en")
        index = self.get_title_index()
        title = Title.objects.get(pk=page.title_set.all()[0].pk)
        index.update_object(title, using=DEFAULT_ALIAS)
        indexed = index.prepared_data
        self.assertEqual('home', indexed['title'])
        self.assertEqual('home', indexed['text'])
Beispiel #4
0
class PluginIndexingTests(BaseTestCase):

    def setUp(self):
        self.index = TitleIndex()
        self.request = get_request(language='en')

    def get_plugin(self):
        instance = CMSPlugin(
            language='en',
            plugin_type="NotIndexedPlugin",
            placeholder=Placeholder(id=1235)
        )
        instance.cmsplugin_ptr = instance
        instance.pk = 1234  # otherwise plugin_meta_context_processor() crashes
        return instance

    def test_plugin_indexing_is_enabled_by_default(self):
        cms_plugin = self.get_plugin()
        indexed_content = self.index.get_plugin_search_text(cms_plugin, self.request)
        self.assertEqual(NotIndexedPlugin.plugin_content, indexed_content)

    def test_plugin_indexing_can_be_disabled_on_model(self):
        cms_plugin = self.get_plugin()
        cms_plugin.search_fulltext = False
        indexed_content = self.index.get_plugin_search_text(cms_plugin, self.request)
        self.assertEqual('', indexed_content)

    def test_plugin_indexing_can_be_disabled_on_plugin(self):
        NotIndexedPlugin.search_fulltext = False

        try:
            self.assertEqual('', self.index.get_plugin_search_text(self.get_plugin(), self.request))
        finally:
            del NotIndexedPlugin.search_fulltext

    def test_page_title_is_indexed_using_prepare(self):
        """This tests the indexing path way used by update_index mgmt command"""
        page = create_page(title="home", template="page.html", language="en")
        index = self.get_title_index()

        title = Title.objects.get(pk=page.title_set.all()[0].pk)
        index.index_queryset(DEFAULT_ALIAS)  # initialises index._backend_alias
        indexed = index.prepare(title)
        self.assertEqual('home', indexed['title'])
        self.assertEqual('home', indexed['text'])

    def test_page_title_is_indexed_using_update_object(self):
        """This tests the indexing path way used by the RealTimeSignalProcessor"""
        page = create_page(title="home", template="page.html", language="en")
        index = self.get_title_index()
        title = Title.objects.get(pk=page.title_set.all()[0].pk)
        index.update_object(title, using=DEFAULT_ALIAS)
        indexed = index.prepared_data
        self.assertEqual('home', indexed['title'])
        self.assertEqual('home', indexed['text'])