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)
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")
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, })
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" }, }) ]
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.")
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)
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' })
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." )
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)
class Meta: indexes = [ ZomboDBIndex(fields=[ 'name', 'street', 'zip_code', 'city', 'state', 'phone', 'categories', ]), ]
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', ]), ]
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))
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)
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))
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)
class Meta: indexes = [ ZomboDBIndex(fields=[ 'content', ]), ]
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)
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')