Commit 4a575f3e authored by Jérome Perrin's avatar Jérome Perrin

core_test: more Localizer tests

and adjust the test for better python3 compatibility
parent e0e773c4
Pipeline #27240 failed with stage
in 0 seconds
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
import unittest import unittest
import six
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Persistence import PersistentMapping from Persistence import PersistentMapping
...@@ -50,12 +52,12 @@ class TestLocalizer(ERP5TypeTestCase): ...@@ -50,12 +52,12 @@ class TestLocalizer(ERP5TypeTestCase):
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"This is 1€.") "This is 1€.")
# newly created key should be unicode. # newly created key should be unicode.
self.assertNotIn('This is 1€.', self.message_catalog._messages) self.assertNotIn(u'This is 1€.'.encode('utf-8'), self.message_catalog._messages)
self.assertIn(u'This is 1€.', self.message_catalog._messages) self.assertIn(u'This is 1€.', self.message_catalog._messages)
self.message_catalog.message_edit(u'This is 1€.', 'fr', u"C'est 1€.", '') self.message_catalog.message_edit(u'This is 1€.', 'fr', u"C'est 1€.", '')
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"C'est 1€.") "C'est 1€.")
self.assertNotIn('This is 1€.', self.message_catalog._messages) self.assertNotIn(u'This is 1€.'.encode('utf-8'), self.message_catalog._messages)
self.assertIn(u'This is 1€.', self.message_catalog._messages) self.assertIn(u'This is 1€.', self.message_catalog._messages)
def test_migrated_non_ascii_msgid(self): def test_migrated_non_ascii_msgid(self):
...@@ -66,22 +68,36 @@ class TestLocalizer(ERP5TypeTestCase): ...@@ -66,22 +68,36 @@ class TestLocalizer(ERP5TypeTestCase):
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"C'est 1€.") "C'est 1€.")
# translate() should not create a unicode key if str key already exists. # translate() should not create a unicode key if str key already exists.
self.assertIn('This is 1€.', self.message_catalog._messages) self.assertIn(u'This is 1€.'.encode('utf-8'), self.message_catalog._messages)
self.assertNotIn(u'This is 1€.', self.message_catalog._messages) self.assertNotIn(u'This is 1€.', self.message_catalog._messages)
self.message_catalog.message_edit(u'This is 1€.', 'fr', u"Ceci est 1€.", '') self.message_catalog.message_edit(u'This is 1€.', 'fr', u"Ceci est 1€.", '')
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"Ceci est 1€.") "Ceci est 1€.")
# message_edit() should not create a unicode key if str key already exists. # message_edit() should not create a unicode key if str key already exists.
self.assertIn('This is 1€.', self.message_catalog._messages) self.assertIn(u'This is 1€.'.encode('utf-8'), self.message_catalog._messages)
self.assertNotIn(u'This is 1€.', self.message_catalog._messages) self.assertNotIn(u'This is 1€.', self.message_catalog._messages)
def test_non_ascii_mapping(self): def test_non_ascii_mapping(self):
self.assertEqual(self.portal.Base_translateString('This is 1${currency}.', lang='fr', self.assertEqual(self.portal.Base_translateString('This is 1${currency}.', lang='fr',
mapping={'currency':'€'}), mapping={'currency': '€'}),
"This is 1€.")
if six.PY2:
self.assertEqual(
self.portal.Base_translateString(
'This is 1${currency}.',
lang='fr',
mapping={'currency': u'€'}),
"This is 1€.") "This is 1€.")
self.message_catalog.message_edit(u'This is 1${currency}.', 'fr', u"C'est 1${currency}.", '') self.message_catalog.message_edit(u'This is 1${currency}.', 'fr', u"C'est 1${currency}.", '')
self.assertEqual(self.portal.Base_translateString('This is 1${currency}.', lang='fr', self.assertEqual(self.portal.Base_translateString('This is 1${currency}.', lang='fr',
mapping={'currency':'€'}), mapping={'currency': '€'}),
"C'est 1€.")
if six.PY2:
self.assertEqual(
self.portal.Base_translateString(
'This is 1${currency}.',
lang='fr',
mapping={'currency': u'€'}),
"C'est 1€.") "C'est 1€.")
def test_non_literal_mapping(self): def test_non_literal_mapping(self):
...@@ -104,7 +120,7 @@ class TestLocalizer(ERP5TypeTestCase): ...@@ -104,7 +120,7 @@ class TestLocalizer(ERP5TypeTestCase):
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"Ceci est 1€.") "Ceci est 1€.")
# po_import() converts existing str key to unicode key. # po_import() converts existing str key to unicode key.
self.assertNotIn('This is 1€.', self.message_catalog._messages) self.assertNotIn(u'This is 1€.'.encode('utf-8'), self.message_catalog._messages)
self.assertIn(u'This is 1€.', self.message_catalog._messages) self.assertIn(u'This is 1€.', self.message_catalog._messages)
def test_localizer_transle_in_activity(self): def test_localizer_transle_in_activity(self):
......
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