Author: chrisz
Date: Wed Jan 19 10:08:35 2011
New Revision: 7213
URL: http://trac.turbogears.org/changeset/7213

Log:
Added a unit test revealing a bug in CP 3.2.0rc1,
so we can check if it is fixed in CP 3.2 final.

Modified:
   branches/1.5/turbogears/tests/test_controllers.py
   branches/1.5/turbogears/tests/test_errorhandling.py

Modified: branches/1.5/turbogears/tests/test_controllers.py
==============================================================================
--- branches/1.5/turbogears/tests/test_controllers.py   Wed Jan 19 08:19:48 
2011        (r7212)
+++ branches/1.5/turbogears/tests/test_controllers.py   Wed Jan 19 10:08:35 
2011        (r7213)
@@ -112,6 +112,11 @@
         return self.istrue(str(value))
 
     @expose()
+    @validate(validators={'value': validators.ForEach(validators.Int())})
+    def valuelist(self, value):
+        return ','.join(map(str, value))
+
+    @expose()
     @validate(validators={'value': validators.StringBoolean()})
     @error_handler(istrue)
     def errorchain(self, value):
@@ -290,6 +295,7 @@
 
 
 class TestRoot(testutil.TGTest):
+
     stop_tg_only = True
 
     def setUp(self):
@@ -480,6 +486,48 @@
         response = self.app.get('/nestedcall?value=false')
         assert response.body == 'False', response.body
 
+    def test_validation_list_get(self):
+        """Multiple values can be passed as list with the get method."""
+        response = self.app.get('/valuelist?value=')
+        assert response.body == ''
+        response = self.app.get('/valuelist?value=42')
+        assert response.body == '42'
+        response = self.app.get('/valuelist?value=4&value=2')
+        assert response.body == '4,2', "values not properly passed as list"
+
+    def test_validation_list_post(self):
+        """Multiple values can be passed as list with the post method."""
+        response = self.app.post('/valuelist',
+            'value=',
+            {'Content-Type': 'application/x-www-form-urlencoded'})
+        assert response.body == ''
+        response = self.app.post('/valuelist',
+            'value=42',
+            {'Content-Type': 'application/x-www-form-urlencoded'})
+        assert response.body == '42'
+        response = self.app.post('/valuelist',
+            'value=4&value=2',
+            {'Content-Type': 'application/x-www-form-urlencoded'})
+        assert response.body == '4,2', "values not properly passed as list"
+        response = self.app.post('/valuelist',
+            '--AaB03x\r\nContent-Disposition: form-data;'
+            ' name="value"\r\n\r\n\r\n--AaB03x--',
+            {'Content-Type': 'multipart/form-data; boundary=AaB03x'})
+        assert response.body == ''
+        response = self.app.post('/valuelist',
+            '--AaB03x\r\nContent-Disposition: form-data;'
+            ' name="value"\r\n\r\n42\r\n--AaB03x--',
+            {'Content-Type': 'multipart/form-data; boundary=AaB03x'})
+        assert response.body == '42'
+        response = self.app.post('/valuelist',
+            '--AaB03x\r\nContent-Disposition: form-data;'
+            ' name="value"\r\n\r\n4\r\n'
+            '--AaB03x\r\nContent-Disposition: form-data;'
+            ' name="value"\r\n\r\n2\r\n--AaB03x--',
+            {'Content-Type': 'multipart/form-data; boundary=AaB03x'})
+        # this fails in CherryPy 3.2.0rc1 because of a bug in _cprequest
+        assert response.body == '4,2', "values not properly passed as list"
+
     def test_validation_with_schema(self):
         """Data can be converted/validated with formencode.Schema instance"""
         response = 
self.app.get('/save2?submit=send&firstname=Joe&lastname=Doe')

Modified: branches/1.5/turbogears/tests/test_errorhandling.py
==============================================================================
--- branches/1.5/turbogears/tests/test_errorhandling.py Wed Jan 19 08:19:48 
2011        (r7212)
+++ branches/1.5/turbogears/tests/test_errorhandling.py Wed Jan 19 10:08:35 
2011        (r7213)
@@ -1,6 +1,6 @@
 import unittest
-from turbogears.controllers import error_handler, exception_handler, \
-                                   expose, validate, RootController, Controller
+from turbogears.controllers import (error_handler, exception_handler,
+    expose, validate, RootController, Controller)
 from turbogears.errorhandling import FailsafeSchema
 from turbogears.util import bind_args
 from turbogears import validators

Reply via email to