Skip to content

Commit

Permalink
Move Model.drop_all -> es.drop_all
Browse files Browse the repository at this point in the history
The function deletes the whole index, not just one type of documents, so
this makes much more sense.
  • Loading branch information
Treora committed Dec 28, 2014
1 parent 229d841 commit 2d00201
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
12 changes: 6 additions & 6 deletions annotator/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def conn(self):
self._connection = self._connect()
return self._connection

def drop_all(self):
"""Delete the index and its contents"""
if self.conn.indices.exists(self.index):
self.conn.indices.close(self.index)
self.conn.indices.delete(self.index)

def create_models(self, models):
mappings = _compile_mappings(models)
analysis = _compile_analysis(models)
Expand Down Expand Up @@ -163,12 +169,6 @@ def get_mapping(cls):
def get_analysis(cls):
return getattr(cls, '__analysis__', {})

@classmethod
def drop_all(cls):
if cls.es.conn.indices.exists(cls.es.index):
cls.es.conn.indices.close(cls.es.index)
cls.es.conn.indices.delete(cls.es.index)

# It would be lovely if this were called 'get', but the dict semantics
# already define that method name.
@classmethod
Expand Down
6 changes: 2 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ class TestCase(object):
@classmethod
def setup_class(cls):
cls.app = create_app()
annotation.Annotation.drop_all()
document.Document.drop_all()
es.drop_all()

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

def teardown(self):
annotation.Annotation.drop_all()
document.Document.drop_all()
es.drop_all()

0 comments on commit 2d00201

Please sign in to comment.