[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form/tests - test_browserwidget.py:1.8
Jim Fulton
jim@zope.com
Tue, 25 Mar 2003 15:39:46 -0500
Update of /cvs-repository/Zope3/src/zope/app/browser/form/tests
In directory cvs.zope.org:/tmp/cvs-serv28335/tests
Modified Files:
test_browserwidget.py
Log Message:
Modified browser widgets to translate labels, which come from field titles
=== Zope3/src/zope/app/browser/form/tests/test_browserwidget.py 1.7 => 1.8 ===
--- Zope3/src/zope/app/browser/form/tests/test_browserwidget.py:1.7 Mon Jan 20 11:23:38 2003
+++ Zope3/src/zope/app/browser/form/tests/test_browserwidget.py Tue Mar 25 15:39:46 2003
@@ -15,21 +15,28 @@
$Id$
"""
-import unittest
+
from zope.app.browser.form.widget import BrowserWidget
-from zope.publisher.browser import TestRequest
-from zope.schema import Text
from zope.app.interfaces.form import ConversionError
from zope.app.interfaces.form import WidgetInputError, MissingInputError
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.i18n.gettextmessagecatalog import GettextMessageCatalog
+from zope.i18n.globaltranslationservice import translationService
+from zope.publisher.browser import TestRequest
+from zope.schema import Text
+import os
+import unittest
+import zope.app.browser.form.tests
-class BrowserWidgetTest(unittest.TestCase):
+class BrowserWidgetTest(PlacelessSetup, unittest.TestCase):
_FieldFactory = Text
_WidgetFactory = BrowserWidget
def setUp(self):
- field = self._FieldFactory(__name__ = 'foo', title = u"Foo Title")
- request = TestRequest()
+ PlacelessSetup.setUp(self)
+ field = self._FieldFactory(__name__ = 'foo', title = _(u"Foo Title"))
+ request = TestRequest(HTTP_ACCEPT_LANGUAGE='pl')
request.form['field.foo'] = u'Foo Value'
self._widget = self._WidgetFactory(field, request)
@@ -69,6 +76,16 @@
def testLabel(self):
label = ' '.join(self._widget.label().strip().split())
self.assertEqual(label, '<label for="field.foo">Foo Title</label>')
+
+ def testTranslatedLabel(self):
+ path = os.path.dirname(zope.app.browser.form.tests.__file__)
+ catalog = GettextMessageCatalog(
+ 'pl', 'zope',
+ os.path.join(path, 'testlabeltranslation.mo'))
+ translationService.addCatalog(catalog)
+
+ label = ' '.join(self._widget.label().strip().split())
+ self.assertEqual(label, '<label for="field.foo">oofay itletay</label>')
def testRow(self):
self._widget.request.form.clear()