def setUp(self):
     self.index_name = 'my_test_index'
     self.index = ZomboDBIndex(
         fields=['datetimes', 'dates', 'times'],
         field_mapping=OrderedDict(
             [  # use OrderedDict to stabilize tests on Python < 3.6
                 ('datetimes',
                  OrderedDict([('type', 'date'),
                               ('format', 'HH:mm:ss.SSSSSS'),
                               ('copy_to', 'zdb_all')])),
                 ('dates',
                  OrderedDict([('type', 'date'), ('copy_to', 'zdb_all')])),
                 ('times',
                  OrderedDict([('type', 'date'), ('copy_to', 'zdb_all')])),
             ]),
         name=self.index_name,
         shards=4,
         replicas=1,
         alias='my-test-index-alias',
         refresh_interval='1s',
         type_name='doc',
         bulk_concurrency=10,
         batch_size=8388608,
         compression_level=9,
         llapi=False,
     )
     with connection.schema_editor() as editor:
         self.statement_adapter = self.index.create_sql(
             model=DateTimeArrayModel, schema_editor=editor, using='')
         self.repr = repr(self.statement_adapter)
         self.str = str(self.statement_adapter)
示例#2
0
 def test_exception_no_url(self):
     with self.assertRaises(ImproperlyConfigured) as cm:
         ZomboDBIndex(fields=['title'], name='test_title_zombodb')
     self.assertEqual(
         str(cm.exception),
         "Please set ZOMBODB_ELASTICSEARCH_URL on settings or "
         "pass a `url` argument for this index")
示例#3
0
 def test_deconstruction(self):
     index = ZomboDBIndex(
         fields=['title'],
         name='test_title_zombodb',
         url='http://localhost/',
         shards=2,
         replicas=2,
         alias='test-alias',
         refresh_interval='10s',
         type_name='test-doc',
         bulk_concurrency=20,
         batch_size=8388608 * 2,
         compression_level=9,
         llapi=True,
     )
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django_zombodb.indexes.ZomboDBIndex')
     self.assertEqual(args, ())
     self.assertEqual(
         kwargs, {
             'fields': ['title'],
             'name': 'test_title_zombodb',
             'url': 'http://localhost/',
             'shards': 2,
             'replicas': 2,
             'alias': 'test-alias',
             'refresh_interval': '10s',
             'type_name': 'test-doc',
             'bulk_concurrency': 20,
             'batch_size': 8388608 * 2,
             'compression_level': 9,
             'llapi': True,
         })
示例#4
0
 class Meta:
     indexes = [
         ZomboDBIndex(fields=[
             'name',
             'street',
             'zip_code',
             'city',
             'state',
             'phone',
             'categories',
         ],
                      field_mapping={
                          'name': {
                              "type": "text",
                              "copy_to": "zdb_all",
                              "analyzer": "fulltext_with_shingles",
                              "search_analyzer":
                              "fulltext_with_shingles_search"
                          },
                          'street': {
                              "type": "text",
                              "copy_to": "zdb_all",
                              "analyzer": "fulltext_with_shingles",
                              "search_analyzer":
                              "fulltext_with_shingles_search"
                          },
                      })
     ]
示例#5
0
    def test_exception_no_url(self):
        del settings.ZOMBODB_ELASTICSEARCH_URL

        with self.assertRaises(ImproperlyConfigured) as cm:
            ZomboDBIndex(fields=['title'], name='test_title_zombodb')

        self.assertEqual(str(cm.exception),
                         "Please set ZOMBODB_ELASTICSEARCH_URL on settings.")
示例#6
0
 def setUp(self):
     self.index_name = 'my_other_test_index'
     self.index = ZomboDBIndex(fields=['dates', 'times'],
                               name=self.index_name,
                               url='http://localhost:7777/')
     with connection.schema_editor() as editor:
         self.remove_sql_str = self.index.remove_sql(
             model=DateTimeArrayModel, schema_editor=editor)
示例#7
0
 def test_deconstruct_no_args(self):
     index = ZomboDBIndex(fields=['title'], name='test_title_zombodb')
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django_zombodb.indexes.ZomboDBIndex')
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {
         'fields': ['title'],
         'name': 'test_title_zombodb'
     })
示例#8
0
    def test_exception_old_url_param(self):
        with self.assertRaises(ImproperlyConfigured) as cm:
            ZomboDBIndex(url='http://localhost:9200/',
                         fields=['title'],
                         name='test_title_zombodb')

        self.assertEqual(
            str(cm.exception), "The `url` param is not supported anymore. "
            "Instead, please remove it and set ZOMBODB_ELASTICSEARCH_URL on settings."
        )
