Ticket #1966: static-data.patch

File static-data.patch, 2.8 KB (added by Jean-Paul Calderone, 15 years ago)

minor changes, mostly reformatting

  • twisted/web2/test/test_static.py

     
    77from twisted.web2 import iweb
    88
    99class TestData(BaseCase):
    10     def test_data(self):
    11         text = "Hello, World\n"
    12         data = static.Data(text, "text/plain")
     10    def setUp(self):
     11        self.text = "Hello, World\n"
     12        self.data = static.Data(self.text, "text/plain")
    1313
    14         self.assertEquals(data.data, text)
    15         self.assertEquals(data.type, http_headers.MimeType("text", "plain"))
    16         self.assertEquals(data.contentType(), http_headers.MimeType("text", "plain"))
    17         self.failUnless(data.etag())
    1814
     15    def test_data_state(self):
     16        """
     17        Test the internal state of the Data object
     18        """
     19        self.assert_(hasattr(self.data, "created_time"))
     20        self.assertEquals(self.data.data, self.text)
     21        self.assertEquals(self.data.type, http_headers.MimeType("text", "plain"))
     22        self.assertEquals(self.data.contentType(), http_headers.MimeType("text", "plain"))
     23
     24
     25    def test_etag(self):
     26        """
     27        Test that we can get an ETag
     28        """
     29        self.failUnless(self.data.etag())
     30
     31
     32    def test_render(self):
     33        """
     34        Test that the result from Data.render is acceptable, including the
     35        response code, the content-type header, and the actual response body
     36        itself.
     37        """
     38        response = iweb.IResponse(self.data.render(None))
     39        self.assertEqual(response.code, 200)
     40        self.assert_(response.headers.hasHeader("content-type"))
     41        self.assertEqual(response.headers.getHeader("content-type"),
     42                         http_headers.MimeType("text", "plain"))
    1943        def checkStream(data):
    20             self.assertEquals(str(data), text)
     44            self.assertEquals(str(data), self.text)
    2145
    22         return stream.readStream(iweb.IResponse(data.render(None)).stream, checkStream)
     46        return stream.readStream(iweb.IResponse(self.data.render(None)).stream,
     47                                 checkStream)
    2348
     49
     50
    2451class TestFileSaver(BaseCase):
    2552    def setUpClass(self):
    2653        self.tempdir = self.mktemp()
  • twisted/web2/static.py

     
    149149        return self.type
    150150
    151151    def render(self, req):
    152         return http.Response(responsecode.OK, stream=self.data)
     152        return http.Response(
     153            responsecode.OK,
     154            http_headers.Headers({'content-type': self.contentType()}),
     155            stream=self.data)
    153156
     157
    154158class File(StaticRenderMixin):
    155159    """
    156160    File is a resource that represents a plain non-interpreted file