Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
swp-unisport
team-warumkeinrust
Backend
Commits
3f83191c
Commit
3f83191c
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Add Testing for Modeltranslation
parent
3179fcbd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
unisportomat/quiz/tests.py
+103
-0
103 additions, 0 deletions
unisportomat/quiz/tests.py
with
103 additions
and
0 deletions
unisportomat/quiz/tests.py
+
103
−
0
View file @
3f83191c
...
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment