Commit 0f8d7f27 authored by Jérome Perrin's avatar Jérome Perrin

hal_json_style: fix double translation of worklist message

There was a regression with 45c03413 (hal_json_style: prevent a
translation of worklist with document count, 2021-05-10), the title
of the worklist was translated twice. This was supposed to be
catched by the test, by checking that the mocked gettext had only
one call for "Draft to Validate", assuming that the translation of
"Draft to Validate" was "Draft to Validate" and that a double
translation would cause this to be translated twice, but because of
a side effect of another test inserting a translation for
"Draft to Validate", this problem was not noticed.

This fixes the double translation and adjust the test to not depend
on the actual content of message catalog.
Co-authored-by: Georgios Dagkakis's avatarGeorgios Dagkakis <georgios.dagkakis@nexedi.com>
parent bb90ac9d
Pipeline #24603 running with stage
...@@ -1546,10 +1546,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1546,10 +1546,11 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
'href': '%s' % view_action['url'], 'href': '%s' % view_action['url'],
'name': view_action['id'], 'name': view_action['id'],
'icon': view_action['icon'], 'icon': view_action['icon'],
'title': Base_translateString( 'title': translateWorklistActionName(
translateWorklistActionName(view_action['title']) view_action['title']
if 'worklist_id' in view_action ) if 'worklist_id' in view_action else Base_translateString(
else view_action['title']), view_action['title']
),
}) })
global_action_type = ("view", "workflow", "object_new_content_action", global_action_type = ("view", "workflow", "object_new_content_action",
......
...@@ -65,6 +65,7 @@ def simulate(script_id, params_string, code_string): ...@@ -65,6 +65,7 @@ def simulate(script_id, params_string, code_string):
try: try:
result = f(self, *args, **kw) result = f(self, *args, **kw)
finally: finally:
transaction.abort()
if script_id in self.portal.portal_skins.custom.objectIds(): if script_id in self.portal.portal_skins.custom.objectIds():
self.portal.portal_skins.custom.manage_delObjects(script_id) self.portal.portal_skins.custom.manage_delObjects(script_id)
transaction.commit() transaction.commit()
...@@ -159,18 +160,12 @@ def replace_request(new_request, context): ...@@ -159,18 +160,12 @@ def replace_request(new_request, context):
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
#####################################################
# Base_getRequestHeader
#####################################################
class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase): class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
self.login() self.login()
wipeFolder(self.portal.foo_module, commit=False) wipeFolder(self.portal.foo_module, commit=False)
def beforeTearDown(self):
transaction.abort()
def generateNewId(self): def generateNewId(self):
return "%sö" % self.portal.portal_ids.generateNewId( return "%sö" % self.portal.portal_ids.generateNewId(
id_group=('erp5_hal_json_style_test')) id_group=('erp5_hal_json_style_test'))
...@@ -184,6 +179,13 @@ class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase): ...@@ -184,6 +179,13 @@ class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase):
) )
return foo return foo
<<<<<<< HEAD
=======
#####################################################
# Base_getRequestHeader
#####################################################
>>>>>>> 4ba1c39f16 (hal_json_style: adjust transaction interactions in the test)
class TestBase_getRequestHeader(ERP5HALJSONStyleSkinsMixin): class TestBase_getRequestHeader(ERP5HALJSONStyleSkinsMixin):
@changeSkin('Hal') @changeSkin('Hal')
def test_getRequestHeader_REQUEST_disallowed(self): def test_getRequestHeader_REQUEST_disallowed(self):
...@@ -2437,8 +2439,9 @@ class TestERP5Person_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin): ...@@ -2437,8 +2439,9 @@ class TestERP5Person_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.tic() self.tic()
def beforeTearDown(self): def beforeTearDown(self):
super(TestERP5Person_getHateoas_mode_search, self).beforeTearDown()
self.portal.person_module.deleteContent(self.person.getId()) self.portal.person_module.deleteContent(self.person.getId())
self.tic()
@simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"') @simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"') @simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"')
...@@ -2942,9 +2945,8 @@ return msg" ...@@ -2942,9 +2945,8 @@ return msg"
# worklists with the actual count of document # worklists with the actual count of document
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
default_gettext = self.portal.Localizer.erp5_ui.gettext
def gettext(message, **kw): def gettext(message, **kw):
return default_gettext(message, **kw) return kw.get('default', message)
with mock.patch.object(self.portal.Localizer.erp5_ui.__class__, 'gettext', side_effect=gettext) as gettext_mock: with mock.patch.object(self.portal.Localizer.erp5_ui.__class__, 'gettext', side_effect=gettext) as gettext_mock:
self.portal.web_site_module.hateoas.ERP5Document_getHateoas( self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
......
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