diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-03 03:28:29 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2010-01-03 03:28:29 (GMT) |
commit | b4066374db45af2927eb5cde68f9b030eaec1b96 (patch) | |
tree | 1c09a2cc471c099ab2e1cbd8d4d29d30a38b3276 /Lib/test/test_httplib.py | |
parent | 91ae4a1404fabc236a835cd5dd058f7e6b32062b (diff) | |
download | cpython-b4066374db45af2927eb5cde68f9b030eaec1b96.zip cpython-b4066374db45af2927eb5cde68f9b030eaec1b96.tar.gz cpython-b4066374db45af2927eb5cde68f9b030eaec1b96.tar.bz2 |
Merged revisions 77263-77264 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77263 | gregory.p.smith | 2010-01-02 17:29:44 -0800 (Sat, 02 Jan 2010) | 4 lines
Adds an optional source_address parameter to socket.create_connection().
For use by issue3972.
........
r77264 | gregory.p.smith | 2010-01-02 18:06:07 -0800 (Sat, 02 Jan 2010) | 5 lines
issue3972: HTTPConnection and HTTPSConnection now support a
source_address parameter.
Also cleans up an annotation in the socket documentation.
........
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 37cda5d..705ceec 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -4,7 +4,8 @@ import io import array import socket -from unittest import TestCase +import unittest +TestCase = unittest.TestCase from test import support @@ -263,6 +264,38 @@ class OfflineTest(TestCase): def test_responses(self): self.assertEquals(client.responses[client.NOT_FOUND], "Not Found") + +class SourceAddressTest(TestCase): + def setUp(self): + self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.port = support.bind_port(self.serv) + self.source_port = support.find_unused_port() + self.serv.listen(5) + self.conn = None + + def tearDown(self): + if self.conn: + self.conn.close() + self.conn = None + self.serv.close() + self.serv = None + + def testHTTPConnectionSourceAddress(self): + self.conn = client.HTTPConnection(HOST, self.port, + source_address=('', self.source_port)) + self.conn.connect() + self.assertEqual(self.conn.sock.getsockname()[1], self.source_port) + + @unittest.skipIf(not hasattr(client, 'HTTPSConnection'), + 'http.client.HTTPSConnection not defined') + def testHTTPSConnectionSourceAddress(self): + self.conn = client.HTTPSConnection(HOST, self.port, + source_address=('', self.source_port)) + # We don't test anything here other the constructor not barfing as + # this code doesn't deal with setting up an active running SSL server + # for an ssl_wrapped connect() to actually return from. + + class TimeoutTest(TestCase): PORT = None @@ -390,7 +423,7 @@ class RequestBodyTest(TestCase): def test_main(verbose=None): support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, - HTTPSTimeoutTest, RequestBodyTest) + HTTPSTimeoutTest, RequestBodyTest, SourceAddressTest) if __name__ == '__main__': test_main() |