Commit cbedc73e authored by Jérome Perrin's avatar Jérome Perrin

Localizer,tests: fix translationContext that was working only in test

Test setup monkey-patched some function which we removed when merging
Zope4 support. This function was used in translationContext, it was
working fine in the tests, because the function was here thanks to the
monkey-patch, but it failed with ImportError when used for real.

This fixes the import to use the real getRequest and drop the patch to
prevent similar problems.
parent 4c608567
Pipeline #27175 failed with stage
in 0 seconds
......@@ -180,11 +180,6 @@ assertEquals("This is 1€.", context.Base_translateString("This is 1€."))
self.assertEqual("This is 1€.",
self.portal.Base_translateString("This is 1€."))
def test_get_request(self):
# check that Localizer's get_request hack works as expected
from Products.Localizer.utils import get_request
self.assertEqual(get_request(), self.portal.REQUEST)
def test_default_not_changed(self):
"""
When there is no translation available for a given message, the default
......
......@@ -85,16 +85,6 @@ config.product_config['deadlockdebugger'] = {'dump_url':'/manage_debug_threads'}
from Testing.ZopeTestCase.layer import onsetup
try:
# Workaround Localizer >= 1.2 patch that doesn't work with
# ZopeTestCase REQUESTs
from Products.Localizer import patches, utils
# revert monkey patches from Localizer
patches.get_request = get_request
utils.get_request = get_request
except ImportError:
pass
from Products.ERP5Type.tests.ProcessingNodeTestCase import \
ProcessingNodeTestCase, patchActivityTool
onsetup(patchActivityTool)()
......
......@@ -27,6 +27,7 @@ from OFS.Folder import Folder
from zLOG import LOG, ERROR, INFO, PROBLEM
from zope.interface import implementer
from zope.i18n import translate
from zope.globalrequest import getRequest
from ZPublisher.BeforeTraverse import registerBeforeTraverse, \
unregisterBeforeTraverse, queryBeforeTraverse, NameCaller
......@@ -258,9 +259,7 @@ class Localizer(LanguageManager, Folder):
LOG('Localizer', PROBLEM,
'Cannot change language inside a translationContext', error=True)
MARKER = []
from .patches import get_request # late import, as this is patched by
# unit tests
request = get_request() # Localizer always use this request internally
request = getRequest()
old_accept_language = request.get('AcceptLanguage', MARKER)
request.set('AcceptLanguage', ForcedLanguage(lang))
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment