def setup_es_test_data(es): try: es.cluster.health() except Exception as e: e.args = tuple([ u"%s (it looks like ES is not running, try starting it or " u"don't run ES tests: make test_no_es)" % e.args[0] ] + list(e.args[1:])) raise aliases_and_indexes = set( list(settings.ES_INDEXES.values()) + list(es.indices.get_alias().keys())) for key in aliases_and_indexes: if key.startswith('test_'): es.indices.delete(key, ignore=[404]) # Figure out the name of the indices we're going to create from the # suffixes generated at import time. Like the aliases later, the name # has been prefixed by pytest, we need to add a suffix that is unique # to this test run. actual_indices = { key: get_es_index_name(key) for key in settings.ES_INDEXES.keys() } # Create new addons and stats indexes with the timestamped name. # This is crucial to set up the correct mappings before we start # indexing things in tests. addons_indexers.create_new_index(index_name=actual_indices['default']) stats_search.create_new_index(index_name=actual_indices['stats']) # Alias it to the name the code is going to use (which is suffixed by # pytest to avoid clashing with the real thing). actions = [{ 'add': { 'index': actual_indices['default'], 'alias': settings.ES_INDEXES['default'] } }, { 'add': { 'index': actual_indices['stats'], 'alias': settings.ES_INDEXES['stats'] } }] es.indices.update_aliases({'actions': actions})
def setup_es_test_data(es): try: es.cluster.health() except Exception as e: e.args = tuple( [u"%s (it looks like ES is not running, try starting it or " u"don't run ES tests: make test_no_es)" % e.args[0]] + list(e.args[1:])) raise aliases_and_indexes = set(list(settings.ES_INDEXES.values()) + list(es.indices.get_alias().keys())) for key in aliases_and_indexes: if key.startswith('test_'): es.indices.delete(key, ignore=[404]) # Figure out the name of the indices we're going to create from the # suffixes generated at import time. Like the aliases later, the name # has been prefixed by pytest, we need to add a suffix that is unique # to this test run. actual_indices = {key: get_es_index_name(key) for key in settings.ES_INDEXES.keys()} # Create new addons and stats indexes with the timestamped name. # This is crucial to set up the correct mappings before we start # indexing things in tests. addons_indexers.create_new_index(index_name=actual_indices['default']) stats_search.create_new_index(index_name=actual_indices['stats']) # Alias it to the name the code is going to use (which is suffixed by # pytest to avoid clashing with the real thing). actions = [ {'add': {'index': actual_indices['default'], 'alias': settings.ES_INDEXES['default']}}, {'add': {'index': actual_indices['stats'], 'alias': settings.ES_INDEXES['stats']}} ] es.indices.update_aliases({'actions': actions})