<commit_before>from django.conf import settings
from elasticsearch import NotFoundError

from corehq.util.test_utils import unit_testing_only

TEST_ES_PREFIX = 'test_'


def es_index(index):
    prefix = '' if not settings.UNIT_TESTING else TEST_ES_PREFIX
    return "{}{}".format(prefix, index)


@unit_testing_only
def ensure_index_deleted(es_index):
    ensure_production_index_deleted(es_index)


def ensure_production_index_deleted(es_index):
    """
    Like ensure_index_deleted but usable outside unit tests
    """
    try:
        delete_production_es_index(es_index)
    except NotFoundError:
        pass


@unit_testing_only
def delete_es_index(es_index):
    delete_production_es_index(es_index)


def delete_production_es_index(es_index):
    """
    Like delete_es_index but usable outside unit tests
    """
    from corehq.elastic import get_es_new

    if es_index.startswith(TEST_ES_PREFIX):
        es = get_es_new()
        es.indices.delete(index=es_index)
    else:
        raise DeleteProductionESIndex('You cannot delete a production index in tests!!')


class DeleteProductionESIndex(Exception):
    pass<commit_msg>fix production index deletion<commit_after>from django.conf import settings
from elasticsearch import NotFoundError

from corehq.util.test_utils import unit_testing_only

TEST_ES_PREFIX = 'test_'


def es_index(index):
    prefix = '' if not settings.UNIT_TESTING else TEST_ES_PREFIX
    return "{}{}".format(prefix, index)


@unit_testing_only
def ensure_index_deleted(es_index):
    ensure_production_index_deleted(es_index)


def ensure_production_index_deleted(es_index):
    """
    Like ensure_index_deleted but usable outside unit tests
    """
    try:
        delete_production_es_index(es_index)
    except NotFoundError:
        pass


@unit_testing_only
def delete_es_index(es_index):
    if es_index.startswith(TEST_ES_PREFIX):
        delete_production_es_index(es_index)

    else:
        raise DeleteProductionESIndex('You cannot delete a production index in tests!!')


def delete_production_es_index(es_index):
    """
    Like delete_es_index but usable outside unit tests
    """
    from corehq.elastic import get_es_new
    es = get_es_new()
    es.indices.delete(index=es_index)


class DeleteProductionESIndex(Exception):
    pass
{'fraction_non_alphanumeric': 0.072236727589208, 'fraction_numerical': 0.0, 'mean_word_length': 4.396713615023474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3704956', 'n_tokens_mistral': 723, 'n_tokens_neox': 705, 'n_words': 160}