From: Ben Darnell Date: Sun, 14 Aug 2011 21:20:09 +0000 (-0700) Subject: Add tests for static file functionality X-Git-Tag: v2.1.0~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c14931142ae832b0f91425c6bdc9021c8ff235a6;p=thirdparty%2Ftornado.git Add tests for static file functionality --- diff --git a/MANIFEST.in b/MANIFEST.in index acbd940d3..dcd3459ff 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,4 +4,5 @@ include tornado/ca-certificates.crt include tornado/test/README include tornado/test/test.crt include tornado/test/test.key +include tornado/test/static/robots.txt global-exclude _auto2to3* \ No newline at end of file diff --git a/setup.py b/setup.py index d9c824e16..d31e379aa 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ distutils.core.setup( packages = ["tornado", "tornado.test", "tornado.platform"], package_data = { "tornado": ["ca-certificates.crt"], - "tornado.test": ["README", "test.crt", "test.key"], + "tornado.test": ["README", "test.crt", "test.key", "static/robots.txt"], }, ext_modules = extensions, author="Facebook", diff --git a/tornado/test/static/robots.txt b/tornado/test/static/robots.txt new file mode 100644 index 000000000..1f53798bb --- /dev/null +++ b/tornado/test/static/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 61e938343..08f4712de 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -7,6 +7,7 @@ from tornado.web import RequestHandler, _O, authenticated, Application, asynchro import binascii import logging +import os import re import socket import sys @@ -511,3 +512,23 @@ class ErrorResponseTest(AsyncHTTPTestCase, LogTrapTestCase): response = self.fetch("/failed_write_error") self.assertEqual(response.code, 500) self.assertEqual(b(""), response.body) + +class StaticFileTest(AsyncHTTPTestCase, LogTrapTestCase): + def get_app(self): + class StaticUrlHandler(RequestHandler): + def get(self, path): + self.write(self.static_url(path)) + + return Application([('/static_url/(.*)', StaticUrlHandler)], + static_path=os.path.join(os.path.dirname(__file__), 'static')) + + def test_static_files(self): + response = self.fetch('/robots.txt') + assert b("Disallow: /") in response.body + + response = self.fetch('/static/robots.txt') + assert b("Disallow: /") in response.body + + def test_static_url(self): + response = self.fetch("/static_url/robots.txt") + self.assertEqual(response.body, b("/static/robots.txt?v=f71d2"))