summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorSenthil Kumaran <orsenthil@gmail.com>2010-08-02 11:04:58 (GMT)
committerSenthil Kumaran <orsenthil@gmail.com>2010-08-02 11:04:58 (GMT)
commit9f8dc4441fa1f053a150abedd3dfb99f671a75b9 (patch)
treebbc3cb0a9887513a3f916107b1becdcbb1cef895 /Lib/test/test_httplib.py
parentaed05eb6b84456f8a97382f65a2d38779249b4a2 (diff)
downloadcpython-9f8dc4441fa1f053a150abedd3dfb99f671a75b9.zip
cpython-9f8dc4441fa1f053a150abedd3dfb99f671a75b9.tar.gz
cpython-9f8dc4441fa1f053a150abedd3dfb99f671a75b9.tar.bz2
Fix Issue8572 - httplib getheader() throws error instead of default
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index cf3a402..e9d24ba 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -442,9 +442,46 @@ class RequestBodyTest(TestCase):
self.assertEqual("5", message.get("content-length"))
self.assertEqual(b'body\xc1', f.read())
+
+class HTTPResponseTest(TestCase):
+
+ def setUp(self):
+ body = "HTTP/1.1 200 Ok\r\nMy-Header: first-value\r\nMy-Header: \
+ second-value\r\n\r\nText"
+ sock = FakeSocket(body)
+ self.resp = client.HTTPResponse(sock)
+ self.resp.begin()
+
+ def test_getting_header(self):
+ header = self.resp.getheader('My-Header')
+ self.assertEqual(header, 'first-value, second-value')
+
+ header = self.resp.getheader('My-Header', 'some default')
+ self.assertEqual(header, 'first-value, second-value')
+
+ def test_getting_nonexistent_header_with_string_default(self):
+ header = self.resp.getheader('No-Such-Header', 'default-value')
+ self.assertEqual(header, 'default-value')
+
+ def test_getting_nonexistent_header_with_iterable_default(self):
+ header = self.resp.getheader('No-Such-Header', ['default', 'values'])
+ self.assertEqual(header, 'default, values')
+
+ header = self.resp.getheader('No-Such-Header', ('default', 'values'))
+ self.assertEqual(header, 'default, values')
+
+ def test_getting_nonexistent_header_without_default(self):
+ header = self.resp.getheader('No-Such-Header')
+ self.assertEqual(header, None)
+
+ def test_getting_header_defaultint(self):
+ header = self.resp.getheader('No-Such-Header',default=42)
+ self.assertEqual(header, 42)
+
def test_main(verbose=None):
support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest,
- HTTPSTimeoutTest, RequestBodyTest, SourceAddressTest)
+ HTTPSTimeoutTest, RequestBodyTest, SourceAddressTest,
+ HTTPResponseTest)
if __name__ == '__main__':
test_main()