def setup(self): es = ElasticSearch() es.host = 'http://127.0.1.1:9202' es.index = 'foobar' self.es = es class MyModel(self.es.Model): __type__ = 'footype' self.Model = MyModel
def setup(self): es = ElasticSearch() es.host = "http://127.0.1.1:9202" es.index = "foobar" self.es = es class MyModel(self.es.Model): __type__ = "footype" self.Model = MyModel
def test_conn(self): app = Flask('testy') app.config['ELASTICSEARCH_HOST'] = 'http://127.0.1.1:9202' app.config['ELASTICSEARCH_INDEX'] = 'foobar' es = ElasticSearch(app) with app.app_context(): assert_true(isinstance(es.conn, elasticsearch.Elasticsearch))
def test_adds_to_app_extensions(self): class App(object): name = 'foo' config = MagicMock() app = App() es = ElasticSearch(app) assert_equal(app.extensions['elasticsearch'], es)
def test_auth(self): app = Flask('testy') app.config['ELASTICSEARCH_HOST'] = 'http://*****:*****@127.0.1.1:9202' app.config['ELASTICSEARCH_INDEX'] = 'foobar' es = ElasticSearch(app) with app.app_context(): assert_equal(('foo', 'bar'), es.conn.transport.hosts[0]['http_auth'])
def setup(self): self.app = MagicMock() self.es = ElasticSearch(self.app) class MyModel(self.es.Model): __type__ = 'footype' self.Model = MyModel
def test_config(self): es = ElasticSearch( host='http://127.0.1.1:9202', index='foobar', authorization_enabled=True, ) assert_equal(es.host, 'http://127.0.1.1:9202') assert_equal(es.index, 'foobar') assert_equal(es.authorization_enabled, True)
def setup(self): app = Flask('testy') app.config['ELASTICSEARCH_HOST'] = 'http://127.0.1.1:9202' app.config['ELASTICSEARCH_INDEX'] = 'foobar' self.es = ElasticSearch(app) class MyModel(self.es.Model): __type__ = 'footype' self.Model = MyModel self.ctx = app.app_context() self.ctx.push()
def test_index(self): app = Flask('testy') app.config['ELASTICSEARCH_INDEX'] = 'foobar' es = ElasticSearch(app) with app.app_context(): assert_equal(es.index, 'foobar')
def test_init_app(self): app = MagicMock() es = ElasticSearch() es.init_app(app) assert_equal(es.app, None)
def test_noapp_error(self): es = ElasticSearch() assert_raises(RuntimeError, es.get_app)
def test_noapp_error(self): es = ElasticSearch() assert_raises(RuntimeError, lambda: es.conn)
def test_conn(self): es = ElasticSearch() es.host = 'http://127.0.1.1:9202' es.index = 'foobar' assert_true(isinstance(es.conn, elasticsearch.Elasticsearch))
def test_index(self): app = MagicMock() app.config.__getitem__.return_value = 'foobar' es = ElasticSearch(app) assert_equal(es.index, 'foobar')
def test_init_creates_model(self): es = ElasticSearch() assert_equal(es.Model.mro()[1], _Model)
def test_conn(self, pyes_mock): app = MagicMock() es = ElasticSearch(app) assert_equal(es.conn, pyes_mock.return_value)
def test_auth(self): es = ElasticSearch() es.host = "http://*****:*****@127.0.1.1:9202" es.index = "foobar" assert_equal(("foo", "bar"), es.conn.transport.hosts[0]["http_auth"])
def test_init_without_app(self): es = ElasticSearch() assert_equal(es.app, None)
def test_auth(self): es = ElasticSearch() es.host = 'http://*****:*****@127.0.1.1:9202' es.index = 'foobar' assert_equal(('foo', 'bar'), es.conn.transport.hosts[0]['http_auth'])
def test_init_with_app(self): app = MagicMock() es = ElasticSearch(app) assert_equal(es.app, app)