<commit_before>from django.contrib.auth.models import User
from django.test import TestCase, override_settings


class TestLanguageSwitching(TestCase):
    @classmethod
    def setUpClass(cls):
        User.objects.create_user(
            username="admin", password="<PASSWORD>", email="<EMAIL>"
        )
        super(TestLanguageSwitching, cls).setUpClass()

    def setUp(self):
        self.client.login(username="admin", password="<PASSWORD>")

    def test_displays_language_form(self):
        self.client.get("/administration/language/")
        self.assertTemplateUsed("language_form.html")

    @override_settings(LANGUAGE_CODE="es")
    def test_selects_correct_language_on_form(self):
        response = self.client.get("/administration/language/")
        assert response.context["language_selection"] == "es"

    @override_settings(LANGUAGE_CODE="es-es")
    def test_falls_back_to_generic_language(self):
        response = self.client.get("/administration/language/")
        assert response.context["language_selection"] == "es"

    @override_settings(LANGUAGE_CODE="en-us")
    def test_switch_language(self):
        response = self.client.post(
            "/i18n/setlang/",
            {"language": "fr", "next": "/administration/language/"},<commit_msg>Fix integrity error reusing db in tests<commit_after>from django.contrib.auth.models import User
from django.test import TestCase, override_settings


class TestLanguageSwitching(TestCase):
    @classmethod
    def setUpClass(cls):
        super(TestLanguageSwitching, cls).setUpClass()
        User.objects.create_user(
            username="admin", password="<PASSWORD>", email="<EMAIL>"
        )

    def setUp(self):
        self.client.login(username="admin", password="<PASSWORD>")

    def test_displays_language_form(self):
        self.client.get("/administration/language/")
        self.assertTemplateUsed("language_form.html")

    @override_settings(LANGUAGE_CODE="es")
    def test_selects_correct_language_on_form(self):
        response = self.client.get("/administration/language/")
        assert response.context["language_selection"] == "es"

    @override_settings(LANGUAGE_CODE="es-es")
    def test_falls_back_to_generic_language(self):
        response = self.client.get("/administration/language/")
        assert response.context["language_selection"] == "es"

    @override_settings(LANGUAGE_CODE="en-us")
    def test_switch_language(self):
        response = self.client.post(
            "/i18n/setlang/",
            {"language": "fr", "next": "/administration/language/"},
{'fraction_non_alphanumeric': 0.13003095975232198, 'fraction_numerical': 0.0015479876160990713, 'mean_word_length': 3.7605893186003683, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, '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': '5932392', 'n_tokens_mistral': 752, 'n_tokens_neox': 731, 'n_words': 113}