示例#9
0
 def setUp(self):
     self.index_name = 'my_other_test_index'
     self.index = ZomboDBIndex(
         fields=['dates', 'times'],
         name=self.index_name,
     )
     with connection.schema_editor() as editor:
         self.statement_adapter_or_str = self.index.remove_sql(
             model=DateTimeArrayModel, schema_editor=editor)
         self.str = str(self.statement_adapter_or_str)
         self.repr = repr(self.statement_adapter_or_str)
示例#10
0
 class Meta:
     indexes = [
         ZomboDBIndex(fields=[
             'name',
             'street',
             'zip_code',
             'city',
             'state',
             'phone',
             'categories',
         ]),
     ]
示例#11
0
 class Meta:
     indexes = [
         Index(name='other-index', fields=['url']),
         ZomboDBIndex(url='http://localhost:9200/',
                      fields=[
                          'name',
                          'street',
                          'zip_code',
                          'city',
                          'state',
                          'phone',
                          'email',
                          'website',
                          'categories',
                      ]),
     ]
示例#12
0
 def test_zombodb_index(self):
     # Ensure the table is there and doesn't have an index.
     self.assertNotIn(
         'field', self.get_constraints(IntegerArrayModel._meta.db_table))
     # Add the index
     index_name = 'integer_array_model_field_zombodb'
     index = ZomboDBIndex(fields=['field'], name=index_name)
     with connection.schema_editor() as editor:
         editor.add_index(IntegerArrayModel, index)
     constraints = self.get_constraints(IntegerArrayModel._meta.db_table)
     # Check zombodb index was added
     self.assertEqual(constraints[index_name]['type'], ZomboDBIndex.suffix)
     # Drop the index
     with connection.schema_editor() as editor:
         editor.remove_index(IntegerArrayModel, index)
     self.assertNotIn(
         index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
示例#13
0
 def setUp(self):
     self.index_name = 'my_test_index'
     self.index = ZomboDBIndex(
         fields=['datetimes', 'dates', 'times'],
         name=self.index_name,
         shards=4,
         replicas=1,
         alias='my-test-index-alias',
         refresh_interval='1s',
         type_name='doc',
         bulk_concurrency=10,
         batch_size=8388608,
         compression_level=9,
         llapi=False,
     )
     with connection.schema_editor() as editor:
         self.statement_adapter = self.index.create_sql(
             model=DateTimeArrayModel, schema_editor=editor, using='')
         self.repr = repr(self.statement_adapter)
         self.str = str(self.statement_adapter)
示例#14
0
 def test_zombodb_parameters(self):
     index_name = 'integer_array_zombodb_params'
     index = ZomboDBIndex(
         fields=['field'],
         field_mapping=OrderedDict([('title', {
             'type': 'text'
         })]),
         name=index_name,
         shards=2,
         replicas=2,
         alias='test-alias',
         refresh_interval='10s',
         type_name='test-doc',
         bulk_concurrency=20,
         batch_size=8388608 * 2,
         compression_level=9,
         llapi=True,
     )
     with connection.schema_editor() as editor:
         editor.add_index(IntegerArrayModel, index)
     constraints = self.get_constraints(IntegerArrayModel._meta.db_table)
     self.assertEqual(constraints[index_name]['type'], ZomboDBIndex.suffix)
     actual_options = constraints[index_name]['options']
     for expected_option in [
             "url=http://localhost:9200/",
             "shards=2",
             "replicas=2",
             "alias=test-alias",
             "refresh_interval=10s",
             "type_name=test-doc",
             "bulk_concurrency=20",
             "batch_size=16777216",
             "compression_level=9",
             "llapi=true",
     ]:
         self.assertIn(expected_option, actual_options)
     with connection.schema_editor() as editor:
         editor.remove_index(IntegerArrayModel, index)
     self.assertNotIn(
         index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
示例#15
0
 def test_eq(self):
     index = ZomboDBIndex(fields=['title'])
     same_index = ZomboDBIndex(fields=['title'])
     another_index = ZomboDBIndex(fields=['author'])
     self.assertEqual(index, same_index)
     self.assertNotEqual(index, another_index)
示例#16
0
 class Meta:
     indexes = [
         ZomboDBIndex(fields=[
             'content',
         ]),
     ]
示例#17
0
 def test_not_eq(self):
     index_with_default_url = ZomboDBIndex(fields=['title'])
     index_with_other_url = ZomboDBIndex(fields=['title'],
                                         url='http://localhost/')
     self.assertNotEqual(index_with_default_url, index_with_other_url)
示例#18
0
 def test_name_auto_generation(self):
     index = ZomboDBIndex(fields=['datetimes', 'dates', 'times'])
     index.set_name_with_model(DateTimeArrayModel)
     self.assertEqual(index.name, 'tests_datet_datetim_22445c_zombodb')