Author: chrisz
Date: Sat Jan 26 06:54:52 2008
New Revision: 4053
URL: http://trac.turbogears.org/changeset/4053
Log:
Merged remaining controller tests from 1.0 to 1.1 branch.
Modified:
branches/1.1/turbogears/identity/tests/test_identity.py
branches/1.1/turbogears/identity/tests/test_visit.py
branches/1.1/turbogears/tests/test_controllers.py
Modified: branches/1.1/turbogears/identity/tests/test_identity.py
==============================================================================
--- branches/1.1/turbogears/identity/tests/test_identity.py (original)
+++ branches/1.1/turbogears/identity/tests/test_identity.py Sat Jan 26
06:54:52 2008
@@ -1,6 +1,8 @@
# coding=UTF-8
import re
import unittest
+import urllib
+import formencode
import cherrypy
import turbogears
from turbogears import testutil, database, identity, config, startup
@@ -113,6 +115,34 @@
return '%s %s' % (user_name, password)
new_user_setup = turbogears.expose()(new_user_setup)
+ _test_encoded_params = ('b=krümel&d.a=klöße1')
+
+ def test_params(self, **kwargs):
+ params = self._test_encoded_params
+ # formencode's variable_decode create a datastructure
+ # but does not "decode" anything
+ to_datastruct = formencode.variabledecode.variable_decode
+
+ 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 unicode objects for all
strings' % (
+ cherrypy.request.params)
+
+ test_params = turbogears.expose()(test_params)
+ test_params = identity.require(identity.not_anonymous())(test_params)
+
class TestIdentity(unittest.TestCase):
Modified: branches/1.1/turbogears/identity/tests/test_visit.py
==============================================================================
--- branches/1.1/turbogears/identity/tests/test_visit.py (original)
+++ branches/1.1/turbogears/identity/tests/test_visit.py Sat Jan 26
06:54:52 2008
@@ -27,6 +27,7 @@
cherrypy.root = VisitRoot()
def tearDown(self):
+ turbogears.startup.stopTurboGears()
turbogears.config.update({'visit.timeout': self._visit_timeout})
turbogears.config.update({'visit.on': self._visit_on})
@@ -37,13 +38,11 @@
# the following command shuts down the visit framework properly
# the test still passes without it, but exceptions are thrown later
# once nose wants to quit.
- turbogears.startup.stopTurboGears()
def test_new_visit(self):
"Test that we can see a new visit on the server."
testutil.create_request("/")
assert turbogears.visit.current().is_new
- turbogears.startup.stopTurboGears()
def test_old_visit(self):
"Test if we can track a visitor over time."
@@ -52,7 +51,6 @@
morsel = cherrypy.response.simple_cookie[self.cookie_name]
testutil.create_request("/", headers=cookie_header(morsel))
assert not turbogears.visit.current().is_new
- turbogears.startup.stopTurboGears()
def test_cookie_expires(self):
"Test if the visit timeout mechanism works."
@@ -66,4 +64,17 @@
'cookie values should not match'
assert turbogears.visit.current().is_new, \
'this should be a new visit, as the cookie has expired'
- turbogears.startup.stopTurboGears()
+
+ def test_cookie_re_sent(self):
+ "Test whether the visit cookie is re-sent with new expiry time."
+ testutil.create_request('/')
+ morsel = cherrypy.response.simple_cookie[self.cookie_name]
+ exp1 = time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT')
+ # sleep one second to ensure that we get a new expiry time.
+ time.sleep(1)
+ headers = {'Cookie': morsel.output(header='')[1:]}
+ testutil.create_request('/', headers=headers)
+ assert self.cookie_name in cherrypy.response.simple_cookie
+ morsel = cherrypy.response.simple_cookie[self.cookie_name]
+ exp2 = time.strptime(morsel['expires'], '%a, %d-%b-%Y %H:%M:%S GMT')
+ assert exp1 < exp2
Modified: branches/1.1/turbogears/tests/test_controllers.py
==============================================================================
--- branches/1.1/turbogears/tests/test_controllers.py (original)
+++ branches/1.1/turbogears/tests/test_controllers.py Sat Jan 26 06:54:52 2008
@@ -221,6 +221,14 @@
"isinstance(tg_exceptions, KeyError)")(raise_all_exc)
raise_all_exc = turbogears.expose()(raise_all_exc)
+ def internal_redirect(self, **kwargs):
+ raise cherrypy.InternalRedirect('/internal_redirect_target')
+ internal_redirect = turbogears.expose()(internal_redirect)
+
+ def internal_redirect_target(self, **kwargs):
+ return "redirected OK"
+ internal_redirect_target = turbogears.expose()(internal_redirect_target)
+
class TestRoot(unittest.TestCase):
def setUp(self):
cherrypy.root = None
@@ -614,7 +622,7 @@
== '/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
def test_list(self):
- """url can handle list parameters, with unicode too"""
+ """url() can handle list parameters, with unicode too"""
testutil.create_request("/")
assert url('/', foo=['bar', u'\N{LATIN SMALL LETTER A WITH GRAVE}']) \
== '/?foo=bar&foo=%C3%A0'
@@ -623,7 +631,6 @@
turbogears.config.update({"server.webpath" : ""})
turbogears.startup.startTurboGears()
-
def test_index_trailing_slash():
"If there is no trailing slash on an index method call, redirect"
cherrypy.root = SubApp()