Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_translate(self, Translator):
page = create_test_page(
title="Test page",
slug="test-page",
test_charfield="Some translatable content",
test_richtextfield="<p>Translatable <b>rich text</b></p>",
)
request_page = self.add_page_to_request(page)
# Mock response from Google Translate
Translator().translate.return_value = [
Translated(
"en",
"fr",
"Some translatable content",
"Certains contenus traduisibles",
"Certains contenus traduisibles",
),
Translated(
"en",
"fr",
"Translatable rich text",
"Texte riche traduisible",
"Texte riche traduisible",
),
]
response = self.client.post(
def test_translate_without_publishing(self, Translator):
page = create_test_page(
title="Test page",
slug="test-page",
test_charfield="Some translatable content",
)
request_page = self.add_page_to_request(page)
# Mock response from Google Translate
Translator().translate.return_value = [
Translated(
"en",
"fr",
"Some translatable content",
"Certains contenus traduisibles",
"Certains contenus traduisibles",
)
]
response = self.client.post(
reverse(
"wagtail_localize_google_translate:translate",
args=[self.translation_request.id],
)
)
self.assertRedirects(
slug="test-page",
test_charfield="Some translatable content",
test_richtextfield="<p>Translatable <b>rich text</b></p>",
)
request_page = self.add_page_to_request(page)
# Mock response from Google Translate
Translator().translate.return_value = [
Translated(
"en",
"fr",
"Some translatable content",
"Certains contenus traduisibles",
"Certains contenus traduisibles",
),
Translated(
"en",
"fr",
"Translatable rich text",
"Texte riche traduisible",
"Texte riche traduisible",
),
]
response = self.client.post(
reverse(
"wagtail_localize_google_translate:translate",
args=[self.translation_request.id],
),
{"publish": "on"},
)
def test_translate_with_nested_snippet(self, Translator):
snippet = TestSnippet.objects.create(field="Some test snippet content")
page = create_test_page(
title="Test page", slug="test-page", test_snippet=snippet
)
request_page = self.add_page_to_request(page)
# Mock response from Google Translate
Translator().translate.return_value = [
Translated(
"en",
"fr",
"Some test snippet content",
"Du contenu d'extrait de test",
"Du contenu d'extrait de test",
)
]
response = self.client.post(
reverse(
"wagtail_localize_google_translate:translate",
args=[self.translation_request.id],
),
{"publish": "on"},
)
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str): # pragma: nocover
origin = origin.decode('utf-8')
if dest in EXCLUDES and pron == origin:
pron = translated
# for python 2.x compatbillity
if not PY3: # pragma: nocover
if isinstance(src, str):
src = src.decode('utf-8')
if isinstance(dest, str):
dest = dest.decode('utf-8')
if isinstance(translated, str):
translated = translated.decode('utf-8')
# put final values into a new Translated object
result = Translated(src=src, dest=dest, origin=origin,
text=translated, pronunciation=pron, extra_data=extra_data)
return result
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str): # pragma: nocover
origin = origin.decode('utf-8')
if dest in EXCLUDES and pron == origin:
pron = translated
# for python 2.x compatbillity
if not PY3: # pragma: nocover
if isinstance(src, str):
src = src.decode('utf-8')
if isinstance(dest, str):
dest = dest.decode('utf-8')
if isinstance(translated, str):
translated = translated.decode('utf-8')
# put final values into a new Translated object
result = Translated(src=src, dest=dest, origin=origin,
text=translated, pronunciation=pron)
return result
if not PY3 and isinstance(pron, unicode) and isinstance(origin, str): # pragma: nocover
origin = origin.decode('utf-8')
if dest in EXCLUDES and pron == origin:
pron = translated
# for python 2.x compatbillity
if not PY3: # pragma: nocover
if isinstance(src, str):
src = src.decode('utf-8')
if isinstance(dest, str):
dest = dest.decode('utf-8')
if isinstance(translated, str):
translated = translated.decode('utf-8')
# put final values into a new Translated object
result = Translated(src=src, dest=dest, origin=origin,
text=translated, pronunciation=pron, extra_data=extra_data)
return result