Author: faide
Date: Sun Jan 20 07:59:42 2008
New Revision: 3979
URL: http://trac.turbogears.org/changeset/3979
Log:
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.
Modified:
branches/1.0/turbogears/identity/tests/test_identity.py
branches/1.0/turbogears/visit/api.py
Modified: branches/1.0/turbogears/identity/tests/test_identity.py
==============================================================================
--- branches/1.0/turbogears/identity/tests/test_identity.py (original)
+++ branches/1.0/turbogears/identity/tests/test_identity.py Sun Jan 20
07:59:42 2008
@@ -115,20 +115,30 @@
return '%s %s' % (user_name, password)
new_user_setup = turbogears.expose()(new_user_setup)
- _test_params = ('a=quark&b=krümel&c-0=sülze1&c-1=sülze2'
- '&d.a=klöße1&d.b-0=klöße2&d.b-1=klöße3'
- '&e-0=käse1&e-1.a=käse2&e-2.b-0=käse3&e-2.b-1=käse4')
+ _test_encoded_params = ('b=krümel&d.a=klöße1')
def test_params(self, **kwargs):
- params = self._test_params
- decode = formencode.variabledecode.variable_decode
- params = decode(dict([p.split('=') for p in params.split('&')]))
+ params = self._test_encoded_params
+ # formencode's variable_decode create a datastructure
+ # but does not "decode" anything
+ to_datastruct = formencode.variabledecode.variable_decode
- if params == cherrypy.request.params:
+ expected_params = to_datastruct(dict([p.split('=') for p in
params.split('&')]))
+
+ params_ok = True
+
+ if not expected_params['b'].decode('utf8') ==
cherrypy.request.params['b']:
+ params_ok = False
+
+ if not expected_params['d']['a'].decode('utf8') ==
cherrypy.request.params['d']['a']:
+ params_ok = False
+
+ if params_ok:
return 'params ok'
+
else:
- return 'wrong params: %s\nexpected: %s' % (
- params, cherrypy.request.params)
+ return 'wrong params: %s\nexpected unicode objects for all
strings' % (
+ cherrypy.request.params)
test_params = turbogears.expose()(test_params)
test_params = identity.require(identity.not_anonymous())(test_params)
@@ -463,7 +473,7 @@
def test_decode_filter_whenidfails(self):
"""Test that the decode filter doesn't break with nested\
variables and Identity"""
- params =
urllib.quote(IdentityRoot._test_params.decode('utf-8').encode('latin-1'), '=&')
+ params =
urllib.quote(IdentityRoot._test_encoded_params.decode('utf-8').encode('latin-1'),
'=&')
testutil.create_request('/test_params?' + params)
firstline = cherrypy.response.body[0]
assert 'identity_failed_answer' in firstline, firstline
@@ -471,7 +481,7 @@
def test_decode_filter_whenidworks(self):
"""Test that the decode filter doesn't break with nested\
variables and Identity"""
- params =
urllib.quote(IdentityRoot._test_params.decode('utf-8').encode('latin-1'), '=&')
+ params =
urllib.quote(IdentityRoot._test_encoded_params.decode('utf-8').encode('latin-1'),
'=&')
params += '&user_name=samIam&password=secret&login=Login'
testutil.create_request('/test_params?' + params)
firstline = cherrypy.response.body[0]
Modified: branches/1.0/turbogears/visit/api.py
==============================================================================
--- branches/1.0/turbogears/visit/api.py (original)
+++ branches/1.0/turbogears/visit/api.py Sun Jan 20 07:59:42 2008
@@ -117,14 +117,8 @@
# Interface for the TurboGears extension
def start_extension():
- # Bail out if the application hasn't enabled this extension
- if not turbogears.config.get("visit.on", False):
- return
- # Bail out if this extension is already running
- global _manager
- if _manager:
- return
-
+ # TODO: this should alway be active even when visit is not on,
+ # we should find a better place to load this code...
# Monkey patch CP Decoding filter
from cherrypy.filters import decodingfilter
# TODO: is there a better way to inject this ? Maybe earlier than
start_extension
@@ -140,6 +134,15 @@
cherrypy.filters._filterhooks['before_main'].insert(
index, df.before_main)
+ # Here is the real visit code.
+ # Bail out if the application hasn't enabled this extension
+ if not turbogears.config.get("visit.on", False):
+ return
+ # Bail out if this extension is already running
+ global _manager
+ if _manager:
+ return
+
log.info("Visit Tracking starting")
# How long may the visit be idle before a new visit ID is assigned?
# The default is 20 minutes.