def test_setup_on_multilingual_backend(self, mock_obj):
        """
        Tests the Setup method on the elasticsearch backend.
        """
        es = ElasticsearchMultilingualSearchBackend("default", **Data.connection_options)
        self.assertFalse(es.setup_complete)
        es.setup()
        self.assertTrue(es.setup_complete)
        self.assertNotEqual(es.existing_mapping["de"], Data.existing_mapping)
        self.assertEqual(
            es.existing_mapping["de"]["modelresult"]["properties"]["text"]["analyzer"], get_analyzer_for("de")
        )
        es.conn.indices.create.assert_any_call(index="testproject-de", ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(
            index="testproject-de", doc_type="modelresult", body=es.existing_mapping["de"]
        )

        self.assertNotEqual(es.existing_mapping["en"], Data.existing_mapping)
        self.assertEqual(
            es.existing_mapping["en"]["modelresult"]["properties"]["text"]["analyzer"], get_analyzer_for("en")
        )
        es.conn.indices.create.assert_any_call(index="testproject-en", ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(
            index="testproject-en", doc_type="modelresult", body=es.existing_mapping["en"]
        )

        self.assertNotEqual(es.existing_mapping["fr"], Data.existing_mapping)
        self.assertEqual(
            es.existing_mapping["fr"]["modelresult"]["properties"]["text"]["analyzer"], get_analyzer_for("fr")
        )
        es.conn.indices.create.assert_any_call(index="testproject-fr", ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(
            index="testproject-fr", doc_type="modelresult", body=es.existing_mapping["fr"]
        )
Пример #2
0
    def test_setup_on_multilingual_backend(self, mock_obj):
        """
        Tests the Setup method on the elasticsearch backend.
        """
        es = ElasticsearchMultilingualSearchBackend('default', **Data.connection_options)
        self.assertFalse(es.setup_complete)
        es.setup()
        self.assertTrue(es.setup_complete)
        self.assertNotEqual(es.existing_mapping['de'], Data.existing_mapping)
        self.assertEqual(es.existing_mapping['de']['modelresult']['properties']['text']['analyzer'],
                         get_analyzer_for('de'))
        es.conn.indices.create.assert_any_call(index='testproject-de',
                                               ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(index='testproject-de',
                                                    doc_type='modelresult',
                                                    body=es.existing_mapping['de'])

        self.assertNotEqual(es.existing_mapping['en'], Data.existing_mapping)
        self.assertEqual(es.existing_mapping['en']['modelresult']['properties']['text']['analyzer'],
                         get_analyzer_for('en'))
        es.conn.indices.create.assert_any_call(index='testproject-en',
                                               ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(index='testproject-en',
                                                    doc_type='modelresult',
                                                    body=es.existing_mapping['en'])

        self.assertNotEqual(es.existing_mapping['fr'], Data.existing_mapping)
        self.assertEqual(es.existing_mapping['fr']['modelresult']['properties']['text']['analyzer'],
                         get_analyzer_for('fr'))
        es.conn.indices.create.assert_any_call(index='testproject-fr',
                                               ignore=400, body=es.DEFAULT_SETTINGS)
        es.conn.indices.put_mapping.assert_any_call(index='testproject-fr',
                                                    doc_type='modelresult',
                                                    body=es.existing_mapping['fr'])
 def test_multilingual_clear(self, mock_obj):
     es = ElasticsearchMultilingualSearchBackend("default", **Data.connection_options)
     es.setup()
     es.clear(commit=False)
     es.conn.indices.delete.assert_any_call(index="testproject-en", ignore=404)
     es.conn.indices.delete.assert_any_call(index="testproject-fr", ignore=404)
     es.conn.indices.delete.assert_any_call(index="testproject-de", ignore=404)
     es.conn.indices.delete.assert_any_call(index="testproject-ru", ignore=404)
Пример #4
0
 def test_multiligual_process_results(self, mock_es):
     es = ElasticsearchMultilingualSearchBackend('default',
                                                 **Data.connection_options)
     es.setup()
     results = es._process_results(Data.raw_results)
     expected = {
         'hits': 0,
         'spelling_suggestion': None,
         'results': [],
         'facets': {}
     }
     self.assertEqual(expected, results)
Пример #5
0
 def test_mocking_works(self, mock_obj):
     # create a backend instance
     es = ElasticsearchMultilingualSearchBackend('default', **Data.connection_options)
     for language in settings.LANGUAGES:
         self.assertIn(language[0], es.existing_mapping.keys())
     # in the constructor, an Elasticsearche instance is created as 'conn' property.
     self.assertTrue(isinstance(es.conn, mock.Mock))
     self.assertIsNot(es.conn, mock_obj)  # a new mock is created.
     self.assertFalse(es.silently_fail)
     indices = mock_indices()  # use the indices mock from the mocks module.
     es.conn.attach_mock(indices, 'indices')
     self.assertEqual(es.conn.indices.get_mapping(), Data.existing_mapping)
     es.setup()
     # Data.connection_options.INDEX_NAME
     indices.get_mapping.assert_any_call(index='testproject-en')
     indices.get_mapping.assert_any_call(index='testproject-de')
     indices.get_mapping.assert_any_call(index='testproject-ru')
 def test_mocking_works(self, mock_obj):
     # create a backend instance
     es = ElasticsearchMultilingualSearchBackend("default", **Data.connection_options)
     for language in settings.LANGUAGES:
         self.assertIn(language[0], es.existing_mapping.keys())
     # in the constructor, an Elasticsearche instance is created as 'conn' property.
     self.assertTrue(isinstance(es.conn, mock.Mock))
     self.assertIsNot(es.conn, mock_obj)  # a new mock is created.
     self.assertFalse(es.silently_fail)
     indices = mock_indices()  # use the indices mock from the mocks module.
     es.conn.attach_mock(indices, "indices")
     self.assertEqual(es.conn.indices.get_mapping(), Data.existing_mapping)
     es.setup()
     # Data.connection_options.INDEX_NAME
     indices.get_mapping.assert_any_call(index="testproject-en")
     indices.get_mapping.assert_any_call(index="testproject-de")
     indices.get_mapping.assert_any_call(index="testproject-ru")
Пример #7
0
    def test_fixture_and_elasticsearch_up(self):
        documents = Document.objects.all()
        self.assertEqual(len(documents), self.count)
        languages = [l[0] for l in settings.LANGUAGES]
        es = ElasticsearchMultilingualSearchBackend('default',
                                                    **Data.connection_options)
        self.assertEqual(languages, es.languages)

        self.assertTrue(es.conn.ping())
        info = es.conn.info()
        self.assertEqual('elasticsearch', info['cluster_name'])
        self.assertEqual(200, info['status'])
Пример #8
0
 def test_multilingual_search(self, mock_es):
     es = ElasticsearchMultilingualSearchBackend('default',
                                                 **Data.connection_options)
     es.setup()
     kwargs = Data.search_kwargs.copy()
     for language in ['de', 'en', 'ru']:
         with translation.override(language):
             es.search('*:*', end_offset=1)
             kwargs['index'] = es._index_name_for_language(language)
             es.conn.search.assert_called_with(**kwargs)
Пример #9
0
 def test_multilingual_clear(self, mock_obj):
     es = ElasticsearchMultilingualSearchBackend('default', **Data.connection_options)
     es.setup()
     es.clear(models=None, commit=False)
     es.conn.indices.delete.assert_any_call(index='testproject-en', ignore=404)
     es.conn.indices.delete.assert_any_call(index='testproject-fr', ignore=404)
     es.conn.indices.delete.assert_any_call(index='testproject-de', ignore=404)
     es.conn.indices.delete.assert_any_call(index='testproject-ru', ignore=404)
 def test_multilingual_search(self, mock_es):
     es = ElasticsearchMultilingualSearchBackend('default', **Data.connection_options)
     es.setup()
     kwargs = Data.search_kwargs.copy()
     for language in ['de', 'en', 'ru']:
         with translation.override(language):
             es.search('*:*', end_offset=1)
             kwargs['index'] = es._index_name_for_language(language)
             es.conn.search.assert_called_with(**kwargs)
 def test_multiligual_process_results(self, mock_es):
     es = ElasticsearchMultilingualSearchBackend('default', **Data.connection_options)
     es.setup()
     results = es._process_results(Data.raw_results)
     expected = {'hits': 0, 'spelling_suggestion': None, 'results': [], 'facets': {}}
     self.assertEqual(expected, results)