Skip to content
Snippets Groups Projects
Commit 3f83191c authored by borzechof99's avatar borzechof99 :whale2:
Browse files

Add Testing for Modeltranslation

parent 3179fcbd
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ import tempfile
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.management import call_command
from django.utils.translation import get_language, activate
from django.test import TestCase, override_settings
from django.conf import settings
from .models import (
......@@ -276,3 +277,105 @@ class SeedingTest(TestCase):
self.assertEqual(Question.objects.count(), n_criteria)
self.assertEqual(CallToMove.objects.count(), 3)
self.assertEqual(KnowledgeSnack.objects.count(), 3)
class ModeltranslationFallbackTest(TestCase):
"""
Tests Behaviour of Modeltranslation when no translation is given
Also tests Default Language
"""
def setUp(self):
"""
Creates a Question and fills the german Translation
"""
self.criterion = Criterion(name="test")
self.question = Question(text="", criterion=self.criterion)
self.criterion.save()
self.question.save()
def test_default_language(self):
"""
Checks whether the Default Language is German
"""
cur_language = get_language()
self.assertEqual(cur_language, "de")
def test_vallback_value(self):
"""
Checks whether if no Translation is set, the Fallbackvalue is used
"""
self.assertEqual(self.question.text, ("No Translation for this Field",))
class Modeltranslation_One_Language_Test(TestCase):
"""
Tests Behaviour when only one language is defined
"""
def setUp(self):
"""
Creates a Question and fills the german Translation
"""
self.criterion = Criterion(name="test")
self.question = Question(text="", criterion=self.criterion)
self.question.text = "de_text"
self.criterion.save()
self.question.save()
def test_german_translation(self):
"""
Check whether obj.text returns the German Translation
"""
self.assertEqual(self.question.text, "de_text")
def test_fallback_value_translations(self):
"""
English Translation is not filled out, check whether german text is returned
"""
activate("en")
self.assertNotEqual(self.question.text, self.question.text_en)
self.assertEqual(self.question.text, self.question.text_de)
class Modeltranslation_Two_Languages_Test(TestCase):
"""
Tests Behaviour when two languages are defined
"""
def setUp(self):
"""
Creates a Question and fills both the german and english Translations
"""
self.criterion = Criterion(name="test")
self.question = Question(text="", criterion=self.criterion)
activate("de")
self.question.text = "de_text"
activate("en")
self.question.text = "en_text"
activate("de")
self.criterion.save()
self.question.save()
def test_german_translation(self):
"""
Tests whether German Translation is returned
"""
activate("de")
self.assertEqual(self.question.text, self.question.text_de)
self.assertNotEqual(self.question.text, self.question.text_en)
def test_english_translation(self):
"""
Tests whether English Translation is returned
"""
activate("en")
self.assertEqual(self.question.text, self.question.text_en)
self.assertNotEqual(self.question.text, self.question.text_de)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment