def test_build_query_field_mapping(client_with_entries_scope_session,
                                   resources, query, expected):
    args = {"sort": "shut up"}
    if query:
        args["q"] = query
    q = search.build_query(args, resources)

    print("q = {q}".format(q=q))
    assert isinstance(q, EsQuery)
    assert q.query == expected
예제 #2
0
def query(resources: str):
    print("Called 'query' called with resources={}".format(resources))
    resource_list = resources.split(",")
    resourcemgr.check_resource_published(resource_list)
    try:
        q = search.build_query(request.args, resources)
        print("query::q={q}".format(q=q))
        response = search.search_with_query(q)
    except errors.KarpError as e:
        _logger.exception(
            "Error occured when calling 'query' with resources='{}' and q='{}'. e.msg='{}"
            .format(resources, request.args.get("q"), e.message))
        raise
    return flask_jsonify(response), 200
예제 #3
0
def test_es_search(es, client_with_data_f):
    if es == "skip":
        pytest.skip("elasticsearch disabled")

    client_with_data = init(client_with_data_f, es)

    with client_with_data.application.app_context():
        args = {"q": "equals|population|3"}
        query = search.build_query(args, "places,municipalities")
        ids = search.search_with_query(query)
        assert len(ids["hits"]) == 1
        print("ids[0] = {}".format(ids["hits"][0]))
        assert "entry" in ids["hits"][0]
        assert ids["hits"][0]["entry"]["population"] == 3
예제 #4
0
def test_es_search2(es, client_with_data_f):
    if es == "skip":
        pytest.skip("elasticsearch disabled")

    client_with_data = init(client_with_data_f, es)

    with client_with_data.application.app_context():
        args = {"q": "equals|population|3"}
        query = search.build_query(args, "places,municipalities")
        assert isinstance(query, es_search.EsQuery)
        query.split_results = True
        result = search.search_with_query(query)
        assert "hits" in result
        assert "places" in result["hits"]
        assert "municipalities" in result["hits"]
        assert len(result["hits"]["municipalities"]) == 0
        assert len(result["hits"]["places"]) == 1