[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services/translation/tests - __init__.py:1.2 test_translate.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:14:10 -0500


Update of /cvs-repository/Zope3/src/zope/app/browser/services/translation/tests
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/browser/services/translation/tests

Added Files:
	__init__.py test_translate.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/browser/services/translation/tests/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:09 2002
+++ Zope3/src/zope/app/browser/services/translation/tests/__init__.py	Wed Dec 25 09:12:39 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/browser/services/translation/tests/test_translate.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:14:10 2002
+++ Zope3/src/zope/app/browser/services/translation/tests/test_translate.py	Wed Dec 25 09:12:39 2002
@@ -0,0 +1,133 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+import unittest
+from StringIO import StringIO
+
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.component.adapter import provideAdapter
+from zope.component.factory import provideFactory
+
+from zope.app.browser.services.translation.translate \
+     import Translate
+from zope.app.services.translation.translationservice import \
+     TranslationService
+from zope.app.services.translation.messagecatalog import \
+     MessageCatalog
+from zope.interfaces.i18n import IUserPreferredCharsets
+
+from zope.publisher.http import IHTTPRequest
+from zope.publisher.http import HTTPCharsets
+from zope.publisher.browser import BrowserRequest
+
+
+class TranslateTest(unittest.TestCase, PlacelessSetup):
+
+    def setUp(self):
+        PlacelessSetup.setUp(self)
+
+        # Setup the registries
+        provideAdapter(IHTTPRequest, IUserPreferredCharsets, HTTPCharsets)
+        provideFactory('Message Catalog', MessageCatalog)
+
+        service = TranslationService('default')
+
+        en_catalog = MessageCatalog('en', 'default')
+        de_catalog = MessageCatalog('de', 'default')
+
+        en_catalog.setMessage('short_greeting', 'Hello!')
+        de_catalog.setMessage('short_greeting', 'Hallo!')
+
+        en_catalog.setMessage('greeting', 'Hello $name, how are you?')
+        de_catalog.setMessage('greeting', 'Hallo $name, wie geht es Dir?')
+
+        service.setObject('en-default-1', en_catalog)
+        service.setObject('de-default-1', de_catalog)
+
+        self._view = Translate(service, self._getRequest())
+
+
+    def _getRequest(self, **kw):
+        request = BrowserRequest(StringIO(''), StringIO(), kw)
+        request._cookies = {'edit_domains': 'default',
+                            'edit_languages': 'en,de'}
+        request._traversed_names = ['foo', 'bar']
+        return request
+
+
+    def testGetMessages(self):
+        ids = [m[0] for m in self._view.getMessages()]
+        ids.sort()
+        self.assertEqual(ids, ['greeting', 'short_greeting'])
+
+
+    def testGetTranslation(self):
+        self.assertEqual(self._view.getTranslation('default', 'short_greeting',
+                                                   'en'),
+                         'Hello!')
+
+
+    def testGetAllLanguages(self):
+        languages = self._view.getAllLanguages()
+        languages.sort()
+        self.assertEqual(languages, ['de', 'en'])
+
+
+    def testGetAllDomains(self):
+        domains = self._view.getAllDomains()
+        domains.sort()
+        self.assertEqual(domains, ['default'])
+
+
+    def testGetEditLanguages(self):
+        languages = self._view.getEditLanguages()
+        languages.sort()
+        self.assertEqual(languages, ['de', 'en'])
+
+
+    def testGetEditDomains(self):
+        domains = self._view.getEditDomains()
+        domains.sort()
+        self.assertEqual(domains, ['default'])
+
+
+    # def testEditMessages(self):
+    #     pass
+    #
+    # def testDeleteMessages(self):
+    #     pass
+
+    def testAddDeleteLanguage(self):
+        self._view.addLanguage('es')
+        assert 'es' in self._view.getAllLanguages()
+        self._view.deleteLanguages(['es'])
+        assert 'es' not in self._view.getAllLanguages()
+
+
+    def testAddDeleteDomain(self):
+        self._view.addDomain('Zope')
+        assert 'Zope' in self._view.getAllDomains()
+        self._view.deleteDomains(['Zope'])
+        assert 'Zope' not in self._view.getAllDomains()
+
+
+def test_suite():
+    loader = unittest.TestLoader()
+    return loader.loadTestsFromTestCase( TranslateTest )
+
+if __name__=='__main__':
+    unittest.main()