# Path: elasticsearch_django/settings.py
# def auto_sync(instance: Model) -> bool:
#     """Return True if auto_sync is on for the model (instance)."""
#     # this allows us to turn off sync temporarily - e.g. when doing bulk updates
#     if not get_setting("auto_sync"):
#         return False
#     model_name = f"{instance._meta.app_label}.{instance._meta.model_name}"
#     if model_name in get_setting("never_auto_sync", *[]):
#         return False
#     return True
# 
# def get_client(connection: str = "default") -> Elasticsearch:
#     """Return configured elasticsearch client."""
#     return Elasticsearch(get_connection_string(connection))
# 
# def get_connection_string(connection: str = "default") -> str:
#     """Return index settings from Django conf."""
#     return settings.SEARCH_SETTINGS["connections"][connection]
# 
# def get_document_models() -> dict[str, Model]:
#     """Return dict of index.doc_type: model."""
#     mappings: dict[str, Model] = {}
#     for i in get_index_names():
#         for m in get_index_models(i):
#             mappings[f"{i}.{m._meta.model_name}"] = m
#     return mappings
# 
# def get_index_config(index: str) -> dict[str, list[str]]:
#     """Return index settings from Django conf."""
#     return settings.SEARCH_SETTINGS["indexes"][index]
# 
# def get_index_models(index: str) -> list[Model]:
#     """Return list of models configured for a named index."""
#     models = []  # type: List[Model]
#     for app_model in get_index_config(index).get("models"):
#         app, model = app_model.split(".")
#         models.append(apps.get_model(app, model))
#     return models
# 
# def get_index_names() -> list[str]:
#     """Return list of the names of all configured indexes."""
#     return list(settings.SEARCH_SETTINGS["indexes"].keys())
# 
# def get_model_indexes(model: Model) -> list[str]:
#     """
#     Return list of all indexes in which a model is configured.
# 
#     A model may be configured to appear in multiple indexes. This function
#     will return the names of the indexes as a list of strings. This is
#     useful if you want to know which indexes need updating when a model
#     is saved.
# 
#     Args:
#         model: a Django model class.
# 
#     """
#     indexes = []  # type: List[str]
#     for index in get_index_names():
#         for app_model in get_index_models(index):
#             if app_model == model:
#                 indexes.append(index)
#     return indexes
# 
# def get_setting(key, *default: str | int | bool | list | dict) -> SettingType:
#     """Return specific search setting from Django conf."""
#     if default:
#         return get_settings().get(key, default[0])
#     else:
#         return get_settings()[key]
# 
# def get_settings() -> SettingsType:
#     """Return settings from Django conf."""
#     return settings.SEARCH_SETTINGS["settings"]
# 
# Path: tests/models.py
# class ExampleModel(SearchDocumentMixin, models.Model):
#     """Model class for use in tests."""
# 
#     simple_field_1 = models.IntegerField()
#     simple_field_2 = models.CharField(max_length=100)
#     complex_field = models.FileField()
# 
#     objects = ExampleModelManager()
# 
#     def as_search_document(self, index="_all"):
#         return {
#             "simple_field_1": self.simple_field_1,
#             "simple_field_2": self.simple_field_2,
#             "complex_field": str(self.complex_field),
#         }


from unittest import mock
from django.test import TestCase
from django.test.utils import override_settings
from elasticsearch_django.settings import (
    auto_sync,
    get_client,
    get_connection_string,
    get_document_models,
    get_index_config,
    get_index_models,
    get_index_names,
    get_model_indexes,
    get_setting,
    get_settings,
)
from .models import ExampleModel
        from django.apps import apps

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_index_models(self):
        """Test the get_index_models function."""

        models = get_index_models("baz")
        self.assertEqual(models, [apps.get_model("tests", "ExampleModel")])

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_model_indexes(self):
        """Test the get_model_indexes function."""
        # ExampleModel is in the TEST_SETTINGS
        self.assertEqual(get_model_indexes(ExampleModel), ["baz"])
        # plain old object isn't in any indexes
        self.assertEqual(get_model_indexes(object), [])

    def test_get_index_mapping(self):
        """Test the get_index_mapping function."""
        # this interacts with the file system, not going to bother to test
        # as it just opens a file and loads in into a dict - there's no 'logic'
        pass

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_document_models(self):
        """Test the get_document_models function."""
        self.assertEqual(get_document_models(), {"baz.examplemodel": ExampleModel})

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_auto_sync(self):
        """Test the auto_sync function."""

