From 86c2bf83be73e28aa9a9ab9465ad33d8d6d6a5dd Mon Sep 17 00:00:00 2001 From: David Wolever Date: Tue, 21 May 2013 17:06:53 -0400 Subject: [PATCH] Test revealing StaticFileHandler path regression. A bisect suggests that the regression was introduced in 3f04edf5546e388293d8d1d2f015ca74f8a93217 --- tornado/test/web_test.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 89c549c2d..47ce5fb62 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -21,6 +21,7 @@ import sys wsgi_safe_tests = [] +relpath = lambda *a: os.path.join(os.path.dirname(__file__), *a) def wsgi_safe(cls): wsgi_safe_tests.append(cls) @@ -792,8 +793,7 @@ class StaticFileTest(WebTestCase): ('/override_static_url/(.*)', OverrideStaticUrlHandler)] def get_app_kwargs(self): - return dict(static_path=os.path.join(os.path.dirname(__file__), - 'static')) + return dict(static_path=relpath('static')) def test_static_files(self): response = self.fetch('/robots.txt') @@ -860,8 +860,7 @@ class StaticFileTest(WebTestCase): # chosen just before and after the known modification time # of the file to ensure that the right time zone is being used # when parsing If-Modified-Since. - stat = os.stat(os.path.join(os.path.dirname(__file__), - 'static/robots.txt')) + stat = os.stat(relpath('static/robots.txt')) response = self.fetch('/static/robots.txt', headers={ 'If-Modified-Since': format_timestamp(stat.st_mtime - 1)}) @@ -943,8 +942,7 @@ class StaticFileTest(WebTestCase): @wsgi_safe class StaticDefaultFilenameTest(WebTestCase): def get_app_kwargs(self): - return dict(static_path=os.path.join(os.path.dirname(__file__), - 'static'), + return dict(static_path=relpath('static'), static_handler_args=dict(default_filename='index.html')) def get_handlers(self): @@ -961,6 +959,21 @@ class StaticDefaultFilenameTest(WebTestCase): self.assertTrue(response.headers['Location'].endswith('/static/dir/')) +@wsgi_safe +class StaticFileWithPathTest(WebTestCase): + def get_app_kwargs(self): + return dict(static_path=relpath('static'), + static_handler_args=dict(default_filename='index.html')) + + def get_handlers(self): + return [("/foo/(.*)", StaticFileHandler, { + "path": relpath("templates/"), + })] + + def test_serve(self): + response = self.fetch("/foo/utf8.html") + self.assertEqual(response.body, b"H\xc3\xa9llo\n") + @wsgi_safe class CustomStaticFileTest(WebTestCase): -- 2.47.2