[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/Browser/tests - testBrowserCharsets.py:1.2
Fred L. Drake, Jr.
fdrake@acm.org
Fri, 14 Jun 2002 11:12:14 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/Browser/tests
In directory cvs.zope.org:/tmp/cvs-serv28814/tests
Modified Files:
testBrowserCharsets.py
Log Message:
Ensure reasonable handling of some cases of "broken" input:
- quality values which are not valid floats are converted to 0
- charset parameters which are not quality values are ignored
If a quality value is 0.0, do not include that charset in the return.
Added tests.
=== Zope3/lib/python/Zope/Publisher/Browser/tests/testBrowserCharsets.py 1.1 => 1.2 ===
self.assertEqual(list(browser_charsets.getPreferredCharsets()),
- ['ISO-8859-1', 'UTF-8', 'UTF-16'])
+ ['iso-8859-1', 'utf-8', 'utf-16'])
+
+ def testGetPreferredCharsetOrdering(self):
+ # test that the charsets are returned sorted according to
+ # their "quality value"
+ request = {'HTTP_ACCEPT_CHARSET':
+ 'ISO-8859-1, UTF-16;Q=0.33, UTF-8;q=0.66'}
+
+ browser_charsets = BrowserCharsets(request)
+
+ self.assertEqual(list(browser_charsets.getPreferredCharsets()),
+ ['iso-8859-1', 'utf-8', 'utf-16'])
+
+ def testGetPreferredCharsetBogusQuality(self):
+ # test that handling of bogus "quality values" and non-quality
+ # parameters is reasonable
+ request = {'HTTP_ACCEPT_CHARSET':
+ 'ISO-8859-1;x, UTF-16;Q=0.33, UTF-8;q=foo'}
+
+ browser_charsets = BrowserCharsets(request)
+
+ self.assertEqual(list(browser_charsets.getPreferredCharsets()),
+ ['iso-8859-1', 'utf-16'])
def test_suite():