跳转到主要内容

ElasticSearch查询测试工具

项目描述

ESTester是一个Python包,用于帮助测试ElasticSearch查询。

它提供了一个TestCase,允许您将数据加载到测试索引中并验证搜索查询的行为。

如何安装

使用pip从Cheeseshop安装

pip install estester

或者,从源安装

git clone git://github.com/tatiana/estester.git
python setup.py install

如何使用

ESTester定义了一个主要测试类,称为ElasticSearchQueryTestCase。

为了使用它,您应该从它派生一个子类并重新定义一个或多个类属性

  • index:索引的名称(默认:sample.test)

  • host:ElasticSearch主机(默认:http://localhost:9200/

  • fixtures:要加载的项目列表(默认:[])

  • timeout:等待索引加载的时间(秒)(默认:5s)

  • reset_index:在运行测试后删除索引(默认:True)

基本示例,仅重新定义fixtures

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并且它已启动:

make setup make test

兼容性

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 <https://gnu.ac.cn/licenses/>.

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

ESTester-1.1.0.tar.gz (4.2 kB 查看哈希值)

上传时间

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页