Changeset 3979

Show
Ignore:
Timestamp:
01/20/08 07:59:42 (6 months ago)
Author:
faide
Message:

Make the decoding filter be active even when visit filter is not active.
Changed the tests to make them work and really validate that our param arrive as unicode objects.

Files:

Legend:

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

    r3974 r3979  
    116116    new_user_setup = turbogears.expose()(new_user_setup) 
    117117 
    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') 
     118    _test_encoded_params = ('b=krümel&d.a=klöße1') 
    121119 
    122120    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  
    127         if params == cherrypy.request.params: 
     121        params = self._test_encoded_params 
     122        # formencode's variable_decode create a datastructure 
     123        #  but does not "decode" anything 
     124        to_datastruct = formencode.variabledecode.variable_decode 
     125 
     126        expected_params = to_datastruct(dict([p.split('=') for p in params.split('&')])) 
     127 
     128        params_ok = True 
     129 
     130        if not expected_params['b'].decode('utf8') == cherrypy.request.params['b']:  
     131            params_ok = False 
     132 
     133        if not expected_params['d']['a'].decode('utf8') == cherrypy.request.params['d']['a']: 
     134            params_ok = False 
     135 
     136        if params_ok: 
    128137            return 'params ok' 
     138 
    129139        else: 
    130             return 'wrong params: %s\nexpected: %s' % ( 
    131                 params, cherrypy.request.params) 
     140            return 'wrong params: %s\nexpected unicode objects for all strings' % ( 
     141                cherrypy.request.params) 
    132142 
    133143    test_params = turbogears.expose()(test_params) 
     
    464474        """Test that the decode filter doesn't break with nested\ 
    465475        variables and Identity""" 
    466         params = urllib.quote(IdentityRoot._test_params.decode('utf-8').encode('latin-1'), '=&') 
     476        params = urllib.quote(IdentityRoot._test_encoded_params.decode('utf-8').encode('latin-1'), '=&') 
    467477        testutil.create_request('/test_params?' + params) 
    468478        firstline = cherrypy.response.body[0] 
     
    472482        """Test that the decode filter doesn't break with nested\ 
    473483        variables and Identity""" 
    474         params = urllib.quote(IdentityRoot._test_params.decode('utf-8').encode('latin-1'), '=&') 
     484        params = urllib.quote(IdentityRoot._test_encoded_params.decode('utf-8').encode('latin-1'), '=&') 
    475485        params += '&user_name=samIam&password=secret&login=Login' 
    476486        testutil.create_request('/test_params?' + params) 
  • branches/1.0/turbogears/visit/api.py

    r3974 r3979  
    118118# Interface for the TurboGears extension 
    119119def start_extension(): 
     120    # TODO: this should alway be active even when visit is not on, 
     121    # we should find a better place to load this code... 
     122    # Monkey patch CP Decoding filter 
     123    from cherrypy.filters import decodingfilter 
     124    # TODO: is there a better way to inject this ? Maybe earlier than start_extension 
     125    # monkey inject our replacement filter into the CP2 filter chain 
     126    df = MonkeyDecodingFilter() 
     127    for index, active_filter in enumerate( 
     128            cherrypy.filters._filterhooks.get('before_main', [])): 
     129 
     130        if active_filter.im_class == \ 
     131                cherrypy.filters.decodingfilter.DecodingFilter: 
     132 
     133            cherrypy.filters._filterhooks['before_main'].pop(index) 
     134            cherrypy.filters._filterhooks['before_main'].insert( 
     135                    index, df.before_main) 
     136 
     137    # Here is the real visit code. 
    120138    # Bail out if the application hasn't enabled this extension 
    121139    if not turbogears.config.get("visit.on", False): 
     
    125143    if _manager: 
    126144        return 
    127  
    128     # Monkey patch CP Decoding filter 
    129     from cherrypy.filters import decodingfilter 
    130     # TODO: is there a better way to inject this ? Maybe earlier than start_extension 
    131     # monkey inject our replacement filter into the CP2 filter chain 
    132     df = MonkeyDecodingFilter() 
    133     for index, active_filter in enumerate( 
    134             cherrypy.filters._filterhooks.get('before_main', [])): 
    135  
    136         if active_filter.im_class == \ 
    137                 cherrypy.filters.decodingfilter.DecodingFilter: 
    138  
    139             cherrypy.filters._filterhooks['before_main'].pop(index) 
    140             cherrypy.filters._filterhooks['before_main'].insert( 
    141                     index, df.before_main) 
    142145 
    143146    log.info("Visit Tracking starting")