# Path: modeltrans/conf.py
# def check_fallback_chain():
#     MODELTRANS_FALLBACK = get_modeltrans_setting("MODELTRANS_FALLBACK")
#     MODELTRANS_AVAILABLE_LANGUAGES = get_available_languages(include_default=True)
# 
#     if "default" not in MODELTRANS_FALLBACK:
#         raise ImproperlyConfigured("MODELTRANS_FALLBACK setting must have a `default` key.")
# 
#     message_fmt = (
#         "MODELTRANS_FALLBACK contains language `{}` "
#         "which is not in MODELTRANS_AVAILABLE_LANGUAGES"
#     )
#     for lang, chain in MODELTRANS_FALLBACK.items():
#         if lang != "default" and lang not in MODELTRANS_AVAILABLE_LANGUAGES:
#             raise ImproperlyConfigured(message_fmt.format(lang))
#         for lang in chain:
#             if lang not in MODELTRANS_AVAILABLE_LANGUAGES:
#                 raise ImproperlyConfigured(message_fmt.format(lang))
# 
# def get_available_languages_setting():
#     """
#     list of available languages for modeltrans translations.
#     defaults to the list of language codes extracted from django setting LANGUAGES
#     """
#     languages = tuple(
#         set(
#             getattr(
#                 settings,
#                 "MODELTRANS_AVAILABLE_LANGUAGES",
#                 (code for code, _ in getattr(settings, "LANGUAGES")),
#             )
#         )
#     )
# 
#     if not all(isinstance(x, str) for x in languages):
#         raise ImproperlyConfigured(
#             "MODELTRANS_AVAILABLE_LANGUAGES should be an iterable of strings"
#         )
# 
#     # make sure LANGUAGE_CODE is not in available languages
#     return (lang for lang in languages if lang != get_default_language())


from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
from modeltrans.conf import check_fallback_chain, get_available_languages_setting



class FallbackConfTest(TestCase):
    @override_settings(MODELTRANS_FALLBACK={"fy": ("nl", "en")})
    def test_fallback_must_have_default(self):
        message = "MODELTRANS_FALLBACK setting must have a `default` key."

        with self.assertRaisesMessage(ImproperlyConfigured, message):

# Path: modeltrans/conf.py
# def check_fallback_chain():
#     MODELTRANS_FALLBACK = get_modeltrans_setting("MODELTRANS_FALLBACK")
#     MODELTRANS_AVAILABLE_LANGUAGES = get_available_languages(include_default=True)
# 
#     if "default" not in MODELTRANS_FALLBACK:
#         raise ImproperlyConfigured("MODELTRANS_FALLBACK setting must have a `default` key.")
# 
#     message_fmt = (
#         "MODELTRANS_FALLBACK contains language `{}` "
#         "which is not in MODELTRANS_AVAILABLE_LANGUAGES"
#     )
#     for lang, chain in MODELTRANS_FALLBACK.items():
#         if lang != "default" and lang not in MODELTRANS_AVAILABLE_LANGUAGES:
#             raise ImproperlyConfigured(message_fmt.format(lang))
#         for lang in chain:
#             if lang not in MODELTRANS_AVAILABLE_LANGUAGES:
#                 raise ImproperlyConfigured(message_fmt.format(lang))
# 
# def get_available_languages_setting():
#     """
#     list of available languages for modeltrans translations.
#     defaults to the list of language codes extracted from django setting LANGUAGES
#     """
#     languages = tuple(
#         set(
#             getattr(
#                 settings,
#                 "MODELTRANS_AVAILABLE_LANGUAGES",
#                 (code for code, _ in getattr(settings, "LANGUAGES")),
#             )
#         )
#     )
# 
#     if not all(isinstance(x, str) for x in languages):
#         raise ImproperlyConfigured(
#             "MODELTRANS_AVAILABLE_LANGUAGES should be an iterable of strings"
#         )
# 
#     # make sure LANGUAGE_CODE is not in available languages
#     return (lang for lang in languages if lang != get_default_language())


# Path: tests/test_conf.py
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, override_settings
from modeltrans.conf import check_fallback_chain, get_available_languages_setting




class FallbackConfTest(TestCase):
    @override_settings(MODELTRANS_FALLBACK={"fy": ("nl", "en")})
    def test_fallback_must_have_default(self):
        message = "MODELTRANS_FALLBACK setting must have a `default` key."

        with self.assertRaisesMessage(ImproperlyConfigured, message):

            check_fallback_chain()