예제 #1
0
    def test_admin_licence_change_view_get(self):
        """
        The admin change view should include the name and content fields for the given language.
        """
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="******")

        # Create a licence with English fields and French translations
        licence = LicenceFactory(name="some licence name",
                                 content="some licence text content")
        with switch_language(licence, "fr"):
            licence.name = "quelque nom de licence"
            licence.content = "quelque contenu textuel de licence"
            licence.save()

        # Get the admin change view in English
        url = reverse("admin:courses_licence_change", args=[licence.id])
        response = self.client.get(url)

        # Check that the page includes the name and content in English
        with switch_language(licence, "en"):
            self.assertContains(response, licence.name)
            self.assertContains(response, licence.content)

        # Get the admin change view in French
        url = reverse("admin:courses_licence_change", args=[licence.id])
        response = self.client.get("{}?language=fr".format(url))

        # Check that the page includes the name and content in French
        with switch_language(licence, "fr"):
            self.assertContains(response, licence.name)
            self.assertContains(response, licence.content)
예제 #2
0
    def test_admin_licence_list_view(self):
        """
        The admin list view of licences should display the name of the licence.
        """
        user = UserFactory(is_staff=True, is_superuser=True)
        self.client.login(username=user.username, password="******")

        # Create a licence with English fields and French translations
        licence = LicenceFactory(name="some licence name")
        with switch_language(licence, "fr"):
            licence.name = "quelque nom de licence"
            licence.save()

        # Get the admin list view in English
        url = reverse("admin:courses_licence_changelist")
        response = self.client.get(url, follow=True)

        # Check that the page includes the name in English
        with switch_language(licence, "en"):
            self.assertContains(response, licence.name, status_code=200)

        # Get the admin change view in French
        with translation.override("fr"):
            url = reverse("admin:courses_licence_changelist")
        response = self.client.get(url)

        # Check that the page includes the name in French
        with switch_language(licence, "fr"):
            self.assertContains(response, licence.name)
예제 #3
0
    def test_models_licence_fields_name_internationalized(self):
        """
        The "name" field on Licence is internationalized using django-parler.
        """
        licence = LicenceFactory(name="licence name")

        with switch_language(licence, "en"):
            self.assertEqual(licence.name, "licence name")

        with switch_language(licence, "fr"):
            self.assertEqual(licence.name, "licence name")

            licence.name = "nom de la licence"
            licence.save()

            self.assertEqual(licence.name, "nom de la licence")

        with switch_language(licence, "en"):
            self.assertEqual(licence.name, "licence name")
예제 #4
0
    def test_indexers_licences_get_es_documents(self):
        """
        Happy path: licence data is fetched from the models properly formatted
        """
        licence1 = LicenceFactory(name="my first licence")
        with switch_language(licence1, "fr"):
            licence1.name = "ma première licence"
            licence1.content = "première licence contenu"
            licence1.save()

        licence2 = LicenceFactory(name="my second licence")
        with switch_language(licence2, "fr"):
            licence2.name = "ma deuxième licence"
            licence2.content = "deuxième licence contenu"
            licence2.save()

        # The results were properly formatted and passed to the consumer
        self.assertEqual(
            list(
                LicencesIndexer.get_es_documents(index="some_index",
                                                 action="some_action")),
            [
                {
                    "_id": licence1.id,
                    "_index": "some_index",
                    "_op_type": "some_action",
                    "complete": {
                        "en": [
                            "my first licence",
                            "first licence",
                            "licence",
                        ],
                        "fr": [
                            "ma première licence",
                            "première licence",
                            "licence",
                        ],
                    },
                    "content": {
                        "en": licence1.content,
                        "fr": "première licence contenu",
                    },
                    "title": {
                        "en": "my first licence",
                        "fr": "ma première licence",
                    },
                    "title_raw": {
                        "en": "my first licence",
                        "fr": "ma première licence",
                    },
                },
                {
                    "_id": licence2.id,
                    "_index": "some_index",
                    "_op_type": "some_action",
                    "complete": {
                        "en": [
                            "my second licence",
                            "second licence",
                            "licence",
                        ],
                        "fr": [
                            "ma deuxième licence",
                            "deuxième licence",
                            "licence",
                        ],
                    },
                    "content": {
                        "en": licence2.content,
                        "fr": "deuxième licence contenu",
                    },
                    "title": {
                        "en": "my second licence",
                        "fr": "ma deuxième licence",
                    },
                    "title_raw": {
                        "en": "my second licence",
                        "fr": "ma deuxième licence",
                    },
                },
            ],
        )