# Path: elasticsearch_django/settings.py
# def auto_sync(instance: Model) -> bool:
#     """Return True if auto_sync is on for the model (instance)."""
#     # this allows us to turn off sync temporarily - e.g. when doing bulk updates
#     if not get_setting("auto_sync"):
#         return False
#     model_name = f"{instance._meta.app_label}.{instance._meta.model_name}"
#     if model_name in get_setting("never_auto_sync", *[]):
#         return False
#     return True
# 
# def get_client(connection: str = "default") -> Elasticsearch:
#     """Return configured elasticsearch client."""
#     return Elasticsearch(get_connection_string(connection))
# 
# def get_connection_string(connection: str = "default") -> str:
#     """Return index settings from Django conf."""
#     return settings.SEARCH_SETTINGS["connections"][connection]
# 
# def get_document_models() -> dict[str, Model]:
#     """Return dict of index.doc_type: model."""
#     mappings: dict[str, Model] = {}
#     for i in get_index_names():
#         for m in get_index_models(i):
#             mappings[f"{i}.{m._meta.model_name}"] = m
#     return mappings
# 
# def get_index_config(index: str) -> dict[str, list[str]]:
#     """Return index settings from Django conf."""
#     return settings.SEARCH_SETTINGS["indexes"][index]
# 
# def get_index_models(index: str) -> list[Model]:
#     """Return list of models configured for a named index."""
#     models = []  # type: List[Model]
#     for app_model in get_index_config(index).get("models"):
#         app, model = app_model.split(".")
#         models.append(apps.get_model(app, model))
#     return models
# 
# def get_index_names() -> list[str]:
#     """Return list of the names of all configured indexes."""
#     return list(settings.SEARCH_SETTINGS["indexes"].keys())
# 
# def get_model_indexes(model: Model) -> list[str]:
#     """
#     Return list of all indexes in which a model is configured.
# 
#     A model may be configured to appear in multiple indexes. This function
#     will return the names of the indexes as a list of strings. This is
#     useful if you want to know which indexes need updating when a model
#     is saved.
# 
#     Args:
#         model: a Django model class.
# 
#     """
#     indexes = []  # type: List[str]
#     for index in get_index_names():
#         for app_model in get_index_models(index):
#             if app_model == model:
#                 indexes.append(index)
#     return indexes
# 
# def get_setting(key, *default: str | int | bool | list | dict) -> SettingType:
#     """Return specific search setting from Django conf."""
#     if default:
#         return get_settings().get(key, default[0])
#     else:
#         return get_settings()[key]
# 
# def get_settings() -> SettingsType:
#     """Return settings from Django conf."""
#     return settings.SEARCH_SETTINGS["settings"]
# 
# Path: tests/models.py
# class ExampleModel(SearchDocumentMixin, models.Model):
#     """Model class for use in tests."""
# 
#     simple_field_1 = models.IntegerField()
#     simple_field_2 = models.CharField(max_length=100)
#     complex_field = models.FileField()
# 
#     objects = ExampleModelManager()
# 
#     def as_search_document(self, index="_all"):
#         return {
#             "simple_field_1": self.simple_field_1,
#             "simple_field_2": self.simple_field_2,
#             "complex_field": str(self.complex_field),
#         }


# Path: tests/test_settings.py
from unittest import mock
from django.test import TestCase
from django.test.utils import override_settings
from elasticsearch_django.settings import (
    auto_sync,
    get_client,
    get_connection_string,
    get_document_models,
    get_index_config,
    get_index_models,
    get_index_names,
    get_model_indexes,
    get_setting,
    get_settings,
)
from .models import ExampleModel
        from django.apps import apps


    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_index_models(self):
        """Test the get_index_models function."""

        models = get_index_models("baz")
        self.assertEqual(models, [apps.get_model("tests", "ExampleModel")])

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_model_indexes(self):
        """Test the get_model_indexes function."""
        # ExampleModel is in the TEST_SETTINGS
        self.assertEqual(get_model_indexes(ExampleModel), ["baz"])
        # plain old object isn't in any indexes
        self.assertEqual(get_model_indexes(object), [])

    def test_get_index_mapping(self):
        """Test the get_index_mapping function."""
        # this interacts with the file system, not going to bother to test
        # as it just opens a file and loads in into a dict - there's no 'logic'
        pass

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_get_document_models(self):
        """Test the get_document_models function."""
        self.assertEqual(get_document_models(), {"baz.examplemodel": ExampleModel})

    @override_settings(SEARCH_SETTINGS=TEST_SETTINGS)
    def test_auto_sync(self):
        """Test the auto_sync function."""

        obj = ExampleModel()