def test_finalize_headers(self):
    headers = []
    message = Message('1 2 / 22:{"VERSION":"HTTP/1.0"},0:,')
    start_response = StartResponse(message, self.wsgid)
    write_fn = start_response("200 OK", headers)        
    start_response._finalize_headers()
    headers = start_response.headers[:]
    expected_headers = [('X-Wsgid', __version__), ('Date', ANY)]
    self.assertEquals(headers, expected_headers)
    self.assertEquals(start_response.chunked, False)
    self.assertEquals(start_response.should_close, True)

    headers = []
    headers_str = '{"VERSION":"HTTP/1.0","te":"chunked"}'
    message = Message('1 2 / %d:%s,0:,' %(len(headers_str),headers_str))
    start_response = StartResponse(message, self.wsgid)
    write_fn = start_response("200 OK", headers)        
    start_response._finalize_headers()
    headers = start_response.headers[:]
    expected_headers = [('X-Wsgid', __version__),('Date', ANY), ('Transfer-Encoding','chunked')]
    self.assertEquals(headers, expected_headers)
    self.assertEquals(start_response.chunked, True)
    self.assertEquals(start_response.should_close, True)

    headers = []
    message = Message('1 2 / 22:{"VERSION":"HTTP/1.1"},0:,')
    start_response = StartResponse(message, self.wsgid)
    write_fn = start_response("200 OK", headers)        
    start_response._finalize_headers()
    headers = start_response.headers[:]
    expected_headers = [('X-Wsgid', __version__),('Date', ANY), ('Transfer-Encoding','chunked')]
    self.assertEquals(headers, expected_headers)
    self.assertEquals(start_response.chunked, True)
    self.assertEquals(start_response.should_close, False)

    headers = [('content-length','42')]
    message = Message('1 2 / 22:{"VERSION":"HTTP/1.1"},0:,')
    start_response = StartResponse(message, self.wsgid)
    write_fn = start_response("200 OK", headers)        
    start_response._finalize_headers()
    headers = start_response.headers[:]
    expected_headers = [('content-length','42'), ('X-Wsgid', __version__), ('Date', ANY)]
    self.assertEquals(headers, expected_headers)
    self.assertEquals(start_response.chunked, False)
    self.assertEquals(start_response.should_close, False)
dataset/ETHPy150Open daltonmatos/wsgid/tests/unit/startresponse_test.py/StartResponseTest.test_finalize_headers/original