Skip to content

Commit 2d00201

Browse files
committed
Move Model.drop_all -> es.drop_all
The function deletes the whole index, not just one type of documents, so this makes much more sense.
1 parent 229d841 commit 2d00201

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

annotator/elasticsearch.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def conn(self):
6666
self._connection = self._connect()
6767
return self._connection
6868

69+
def drop_all(self):
70+
"""Delete the index and its contents"""
71+
if self.conn.indices.exists(self.index):
72+
self.conn.indices.close(self.index)
73+
self.conn.indices.delete(self.index)
74+
6975
def create_models(self, models):
7076
mappings = _compile_mappings(models)
7177
analysis = _compile_analysis(models)
@@ -163,12 +169,6 @@ def get_mapping(cls):
163169
def get_analysis(cls):
164170
return getattr(cls, '__analysis__', {})
165171

166-
@classmethod
167-
def drop_all(cls):
168-
if cls.es.conn.indices.exists(cls.es.index):
169-
cls.es.conn.indices.close(cls.es.index)
170-
cls.es.conn.indices.delete(cls.es.index)
171-
172172
# It would be lovely if this were called 'get', but the dict semantics
173173
# already define that method name.
174174
@classmethod

tests/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ class TestCase(object):
3030
@classmethod
3131
def setup_class(cls):
3232
cls.app = create_app()
33-
annotation.Annotation.drop_all()
34-
document.Document.drop_all()
33+
es.drop_all()
3534

3635
def setup(self):
3736
es.create_models([annotation.Annotation, document.Document])
3837
es.conn.cluster.health(wait_for_status='yellow')
3938
self.cli = self.app.test_client()
4039

4140
def teardown(self):
42-
annotation.Annotation.drop_all()
43-
document.Document.drop_all()
41+
es.drop_all()

0 commit comments

Comments
 (0)