Changeset 3817

Show
Ignore:
Timestamp:
12/13/07 05:22:53 (1 year ago)
Author:
chrisz
Message:

Better fix for #1622 (Identity and nested params).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/identity/tests/test_identity.py

    r3807 r3817  
    22import re 
    33import unittest 
     4import urllib 
     5import formencode 
    46import cherrypy 
    57import turbogears 
     
    114116    new_user_setup = turbogears.expose()(new_user_setup) 
    115117 
     118    _test_params = ('a=quark&b=krümel&c-0=sülze1&c-1=sülze2' 
     119        '&d.a=klöße1&d.b-0=klöße2&d.b-1=klöße3' 
     120        '&e-0=käse1&e-1.a=käse2&e-2.b-0=käse3&e-2.b-1=käse4') 
     121 
     122    def test_params(self, **kwargs): 
     123        params = self._test_params 
     124        decode = formencode.variabledecode.variable_decode 
     125        params = decode(dict([p.split('=') for p in params.split('&')])) 
     126        if params == cherrypy.request.params: 
     127            return 'params ok' 
     128        else: 
     129            return 'wrong params: %s\nexpected: %s' % ( 
     130                params, cherrypy.request.params) 
     131    test_params = turbogears.expose()(test_params) 
     132    test_params = identity.require(identity.not_anonymous())(test_params) 
    116133 
    117134class TestIdentity(unittest.TestCase): 
     
    444461        """Test that the decode filter doesn't break with nested 
    445462        variables and Identity""" 
    446         testutil.create_request('/in_admin_group?a.b=1&a.c=2') 
    447         firstline = cherrypy.response.body[0] 
    448         assert 'identity_failed_answer' in firstline, firstline 
    449  
    450     def test_decode_filter2(self): 
    451         """Test that the decode filter doesn't break with list 
    452         variables and Identity""" 
    453         testutil.create_request('/in_admin_group?a=1&a=2') 
    454         firstline = cherrypy.response.body[0] 
    455         assert 'identity_failed_answer' in firstline, firstline 
     463        testutil.create_request('/test_params?user_name=samIam&password=secret&login=Login&' 
     464            + urllib.quote(IdentityRoot._test_params.decode('utf-8').encode('latin-1'), '=&')) 
     465        firstline = cherrypy.response.body[0] 
     466        assert 'params ok' in firstline, firstline 
    456467 
    457468class TestTGUser(testutil.DBTest): 
  • branches/1.0/turbogears/tests/test_controllers.py

    r3771 r3817  
    225225        raise cherrypy.InternalRedirect('/internal_redirect_target') 
    226226    internal_redirect = turbogears.expose()(internal_redirect) 
    227      
     227 
    228228    def internal_redirect_target(self, **kwargs): 
    229229        return "redirected OK" 
     
    491491        #assert "AssertionError" not in outputcap.getvalue() 
    492492 
    493     def test_internal_redirect(self):  
     493    def test_internal_redirect(self): 
    494494        ''' 
    495495        test to make sure we don't have regressions on tickets: #1598, #1407 
    496496        and #1022 
    497497        ''' 
    498         testutil.createRequest("/internal_redirect")  
    499         firstline = cherrypy.response.body[0]  
    500         assert "redirected OK" in firstline  
    501          
    502     def test_internal_redirect_nested_variables(self):  
     498        testutil.createRequest("/internal_redirect") 
     499        firstline = cherrypy.response.body[0] 
     500        assert "redirected OK" in firstline 
     501 
     502    def test_internal_redirect_nested_variables(self): 
    503503        ''' 
    504504        test to make sure we don't have regressions on tickets: #1598, #1407 
    505505        and #1022 
    506506        ''' 
    507         testutil.createRequest("/internal_redirect?a.b=1&a.c=2")  
    508         firstline = cherrypy.response.body[0]  
    509         print firstline  
     507        testutil.createRequest("/internal_redirect?a=1&a-1.b=2&a-2.c=3&a-2.c-1=4") 
     508        firstline = cherrypy.response.body[0] 
     509        print firstline 
    510510        assert "redirected OK" in firstline 
    511511 
  • branches/1.0/turbogears/visit/api.py

    r3807 r3817  
    175175        an existing visit. 
    176176        ''' 
    177         def encode_utf8(params): 
     177        def encode_utf8(value): 
    178178            ''' 
    179             will recursively encode to utf-8 all values in a dictionnary 
     179            will recursively encode all values in a dictionary to utf-8 
    180180            ''' 
    181             res = dict() 
    182             for k, v in params.items(): 
    183                 if isinstance(v, dict): 
    184                     res[k] = encode_utf8(v) 
    185                 elif isinstance(v, list): 
    186                     res[k] = [vv.encode('utf-8') for vv in v] 
    187                 else: 
    188                     res[k] = v.encode('utf-8') 
    189  
    190             return res 
     181            if isinstance(value, dict): 
     182                for k, v in value.items(): 
     183                    value[k] = encode_utf8(v) 
     184            elif isinstance(value, list): 
     185                return map(encode_utf8, value) 
     186            else: 
     187                try: 
     188                    return value.encode('utf-8') 
     189                except AttributeError: 
     190                    pass 
     191            return value 
    191192 
    192193        if not turbogears.config.get("visit.on", True): 
     
    222223            cherrypy.request.object_path = e.path 
    223224 
    224         cherrypy.request.params = encode_utf8(cherrypy.request.params) 
     225        encode_utf8(cherrypy.request.params) 
    225226 
    226227    def _generate_key(self):