Skip to content

Commit

Permalink
Add a unit test for tornado.web.RedirectHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
leekchan committed Sep 23, 2014
1 parent 4ad3e1e commit df4ba9b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tornado/test/web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from tornado.testing import AsyncHTTPTestCase, ExpectLog, gen_test
from tornado.test.util import unittest
from tornado.util import u, ObjectDict, unicode_type, timedelta_to_seconds
from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature_v1, create_signed_value, decode_signed_value, ErrorHandler, UIModule, MissingArgumentError, stream_request_body, Finish, removeslash, addslash
from tornado.web import RequestHandler, authenticated, Application, asynchronous, url, HTTPError, StaticFileHandler, _create_signature_v1, create_signed_value, decode_signed_value, ErrorHandler, UIModule, MissingArgumentError, stream_request_body, Finish, removeslash, addslash, RedirectHandler as WebRedirectHandler

import binascii
import contextlib
Expand Down Expand Up @@ -577,6 +577,8 @@ def get_handlers(self):
url("/optional_path/(.+)?", OptionalPathHandler),
url("/multi_header", MultiHeaderHandler),
url("/redirect", RedirectHandler),
url("/web_redirect_permanent", WebRedirectHandler, {"url": "/web_redirect_newpath"}),
url("/web_redirect", WebRedirectHandler, {"url": "/web_redirect_newpath", "permanent": False}),
url("/header_injection", HeaderInjectionHandler),
url("/get_argument", GetArgumentHandler),
url("/get_arguments", GetArgumentsHandler),
Expand Down Expand Up @@ -702,6 +704,14 @@ def test_redirect(self):
response = self.fetch("/redirect?status=307", follow_redirects=False)
self.assertEqual(response.code, 307)

def test_web_redirect(self):
response = self.fetch("/web_redirect_permanent", follow_redirects=False)
self.assertEqual(response.code, 301)
self.assertEqual(response.headers['Location'], '/web_redirect_newpath')
response = self.fetch("/web_redirect", follow_redirects=False)
self.assertEqual(response.code, 302)
self.assertEqual(response.headers['Location'], '/web_redirect_newpath')

def test_header_injection(self):
response = self.fetch("/header_injection")
self.assertEqual(response.body, b"ok")
Expand Down

0 comments on commit df4ba9b

Please sign in to comment.