コード例 #1
0
    def test_blockquoteblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id), "test_blockquoteblock", "Test content"
        )

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [StringSegmentValue(f"test_streamfield.{block_id}", "Tester le contenu")],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            translated_page.test_streamfield.stream_data,
            [
                {
                    "id": str(block_id),
                    "type": "test_blockquoteblock",
                    "value": "Tester le contenu",
                }
            ],
        )
コード例 #2
0
    def test_childobjects(self):
        page = make_test_page()
        page.test_childobjects.add(TestChildObject(field="Test content"))
        page.save()

        child_translation_key = TestChildObject.objects.get().translation_key

        translated_page = page.copy_for_translation(self.locale)

        copy_synchronised_fields(page, translated_page)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                StringSegmentValue(
                    f"test_childobjects.{child_translation_key}.field",
                    "Tester le contenu",
                )
            ],
        )

        old_child_object = page.test_childobjects.get()
        new_child_object = translated_page.test_childobjects.get()

        self.assertNotEqual(old_child_object.id, new_child_object.id)
        self.assertEqual(old_child_object.locale, self.src_locale)
        self.assertEqual(new_child_object.locale, self.locale)
        self.assertEqual(
            old_child_object.translation_key, new_child_object.translation_key
        )

        self.assertEqual(new_child_object.field, "Tester le contenu")
コード例 #3
0
    def test_rawhtmlblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id), "test_rawhtmlblock", RICH_TEXT_TEST_INPUT
        )

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                segment.wrap(f"test_streamfield.{block_id}")
                for segment in RICH_TEXT_TEST_FRENCH_SEGMENTS
            ],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            translated_page.test_streamfield.stream_data,
            [
                {
                    "id": str(block_id),
                    "type": "test_rawhtmlblock",
                    "value": RICH_TEXT_TEST_OUTPUT,
                }
            ],
        )
コード例 #4
0
    def test_listblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id), "test_listblock",
            ["Test content", "Some more test content"])

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                StringSegmentValue(f"test_streamfield.{block_id}",
                                   "Tester le contenu",
                                   order=0),
                StringSegmentValue(f"test_streamfield.{block_id}",
                                   "Encore du contenu de test",
                                   order=1),
            ],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            translated_page.test_streamfield.stream_data,
            [{
                "id": str(block_id),
                "type": "test_listblock",
                "value": ["Tester le contenu", "Encore du contenu de test"],
            }],
        )
コード例 #5
0
    def test_embedblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id), "test_embedblock",
            "https://www.youtube.com/watch?v=pGpCHRyUZXQ")

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                OverridableSegmentValue(
                    f"test_streamfield.{block_id}",
                    "https://www.youtube.com/watch?v=aBByJQCaaEA")
            ],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            list(translated_page.test_streamfield.stream_data),
            [{
                "id": str(block_id),
                "type": "test_embedblock",
                "value": "https://www.youtube.com/watch?v=aBByJQCaaEA",
            }],
        )
コード例 #6
0
    def test_urlblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id), "test_urlblock", "http://test-content.com/foo")

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                StringSegmentValue(f"test_streamfield.{block_id}",
                                   "http://test-content.fr/foo")
            ],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            list(translated_page.test_streamfield.stream_data),
            [{
                "id": str(block_id),
                "type": "test_urlblock",
                "value": "http://test-content.fr/foo",
            }],
        )
コード例 #7
0
    def test_emailfield(self):
        page = make_test_page(test_emailfield="*****@*****.**")
        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [StringSegmentValue("test_emailfield", "*****@*****.**")],
        )

        self.assertEqual(translated_page.test_emailfield, "*****@*****.**")
コード例 #8
0
    def test_textfield(self):
        page = make_test_page(test_textfield="Test content")
        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [StringSegmentValue("test_textfield", "Tester le contenu")],
        )

        self.assertEqual(translated_page.test_textfield, "Tester le contenu")
コード例 #9
0
    def test_urlfield(self):
        page = make_test_page(test_urlfield="http://test-content.com/foo")
        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [StringSegmentValue("test_urlfield", "http://test-content.fr/foo")],
        )

        self.assertEqual(translated_page.test_urlfield, "http://test-content.fr/foo")
コード例 #10
0
    def test_richtextfield(self):
        page = make_test_page(test_richtextfield=RICH_TEXT_TEST_INPUT)
        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                segment.wrap("test_richtextfield")
                for segment in RICH_TEXT_TEST_FRENCH_SEGMENTS
            ],
        )

        self.assertEqual(translated_page.test_richtextfield, RICH_TEXT_TEST_OUTPUT)
コード例 #11
0
    def test_snippet(self):
        test_snippet = TestSnippet.objects.create(field="Test content")
        translated_snippet = test_snippet.copy_for_translation(self.locale)
        translated_snippet.save()

        # Ingest segments into the snippet
        ingest_segments(
            test_snippet,
            translated_snippet,
            self.src_locale,
            self.locale,
            [StringSegmentValue("field", "Tester le contenu")],
        )

        translated_snippet.save()

        self.assertEqual(translated_snippet.field, "Tester le contenu")

        # Now ingest a RelatedObjectSegmentValue into the page
        page = make_test_page(test_snippet=test_snippet)
        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                RelatedObjectSegmentValue.from_instance(
                    "test_snippet", test_snippet)
            ],
        )

        # Check the translated snippet was linked to the translated page
        self.assertNotEqual(page.test_snippet_id,
                            translated_page.test_snippet_id)
        self.assertEqual(page.test_snippet.locale, self.src_locale)
        self.assertEqual(translated_page.test_snippet.locale, self.locale)
        self.assertEqual(
            page.test_snippet.translation_key,
            translated_page.test_snippet.translation_key,
        )

        self.assertEqual(translated_page.test_snippet.field,
                         "Tester le contenu")
コード例 #12
0
    def test_customstructblock(self):
        block_id = uuid.uuid4()
        page = make_test_page_with_streamfield_block(
            str(block_id),
            "test_customstructblock",
            {
                "field_a": "Test content",
                "field_b": "Some more test content"
            },
        )

        translated_page = page.copy_for_translation(self.locale)

        ingest_segments(
            page,
            translated_page,
            self.src_locale,
            self.locale,
            [
                StringSegmentValue(
                    f"test_streamfield.{block_id}.foo",
                    "Tester le contenu / Encore du contenu de test",
                )
            ],
        )

        translated_page.save()
        translated_page.refresh_from_db()

        self.assertEqual(
            translated_page.test_streamfield.stream_data,
            [{
                "id": str(block_id),
                "type": "test_customstructblock",
                "value": {
                    "field_a": "Tester le contenu",
                    "field_b": "Encore du contenu de test",
                },
            }],
        )