用于测试ElasticSearch查询的实用程序
ESTester的Python项目详细描述
estester是一个python包,用于帮助测试elasticsearch查询。
它提供了一个测试用例,允许您将数据加载到测试索引 并验证搜索查询的行为。
如何安装
使用pip从cheeseshop安装
pip install estester
或者,从源安装
git clone git://github.com/tatiana/estester.git python setup.py install
如何使用
Estester定义了一个主测试类,称为ElasticSearchQueryTestCase。
为了使用它,您应该对它进行子类化并重新定义一个或多个类属性:
- index:索引的名称(默认值:sample.test)
- 主机:elasticsearch主机(默认值:http://localhost:9200/)
- fixtures:要加载的项目列表(默认值:[])
- 超时:等待索引加载的时间(秒)(默认值:5s)
- 重置索引:运行测试后删除索引(默认值:true)
基本示例,仅重新定义装置:
from estester import ElasticSearchQueryTestCase SAMPLE_QUERY = { "query": { "query_string": { "fields": [ "name" ], "query": "nina" } } } class QueryTestCase(ElasticSearchQueryTestCase): fixtures = [ { "type": "dog", "id": "1", "body": {"name": "Nina Fox"} }, { "type": "dog", "id": "2", "body": {"name": "Charles M."} } ] def test_query_by_nina_returns_one_result(self): response = self.query(SAMPLE_QUERY) self.assertEqual(response["hits"]["total"], 1) self.assertEqual(response["hits"]["hits"][0]["_id"], u"1") self.assertEqual(response["hits"]["hits"][0]["_source"], {u"name": u"Nina Fox"})
Estester测试
- 若要运行Estester测试,请确保已在本地安装ElasticSearch,并且它已启动:
- 设置 进行测试
兼容性
Estester已成功用于测试ElasticSearch 19.x和90.x版本的查询。
有关这个令人惊叹的开源搜索引擎的更多信息,请阅读: http://www.elasticsearch.org/
许可证
Estester是GNU GPL 2:
< ESTester: ElasticSearch Tester > Copyright (C) 2013 - Tatiana Al-Chueyr Pereira Martins ESTester is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License. ESTester is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with ESTester. If not, see <http://www.gnu.org/licenses/>.