Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
cf80c96f
Commit
cf80c96f
authored
Jun 24, 2015
by
Sarina Canelake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add i18n roundtrip regression tests for language pref and dark lang
Tests would have caught issues raised in LOC-87
parent
91a7df88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
lms/djangoapps/courseware/tests/test_i18n.py
+99
-0
No files found.
lms/djangoapps/courseware/tests/test_i18n.py
View file @
cf80c96f
...
...
@@ -4,10 +4,16 @@ Tests i18n in courseware
import
re
from
nose.plugins.attrib
import
attr
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.core.urlresolvers
import
reverse
,
NoReverseMatch
from
django.test
import
TestCase
from
django.test.client
import
Client
from
dark_lang.models
import
DarkLangConfig
from
lang_pref
import
LANGUAGE_KEY
from
openedx.core.djangoapps.user_api.preferences.api
import
set_user_preference
from
student.tests.factories
import
UserFactory
,
RegistrationFactory
,
UserProfileFactory
class
BaseI18nTestCase
(
TestCase
):
...
...
@@ -91,3 +97,96 @@ class I18nRegressionTests(BaseI18nTestCase):
# receive files for 'fa'
response
=
self
.
client
.
get
(
'/'
,
HTTP_ACCEPT_LANGUAGE
=
'fa-ir'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
"fa"
)
# Now try to access with dark lang
response
=
self
.
client
.
get
(
'/?preview-lang=fa-ir'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
"fa-ir"
)
def
test_preview_lang
(
self
):
# Regression test; LOC-87
self
.
release_languages
(
'es-419'
)
site_lang
=
settings
.
LANGUAGE_CODE
# Visit the front page; verify we see site default lang
response
=
self
.
client
.
get
(
'/'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
site_lang
)
# Verify we can switch language using the preview-lang query param
response
=
self
.
client
.
get
(
'/?preview-lang=eo'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
"eo"
)
# We should be able to see released languages using preview-lang, too
response
=
self
.
client
.
get
(
'/?preview-lang=es-419'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
"es-419"
)
# Clearing the language should go back to site default
response
=
self
.
client
.
get
(
'/?clear-lang'
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
site_lang
)
@attr
(
'shard_1'
)
class
I18nLangPrefTests
(
BaseI18nTestCase
):
"""
Regression tests of language presented to the user, when they
choose a language preference, and when they have a preference
and use the dark lang preview functionality.
"""
def
setUp
(
self
):
super
(
I18nLangPrefTests
,
self
)
.
setUp
()
# Create one user and save it to the database
email
=
'test@edx.org'
pwd
=
'test_password'
self
.
user
=
UserFactory
.
build
(
username
=
'test'
,
email
=
email
)
self
.
user
.
set_password
(
pwd
)
self
.
user
.
save
()
# Create a registration for the user
RegistrationFactory
(
user
=
self
.
user
)
# Create a profile for the user
UserProfileFactory
(
user
=
self
.
user
)
# Create the test client
self
.
client
=
Client
()
# Get the login url & log in our user
try
:
login_url
=
reverse
(
'login_post'
)
except
NoReverseMatch
:
login_url
=
reverse
(
'login'
)
self
.
client
.
post
(
login_url
,
{
'email'
:
email
,
'password'
:
pwd
})
# Url and site lang vars for tests to use
self
.
url
=
reverse
(
'dashboard'
)
self
.
site_lang
=
settings
.
LANGUAGE_CODE
def
test_lang_preference
(
self
):
# Regression test; LOC-87
self
.
release_languages
(
'ar, es-419'
)
# Visit the front page; verify we see site default lang
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
self
.
site_lang
)
# Set user language preference
set_user_preference
(
self
.
user
,
LANGUAGE_KEY
,
'ar'
)
# and verify we now get an ar response
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
'ar'
)
# Verify that switching language preference gives the right language
set_user_preference
(
self
.
user
,
LANGUAGE_KEY
,
'es-419'
)
response
=
self
.
client
.
get
(
self
.
url
)
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
'es-419'
)
def
test_preview_precedence
(
self
):
# Regression test; LOC-87
self
.
release_languages
(
'ar, es-419'
)
# Set user language preference
set_user_preference
(
self
.
user
,
LANGUAGE_KEY
,
'ar'
)
# Verify preview-lang takes precedence
response
=
self
.
client
.
get
(
'{}?preview-lang=eo'
.
format
(
self
.
url
))
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
'eo'
)
# Clearing language must set language back to preference language
response
=
self
.
client
.
get
(
'{}?clear-lang'
.
format
(
self
.
url
))
self
.
assert_tag_has_attr
(
response
.
content
,
"html"
,
"lang"
,
'ar'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment