def _es_session(_es_client):
    """
    Session-scoped fixture that creates Elasticsearch indexes that persist for the entire test
    session.
    """
    # Create models in the test index
    for search_app in get_search_apps():
        # Clean up in case of any aborted test runs
        index_name = search_app.es_model.get_target_index_name()
        read_alias = search_app.es_model.get_read_alias()
        write_alias = search_app.es_model.get_write_alias()

        if index_exists(index_name):
            delete_index(index_name)

        if alias_exists(read_alias):
            delete_alias(read_alias)

        if alias_exists(write_alias):
            delete_alias(write_alias)

        # Create indices and aliases
        alias_names = (read_alias, write_alias)
        create_index(index_name,
                     search_app.es_model._doc_type.mapping,
                     alias_names=alias_names)

    yield _es_client

    for search_app in get_search_apps():
        delete_index(search_app.es_model.get_target_index_name())
Beispiel #2
0
def _setup_es_indexes(_es_client):
    """Sets up ES and makes the client available."""
    # Create models in the test index
    for search_app in get_search_apps():
        # Clean up in case of any aborted test runs
        index_name = search_app.es_model.get_target_index_name()
        read_alias = search_app.es_model.get_read_alias()
        write_alias = search_app.es_model.get_write_alias()

        if index_exists(index_name):
            delete_index(index_name)

        if alias_exists(read_alias):
            delete_alias(read_alias)

        if alias_exists(write_alias):
            delete_alias(write_alias)

        # Create indices and aliases
        alias_names = (read_alias, write_alias)
        create_index(index_name,
                     search_app.es_model._doc_type.mapping,
                     alias_names=alias_names)

    yield _es_client

    for search_app in get_search_apps():
        delete_index(search_app.es_model.get_target_index_name())
def test_index_exists(mock_es_client, expected):
    """Tests that `index_exists` returns True if the index exists, False otherwise."""
    index_name = 'test'

    connection = mock_es_client.return_value
    connection.indices.exists.return_value = expected

    assert elasticsearch.index_exists(index_name) == expected
    connection.indices.exists.assert_called_with(index_name)
Beispiel #4
0
def are_apps_initialised(apps):
    """Determines whether the given apps have been initialised (by init_es)."""
    return all(index_exists(app.es_model.get_write_alias()) for app in apps)