Esempio n. 1
0
    def test_reindex_with_replicas(self):
        index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)

        class WebsiteIndex(AlgoliaIndex):
            settings = {
                'replicas': [
                    index.index_name + '_name_asc',
                    index.index_name + '_name_desc'
                ]
            }

        index = WebsiteIndex(Website, self.client, settings.ALGOLIA)
        index.reindex_all()
Esempio n. 2
0
 def test_default_index_name(self):
     index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
     regex = r'^test_Website_django(_travis-\d+.\d+)?$'
     try:
         self.assertRegex(index.index_name, regex)
     except AttributeError:
         self.assertRegexpMatches(index.index_name, regex)
    def test_tmp_index_name(self):
        """Test that the temporary index name should respect suffix and prefix settings"""

        algolia_settings = dict(settings.ALGOLIA)

        # With no suffix nor prefix
        del algolia_settings['INDEX_PREFIX']
        del algolia_settings['INDEX_SUFFIX']

        with self.settings(ALGOLIA=algolia_settings):
            self.index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
            self.assertEqual(
                self.index._AlgoliaIndex__tmp_index.index_name,
                'Website_tmp'
            )

        # With only a prefix
        algolia_settings['INDEX_PREFIX'] = 'prefix'

        with self.settings(ALGOLIA=algolia_settings):
            self.index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
            self.assertEqual(
                self.index._AlgoliaIndex__tmp_index.index_name,
                'prefix_Website_tmp'
            )

        # With only a suffix
        del algolia_settings['INDEX_PREFIX']
        algolia_settings['INDEX_SUFFIX'] = 'suffix'

        with self.settings(ALGOLIA=algolia_settings):
            self.index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
            self.assertEqual(
                self.index._AlgoliaIndex__tmp_index.index_name,
                'Website_tmp_suffix'
            )

        # With a prefix and a suffix
        algolia_settings['INDEX_PREFIX'] = 'prefix'
        algolia_settings['INDEX_SUFFIX'] = 'suffix'

        with self.settings(ALGOLIA=algolia_settings):
            self.index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
            self.assertEqual(
                self.index._AlgoliaIndex__tmp_index.index_name,
                'prefix_Website_tmp_suffix'
            )
Esempio n. 4
0
    def test_save_record_should_index_boolean(self):
        website = Website.objects.create(name='Algolia',
                                         url='https://algolia.com',
                                         is_online=True)
        index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)

        class WebsiteIndex(AlgoliaIndex):
            settings = {
                'replicas': [
                    index.index_name + '_name_asc',
                    index.index_name + '_name_desc'
                ]
            }
            should_index = 'is_online'

        index = WebsiteIndex(Website, self.client, settings.ALGOLIA)
        index.save_record(website)
Esempio n. 5
0
    def test_index_name_settings(self):
        algolia_settings = dict(settings.ALGOLIA)
        del algolia_settings['INDEX_PREFIX']
        del algolia_settings['INDEX_SUFFIX']

        with self.settings(ALGOLIA=algolia_settings):
            index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)
            regex = r'^Website$'
            try:
                self.assertRegex(index.index_name, regex)
            except AttributeError:
                self.assertRegexpMatches(index.index_name, regex)
    def test_reindex_with_should_index_boolean(self):
        Website.objects.create(name='Algolia',
                               url='https://algolia.com',
                               is_online=True)
        self.index = AlgoliaIndex(Website, self.client, settings.ALGOLIA)

        class WebsiteIndex(AlgoliaIndex):
            settings = {
                'replicas': [
                    self.index.index_name + '_name_asc',
                    self.index.index_name + '_name_desc'
                ]
            }
            should_index = 'is_online'

        self.index = WebsiteIndex(Website, self.client, settings.ALGOLIA)
        self.index.reindex_all()
 def test_index_model_with_foreign_key_reference(self):
     self.index = AlgoliaIndex(User, self.client, settings.ALGOLIA)
     self.index.reindex_all()
     self.assertFalse("blogpost" in self.index.fields)