From: Ben Darnell Date: Wed, 25 Aug 2010 18:36:44 +0000 (-0700) Subject: Move AuthRedirectTest from httpserver_test to web_test where it belongs X-Git-Tag: v1.1.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1580728fe85d2b42ca54c88b876a452192f8abee;p=thirdparty%2Ftornado.git Move AuthRedirectTest from httpserver_test to web_test where it belongs --- diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index ac7e5f5c8..cf797093a 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from tornado.testing import AsyncHTTPTestCase, LogTrapTestCase -from tornado.web import authenticated, Application, RequestHandler +from tornado.web import Application, RequestHandler import os import pycurl import re @@ -12,41 +12,6 @@ class HelloWorldRequestHandler(RequestHandler): def get(self): self.finish("Hello world") -class AuthRedirectRequestHandler(RequestHandler): - def initialize(self, login_url): - self.login_url = login_url - - def get_login_url(self): - return self.login_url - - @authenticated - def get(self): - # we'll never actually get here because the test doesn't follow redirects - self.send_error(500) - -class AuthRedirectTest(AsyncHTTPTestCase, LogTrapTestCase): - def get_app(self): - return Application([('/relative', AuthRedirectRequestHandler, - dict(login_url='/login')), - ('/absolute', AuthRedirectRequestHandler, - dict(login_url='http://example.com/login'))]) - - def test_relative_auth_redirect(self): - self.http_client.fetch(self.get_url('/relative'), self.stop, - follow_redirects=False) - response = self.wait() - self.assertEqual(response.code, 302) - self.assertEqual(response.headers['Location'], '/login?next=%2Frelative') - - def test_absolute_auth_redirect(self): - self.http_client.fetch(self.get_url('/absolute'), self.stop, - follow_redirects=False) - response = self.wait() - self.assertEqual(response.code, 302) - self.assertTrue(re.match( - 'http://example.com/login\?next=http%3A%2F%2Flocalhost%3A[0-9]+%2Fabsolute', - response.headers['Location']), response.headers['Location']) - class SSLTest(AsyncHTTPTestCase, LogTrapTestCase): def get_app(self): return Application([('/', HelloWorldRequestHandler)]) diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index a21c9ad7f..7f4a975d0 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -1,5 +1,5 @@ -from tornado.testing import LogTrapTestCase -from tornado.web import RequestHandler, _O +from tornado.testing import LogTrapTestCase, AsyncHTTPTestCase +from tornado.web import RequestHandler, _O, authenticated, Application import logging import re @@ -43,3 +43,39 @@ class SecureCookieTest(LogTrapTestCase): handler._cookies['foo'] = '1234|5678%s|%s' % (timestamp, sig) # it gets rejected assert handler.get_secure_cookie('foo') is None + + +class AuthRedirectRequestHandler(RequestHandler): + def initialize(self, login_url): + self.login_url = login_url + + def get_login_url(self): + return self.login_url + + @authenticated + def get(self): + # we'll never actually get here because the test doesn't follow redirects + self.send_error(500) + +class AuthRedirectTest(AsyncHTTPTestCase, LogTrapTestCase): + def get_app(self): + return Application([('/relative', AuthRedirectRequestHandler, + dict(login_url='/login')), + ('/absolute', AuthRedirectRequestHandler, + dict(login_url='http://example.com/login'))]) + + def test_relative_auth_redirect(self): + self.http_client.fetch(self.get_url('/relative'), self.stop, + follow_redirects=False) + response = self.wait() + self.assertEqual(response.code, 302) + self.assertEqual(response.headers['Location'], '/login?next=%2Frelative') + + def test_absolute_auth_redirect(self): + self.http_client.fetch(self.get_url('/absolute'), self.stop, + follow_redirects=False) + response = self.wait() + self.assertEqual(response.code, 302) + self.assertTrue(re.match( + 'http://example.com/login\?next=http%3A%2F%2Flocalhost%3A[0-9]+%2Fabsolute', + response.headers['Location']), response.headers['Location'])