From 2d0020107a45040aef3fa04bef03cd12e1eeaf50 Mon Sep 17 00:00:00 2001 From: Gerben Date: Sun, 28 Dec 2014 00:45:06 +0100 Subject: [PATCH] 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. --- annotator/elasticsearch.py | 12 ++++++------ tests/__init__.py | 6 ++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/annotator/elasticsearch.py b/annotator/elasticsearch.py index c81f661..e4ca087 100644 --- a/annotator/elasticsearch.py +++ b/annotator/elasticsearch.py @@ -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) @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index ead7f44..9c7c352 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -30,8 +30,7 @@ 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]) @@ -39,5 +38,4 @@ def setup(self): self.cli = self.app.test_client() def teardown(self): - annotation.Annotation.drop_all() - document.Document.drop_all() + es.drop_all()