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_rshift():
value, n = 1000, 3
result = utils.rshift(value, n)
assert result == 125
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"},
)
def test_format_json():
text = '[,,"en",,,,0.96954316,,[["en"],,[0.96954316]]]'
result = utils.legacy_format_json(text)
assert result == [None, None, 'en', None, None, None, 0.96954316, None,
[['en'], None, [0.96954316]]]
def test_format_malformed_json():
text = '[,,"en",,,,0.96954316,,[["en"],,0.96954316]]]'
with raises(ValueError):
utils.legacy_format_json(text)
def acquirer():
return gtoken.TokenAcquirer()
def test_latin_to_english(self):
result = translator.translate('veritas lux mea', src='la', dest='en')
assert result.text == 'The truth is my light'
def test_list_translation(self):
translations = translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'],
src='en', dest='ko')
assert translations[0].text == u'빠른 갈색 여우'
assert translations[1].text == u'이상 점프'
assert translations[2].text == u'게으른 개'