[Zope3-checkins] CVS: Zope3/src/zope/publisher/tests -
test_browserlanguages.py:1.4
Sidnei da Silva
sidnei at x3ng.com.br
Fri Feb 27 12:50:28 EST 2004
Update of /cvs-repository/Zope3/src/zope/publisher/tests
In directory cvs.zope.org:/tmp/cvs-serv1557/tests
Modified Files:
test_browserlanguages.py
Log Message:
Merge language quality handling implementation
=== Zope3/src/zope/publisher/tests/test_browserlanguages.py 1.3 => 1.4 ===
--- Zope3/src/zope/publisher/tests/test_browserlanguages.py:1.3 Fri Apr 11 08:55:41 2003
+++ Zope3/src/zope/publisher/tests/test_browserlanguages.py Fri Feb 27 12:50:27 2004
@@ -13,26 +13,32 @@
##############################################################################
import unittest
-class Test(unittest.TestCase):
-
- def test(self):
- request = {'HTTP_ACCEPT_LANGUAGE': 'da, en-gb;q=0.8, en;q=0.7'}
-
- from zope.publisher.browser import BrowserLanguages
-
- browser_languages = BrowserLanguages(request)
-
- self.assertEqual(list(browser_languages.getPreferredLanguages()),
- ['da', 'en-gb', 'en'])
-
- # XXX Add support for quality statements
+# Note: The expected output is in order of preference,
+# empty 'q=' means 'q=1', and if theres more than one
+# empty, we assume they are in order of preference.
+data = [
+ ('da, en, pt', ['da', 'en', 'pt']),
+ ('da, en;q=.9, en-gb;q=1.0, en-us', ['da', 'en-gb', 'en-us', 'en']),
+ ('pt_BR; q=0.6, pt_PT; q = .7, en-gb', ['en-gb', 'pt-pt', 'pt-br']),
+ ('en-us, en_GB;q=0.9, en, pt_BR; q=1.0', ['en-us', 'en', 'pt-br', 'en-gb']),
+ ('ro,en-us;q=0.8,es;q=0.5,fr;q=0.3', ['ro', 'en-us', 'es', 'fr']),
+ ('ro,en-us;q=0,es;q=0.5,fr;q=0,ru;q=1,it', ['ro', 'ru', 'it', 'es'])
+ ]
+class BrowserLanguagesTest(unittest.TestCase):
+ def test_browser_language_handling(self):
+ from zope.publisher.browser import BrowserLanguages
+ for req, expected in data:
+ request = {'HTTP_ACCEPT_LANGUAGE': req}
+ browser_languages = BrowserLanguages(request)
+ self.assertEqual(list(browser_languages.getPreferredLanguages()),
+ expected)
def test_suite():
loader=unittest.TestLoader()
- return loader.loadTestsFromTestCase(Test)
+ return loader.loadTestsFromTestCase(BrowserLanguagesTest)
if __name__=='__main__':
unittest.TextTestRunner().run(test_suite())
More information about the Zope3-Checkins
mailing list