示例#1
0
def test_es(monkeypatch):
    search_obj = pretend.stub()
    index_obj = pretend.stub(
        doc_type=pretend.call_recorder(lambda d: None),
        search=pretend.call_recorder(lambda: search_obj),
        settings=pretend.call_recorder(lambda **kw: None),
    )
    index_cls = pretend.call_recorder(lambda name, using: index_obj)
    monkeypatch.setattr(search.utils, "Index", index_cls)

    doc_types = [pretend.stub(), pretend.stub()]

    client = pretend.stub()
    request = pretend.stub(
        registry={
            "elasticsearch.client": client,
            "elasticsearch.index": "warehouse",
            "search.doc_types": doc_types,
        })

    es = search.es(request)

    assert es is search_obj
    assert index_cls.calls == [pretend.call("warehouse", using=client)]
    assert index_obj.doc_type.calls == [pretend.call(d) for d in doc_types]
    assert index_obj.settings.calls == [
        pretend.call(number_of_shards=1,
                     number_of_replicas=0,
                     refresh_interval="1s")
    ]
    assert index_obj.search.calls == [pretend.call()]
示例#2
0
def test_es(monkeypatch):
    search_obj = pretend.stub()
    index_obj = pretend.stub(
        doc_type=pretend.call_recorder(lambda d: None),
        search=pretend.call_recorder(lambda: search_obj),
        settings=pretend.call_recorder(lambda **kw: None),
    )
    index_cls = pretend.call_recorder(lambda name, using: index_obj)
    monkeypatch.setattr(search, "Index", index_cls)

    doc_types = [pretend.stub(), pretend.stub()]

    client = pretend.stub()
    request = pretend.stub(
        registry={
            "elasticsearch.client": client,
            "elasticsearch.index": "warehouse",
            "search.doc_types": doc_types,
        },
    )

    es = search.es(request)

    assert es is search_obj
    assert index_cls.calls == [pretend.call("warehouse", using=client)]
    assert index_obj.doc_type.calls == [pretend.call(d) for d in doc_types]
    assert index_obj.settings.calls == [
        pretend.call(number_of_shards=1, number_of_replicas=1),
    ]
    assert index_obj.search.calls == [pretend.call()]