Testing

Usage

Elastic Connect supplies a set of convinience options and fixtures for testing with pytest. To use these features just

import elastic_connect.testing

in your tests or preferably conftest.py. This automatically uses some fixtures, makes available others and adds custom options for running the tests.

Options

--index-noclean
Don’t clear the indices. Debugging only, may break some tests.
--es-host, default="localhost"
Elasticsearch hostname
--es-port, default="9200"
Elasticsearch port
--es-prefix, default="test"
Elasticsearch indices prefix
--namespace, default=False
Also run tests for two namespaces

Autouse Fixtures

elastic_connect.testing.fix_es(request)[source]

@pytest.fixture(scope=”session”, autouse=True)

Fixes the default connection to elasticsearch according to --es-host and --es-port options. Waits for all namespaces to be ready. :yield: None

elastic_connect.testing.prefix_indices(request)[source]

@pytest.fixture(scope=”session”, autouse=True)

Set the prefix for all indices according to --es-prefix option, just to be safe. So with the default option a model which uses index admin_users in production will use index testadmin_users in the tests.

Fixtures

elastic_connect.testing.fix_index(request, model_classes)[source]

@pytest.fixture(scope=”module”)

Creates indices for supplied model_classes. Deletes these indices after the tests according to the --index-noclean option.

Parameters:model_classes – list of model classes
Yield:None
elastic_connect.testing.second_namespace()[source]

@pytest.fixture(scope=”module”)

Returns the Namespace object of a second elasticsearch cluster. This cluster must be available on localhost:18400. You may use this fixture as a base for your own connections to multiple elasticsearch clusters. :return: Namespace