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
1c9a75b4
Commit
1c9a75b4
authored
Apr 04, 2016
by
Nimisha Asthagiri
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12029 from openfun/regisb/fix_broken_french_ugettext_in_tests
Fix broken French i18n in CMS tests
parents
35a235b3
e850ef2d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
cms/djangoapps/contentstore/tests/test_i18n.py
+23
-17
No files found.
cms/djangoapps/contentstore/tests/test_i18n.py
View file @
1c9a75b4
...
...
@@ -82,32 +82,38 @@ class TestModuleI18nService(ModuleStoreTestCase):
Test django translation service works fine.
"""
def
wrap_with_xyz
(
func
):
class
wrap_ugettext_with_xyz
(
object
):
# pylint: disable=invalid-name
"""
A decorator function that just adds 'XYZ ' to the front of all strings
A context manager function that just adds 'XYZ ' to the front
of all strings of the module ugettext function.
"""
def
new_func
(
*
args
,
**
kwargs
):
""" custom function """
output
=
func
(
*
args
,
**
kwargs
)
return
"XYZ "
+
output
return
new_func
old_lang
=
translation
.
get_language
()
def
__init__
(
self
,
module
):
self
.
module
=
module
self
.
old_ugettext
=
module
.
ugettext
def
__enter__
(
self
):
def
new_ugettext
(
*
args
,
**
kwargs
):
""" custom function """
output
=
self
.
old_ugettext
(
*
args
,
**
kwargs
)
return
"XYZ "
+
output
self
.
module
.
ugettext
=
new_ugettext
def
__exit__
(
self
,
_type
,
_value
,
_traceback
):
self
.
module
.
ugettext
=
self
.
old_ugettext
i18n_service
=
self
.
get_module_i18n_service
(
self
.
descriptor
)
# Activate french, so that if the fr files haven't been loaded, they will be loaded now.
translation
.
activate
(
"fr"
)
french_translation
=
translation
.
trans_real
.
_active
.
value
# pylint: disable=protected-access
with
translation
.
override
(
"fr"
):
french_translation
=
translation
.
trans_real
.
_active
.
value
# pylint: disable=protected-access
# wrap the ugettext functions so that 'TEST
' will prefix each translation
french_translation
.
ugettext
=
wrap_with_xyz
(
french_translation
.
ugettext
)
self
.
assertEqual
(
i18n_service
.
ugettext
(
self
.
test_language
),
'XYZ dummy language'
)
# wrap the ugettext functions so that 'XYZ
' will prefix each translation
with
wrap_ugettext_with_xyz
(
french_translation
):
self
.
assertEqual
(
i18n_service
.
ugettext
(
self
.
test_language
),
'XYZ dummy language'
)
# Turn back on our old translations
translation
.
activate
(
old_lang
)
del
old_lang
self
.
assertEqual
(
i18n_service
.
ugettext
(
self
.
test_language
),
'dummy language'
)
# Check that the old ugettext has been put back into place
self
.
assertEqual
(
i18n_service
.
ugettext
(
self
.
test_language
),
'dummy language'
)
@mock.patch
(
'django.utils.translation.ugettext'
,
mock
.
Mock
(
return_value
=
'XYZ-TEST-LANGUAGE'
))
def
test_django_translator_in_use_with_empty_block
(
self
):
...
...
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