Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
slug="home-de",
path="/de/",
static_path=True,
language_code="de",
is_active=True,
menu="main",
translation_of=original,
)
self.assertEqual(set(original.translations()), {original, translation})
self.assertEqual(set(translation.translations()), {original, translation})
self.assertEqual(
[
language["object"]
for language in translations(translation.translations())
],
[original, translation, None],
)
original.delete()
translation.refresh_from_db()
self.assertEqual(set(translation.translations()), set())
def test_translations_filter_edge_cases(self):
self.assertEqual(len(translations(None)), 3)
self.assertEqual(len(translations({})), 3)
t = Template(
"{% load feincms3 %}{% for l in c|translations %}{{ l.code }}{% endfor %}"
)
self.assertEqual(t.render(Context({"c": None})), "endefr")
self.assertEqual(t.render(Context({"c": []})), "endefr")
self.assertEqual(t.render(Context({"c": 1})), "endefr")
def test_translations_filter_edge_cases(self):
self.assertEqual(len(translations(None)), 3)
self.assertEqual(len(translations({})), 3)
t = Template(
"{% load feincms3 %}{% for l in c|translations %}{{ l.code }}{% endfor %}"
)
self.assertEqual(t.render(Context({"c": None})), "endefr")
self.assertEqual(t.render(Context({"c": []})), "endefr")
self.assertEqual(t.render(Context({"c": 1})), "endefr")
)
Page.objects.create(
title="home-de",
slug="home-de",
language_code="de",
is_active=True,
application="translated-articles",
)
original = TranslatedArticle.objects.create(title="News", language_code="en")
translated = TranslatedArticle.objects.create(
title="Neues", language_code="de", translation_of=original
)
self.assertEqual(
[language["object"] for language in translations(original.translations())],
[original, translated, None],
)
with override_urlconf(apps_urlconf()):
self.assertEqual(
original.get_absolute_url(), "/home-en/{}/".format(original.pk)
)
self.assertEqual(
translated.get_absolute_url(), "/home-de/{}/".format(translated.pk)
)