Ticket #1966: static-data-content-type.patch

File static-data-content-type.patch, 4.6 KB (added by yacc, 15 years ago)
  • twisted/web2/test/test_static.py

    ==== Patch <static-data-content-type> level 2
    Source: e3c0e7b8-6901-0410-b62d-a6081d6f05f7:/branches/twisted-static-data:20564
    Target: bbbe8e31-12d6-0310-92fd-ac37d47ddeeb:/trunk:17716
            (svn://svn.twistedmatrix.com/svn/Twisted)
    Log:
     r20561@andi-lap:  andreas | 2006-07-28 15:39:47 +0200
     Fix content-type bug for static.Data.
     r20562@andi-lap:  andreas | 2006-07-28 17:16:46 +0200
     fixed static.Data Content-Type header
     r20564@andi-lap:  andreas | 2006-07-28 20:43:31 +0200
     refactored unit test
    
    === 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")
     13    def test_data_state(self):
     14        "test the internal state of the Data object"
     15        self.assert_(hasattr(self.data, "created_time"))
     16        self.assertEquals(self.data.data, self.text)
     17        self.assertEquals(self.data.type, http_headers.MimeType("text", "plain"))
     18        self.assertEquals(self.data.contentType(), http_headers.MimeType("text", "plain"))
    1319
    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())
     20    def test_etag(self):
     21        "test that we can get an ETag"
     22        self.failUnless(self.data.etag())
    1823
     24    def test_render(self):
     25        "test that the result from Data.render is acceptable"
     26        response = iweb.IResponse(self.data.render(None))
     27        self.assertEqual(response.code, 200)
     28        self.assert_(response.headers.hasHeader("content-type"))
     29        self.assertEqual(response.headers.getHeader("content-type"),
     30                         http_headers.MimeType("text", "plain"))
    1931        def checkStream(data):
    20             self.assertEquals(str(data), text)
     32            self.assertEquals(str(data), self.text)
    2133
    22         return stream.readStream(iweb.IResponse(data.render(None)).stream, checkStream)
     34        return stream.readStream(iweb.IResponse(self.data.render(None)).stream,
     35                                 checkStream)
    2336
    2437class TestFileSaver(BaseCase):
    2538    def setUpClass(self):
  • twisted/web2/static.py

    === 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(responsecode.OK, http_headers.Headers({'content-type':self.contentType()}), stream=self.data)
    153153
    154154class File(StaticRenderMixin):
    155155    """