diff MoinMoin/request/_tests/test_request.py @ 2892:863060b2cfc5

cleanup http header emission, support list-type headers, add tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 20 Oct 2007 17:51:48 +0200
parents 7d97003c0f9a
children 408b301a5e44
line wrap: on
line diff
--- a/MoinMoin/request/_tests/test_request.py	Fri Oct 19 00:11:23 2007 +0200
+++ b/MoinMoin/request/_tests/test_request.py	Sat Oct 20 17:51:48 2007 +0200
@@ -11,6 +11,8 @@
 
 from MoinMoin import config, wikiutil
 
+from MoinMoin.request import HeadersAlreadySentException
+
 class TestNormalizePagename(object):
 
     def testPageInvalidChars(self):
@@ -107,5 +109,36 @@
         assert self.request.httpDate(0, rfc='850') == 'Thursday, 01-Jan-70 00:00:00 GMT'
 
 
+class TestHTTPHeaders(object):
+    std_headers = ['Status: 200 OK', 'Content-type: text/html; charset=UTF-8', ]
+    
+    def setup_method(self, method):
+        self.request.sent_headers = False
+        
+    def testAutoAddStdHeaders(self):
+        """ test if the usual headers get auto-added if not specified """
+        print self.request.sent_headers
+        assert self.request.emit_http_headers(testing=True) == self.std_headers
+
+    def testHeadersOnlyOnce(self):
+        """ test if trying to call emit_http_headers multiple times raises an exception """
+        print self.request.sent_headers
+        self.request.emit_http_headers(testing=True)
+        py.test.raises(HeadersAlreadySentException, self.request.emit_http_headers, [], {'testing': True})
+
+    def testDuplicateHeadersIgnored(self):
+        """ test if duplicate headers get ignored """
+        print self.request.sent_headers
+        headers_in = self.std_headers + ['Status: 500 Server Error']
+        headers_expected = self.std_headers
+        assert self.request.emit_http_headers(headers_in, testing=True) == headers_expected
+
+    def testListHeaders(self):
+        """ test if header values get merged into a list for headers supporting it """
+        print self.request.sent_headers
+        headers_in = self.std_headers + ['Vary: aaa', 'vary: bbb']
+        headers_expected = self.std_headers + ['Vary: aaa, bbb']
+        assert self.request.emit_http_headers(headers_in, testing=True) == headers_expected
+
 coverage_modules = ['MoinMoin.request']