]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
test Content-Type for static compressed files
authorAli Ebrahim <aebrahim@ucsd.edu>
Thu, 30 Jul 2015 20:12:56 +0000 (13:12 -0700)
committerAli Ebrahim <aebrahim@ucsd.edu>
Thu, 30 Jul 2015 20:12:56 +0000 (13:12 -0700)
MANIFEST.in
setup.py
tornado/test/static/sample.xml [new file with mode: 0644]
tornado/test/static/sample.xml.bz2 [new file with mode: 0644]
tornado/test/static/sample.xml.gz [new file with mode: 0644]
tornado/test/web_test.py

index 353f222faaa8bd227cfd475ae4a1336cd05803c1..30cdcd082bd5c23aab3fb7fe2ac51135aab8e2c0 100644 (file)
@@ -8,6 +8,9 @@ include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.mo
 include tornado/test/gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po
 include tornado/test/options_test.cfg
 include tornado/test/static/robots.txt
+include tornado/test/static/sample.xml
+include tornado/test/static/sample.xml.gz
+include tornado/test/static/sample.xml.bz2
 include tornado/test/static/dir/index.html
 include tornado/test/static_foo.txt
 include tornado/test/templates/utf8.html
index 576317588c48d4a6db36fb9907e613de1a69203b..49e436ec3bf13027fb8a26af5990649174907c49 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -146,6 +146,9 @@ setup(
             "gettext_translations/fr_FR/LC_MESSAGES/tornado_test.po",
             "options_test.cfg",
             "static/robots.txt",
+            "static/sample.xml",
+            "static/sample.xml.gz",
+            "static/sample.xml.bz2",
             "static/dir/index.html",
             "static_foo.txt",
             "templates/utf8.html",
diff --git a/tornado/test/static/sample.xml b/tornado/test/static/sample.xml
new file mode 100644 (file)
index 0000000..35ea0e2
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<data>
+    <country name="Liechtenstein">
+        <rank>1</rank>
+        <year>2008</year>
+        <gdppc>141100</gdppc>
+        <neighbor name="Austria" direction="E"/>
+        <neighbor name="Switzerland" direction="W"/>
+    </country>
+    <country name="Singapore">
+        <rank>4</rank>
+        <year>2011</year>
+        <gdppc>59900</gdppc>
+        <neighbor name="Malaysia" direction="N"/>
+    </country>
+    <country name="Panama">
+        <rank>68</rank>
+        <year>2011</year>
+        <gdppc>13600</gdppc>
+        <neighbor name="Costa Rica" direction="W"/>
+        <neighbor name="Colombia" direction="E"/>
+    </country>
+</data>
diff --git a/tornado/test/static/sample.xml.bz2 b/tornado/test/static/sample.xml.bz2
new file mode 100644 (file)
index 0000000..44dc663
Binary files /dev/null and b/tornado/test/static/sample.xml.bz2 differ
diff --git a/tornado/test/static/sample.xml.gz b/tornado/test/static/sample.xml.gz
new file mode 100644 (file)
index 0000000..c0fd5e6
Binary files /dev/null and b/tornado/test/static/sample.xml.gz differ
index 5d8a207187d2b53398db57cc9d6f2d955a8449e0..85c7552c9ebfe8950a55893e067cf9043c83bdf8 100644 (file)
@@ -978,6 +978,19 @@ class StaticFileTest(WebTestCase):
 
         response = self.fetch('/static/robots.txt')
         self.assertTrue(b"Disallow: /" in response.body)
+        self.assertEqual(response.headers.get("Content-Type"), "text/plain")
+
+    def test_static_compressed_files(self):
+        response = self.fetch("/static/sample.xml.gz")
+        self.assertEqual(response.headers.get("Content-Type"),
+                         "application/gzip")
+        response = self.fetch("/static/sample.xml.bz2")
+        self.assertEqual(response.headers.get("Content-Type"),
+                         "application/octet-stream")
+        # make sure the uncompressed file still has the correct type
+        response = self.fetch("/static/sample.xml")
+        self.assertTrue(response.headers.get("Content-Type")
+                        in set(("text/xml", "application/xml")))
 
     def test_static_url(self):
         response = self.fetch("/static_url/robots.txt")