Beispiel #1
0
def prepare_es_for_model(cls):

    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[cls])
    assert es.indices.exists(index=cls.get_index())
    print("before", cls.get_index())
    return indices
def test_delete_indices(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[One, Two])
    assert es.indices.exists(index=request.config.getoption("--es-prefix") +
                             '_' + 'model_one')
    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(
        index=request.config.getoption("--es-prefix") + '_' + 'model_one')
def mappings_one_two(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[One, Two])
    assert len(indices) == 2

    yield

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
    else:
        elastic_connect.delete_indices(indices=indices)
        assert not es.indices.exists(index=One.get_index())
        assert not es.indices.exists(index=Two.get_index())
Beispiel #4
0
def fix_one_many(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[One, Many])
    assert es.indices.exists(index=One.get_index())
    assert es.indices.exists(index=Many.get_index())

    yield

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
        return
    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(index=One.get_index())
    assert not es.indices.exists(index=Many.get_index())
Beispiel #5
0
def fix_id_one_many_with_reference(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(
        model_classes=[IdOneWithReference, IdManyWithReference])
    assert es.indices.exists(index=IdOneWithReference.get_index())
    assert es.indices.exists(index=IdManyWithReference.get_index())

    yield

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
        return
    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(index=IdOneWithReference.get_index())
    assert not es.indices.exists(index=IdManyWithReference.get_index())
Beispiel #6
0
def fix_parent_child(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[Parent, Child])

    assert es.indices.exists(index=Parent.get_index())
    assert es.indices.exists(index=Child.get_index())

    yield

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
        return
    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(index=Parent.get_index())
    assert not es.indices.exists(index=Child.get_index())
Beispiel #7
0
def fix_user_key(request):
    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(
        model_classes=[User, UserNoLoad, Key])

    assert es.indices.exists(index=User.get_index())
    assert es.indices.exists(index=UserNoLoad.get_index())
    assert es.indices.exists(index=Key.get_index())

    yield

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
        return
    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(index=User.get_index())
    assert not es.indices.exists(index=UserNoLoad.get_index())
    assert not es.indices.exists(index=Key.get_index())
def fix_model_one_save(request):
    class OneSave(Model):
        __slots__ = ('value', )

        _meta = {'_doc_type': 'model_save_one'}
        _mapping = {'id': Keyword(name='id'), 'value': Keyword(name='value')}

    es = elastic_connect.get_es()
    indices = elastic_connect.create_mappings(model_classes=[OneSave])
    assert es.indices.exists(index=OneSave.get_index())

    yield OneSave

    if request.config.getoption("--index-noclean"):
        print("** not cleaning")
        return

    elastic_connect.delete_indices(indices=indices)
    assert not es.indices.exists(index=OneSave.get_index())