]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add tests for static file functionality
authorBen Darnell <ben@bendarnell.com>
Sun, 14 Aug 2011 21:20:09 +0000 (14:20 -0700)
committerBen Darnell <ben@bendarnell.com>
Sun, 14 Aug 2011 21:20:09 +0000 (14:20 -0700)
MANIFEST.in
setup.py
tornado/test/static/robots.txt [new file with mode: 0644]
tornado/test/web_test.py

index acbd940d39e4910fcc45f646349cfa916d88854f..dcd3459ffac706c0ff54858d77e1c70e5e385cee 100644 (file)
@@ -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
index d9c824e16a478fd0f0f305c0ac18f8438c1bc81c..d31e379aa7554b97f50361451db7e9d4cc5f4a99 100644 (file)
--- 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 (file)
index 0000000..1f53798
--- /dev/null
@@ -0,0 +1,2 @@
+User-agent: *
+Disallow: /
index 61e938343e16db14f8924351c4d0c2ac83e29b87..08f4712de74552728101fbc73174ed22039a8b6f 100644 (file)
@@ -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"))