Antoine Pitrou | 7248178 | 2009-09-29 17:48:18 +0000 | [diff] [blame] | 1 | import array |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 2 | import httplib |
| 3 | import StringIO |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 4 | import socket |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 5 | |
Gregory P. Smith | 9d32521 | 2010-01-03 02:06:07 +0000 | [diff] [blame] | 6 | import unittest |
| 7 | TestCase = unittest.TestCase |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 8 | |
| 9 | from test import test_support |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 10 | |
Trent Nelson | e41b006 | 2008-04-08 23:47:30 +0000 | [diff] [blame] | 11 | HOST = test_support.HOST |
| 12 | |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 13 | class FakeSocket: |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 14 | def __init__(self, text, fileclass=StringIO.StringIO): |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 15 | self.text = text |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 16 | self.fileclass = fileclass |
Martin v. Löwis | 040a927 | 2006-11-12 10:32:47 +0000 | [diff] [blame] | 17 | self.data = '' |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 18 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 19 | def sendall(self, data): |
Antoine Pitrou | 7248178 | 2009-09-29 17:48:18 +0000 | [diff] [blame] | 20 | self.data += ''.join(data) |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 21 | |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 22 | def makefile(self, mode, bufsize=None): |
| 23 | if mode != 'r' and mode != 'rb': |
Neal Norwitz | 28bb572 | 2002-04-01 19:00:50 +0000 | [diff] [blame] | 24 | raise httplib.UnimplementedFileMode() |
Jeremy Hylton | 121d34a | 2003-07-08 12:36:58 +0000 | [diff] [blame] | 25 | return self.fileclass(self.text) |
| 26 | |
| 27 | class NoEOFStringIO(StringIO.StringIO): |
| 28 | """Like StringIO, but raises AssertionError on EOF. |
| 29 | |
| 30 | This is used below to test that httplib doesn't try to read |
| 31 | more from the underlying file than it should. |
| 32 | """ |
| 33 | def read(self, n=-1): |
| 34 | data = StringIO.StringIO.read(self, n) |
| 35 | if data == '': |
| 36 | raise AssertionError('caller tried to read past EOF') |
| 37 | return data |
| 38 | |
| 39 | def readline(self, length=None): |
| 40 | data = StringIO.StringIO.readline(self, length) |
| 41 | if data == '': |
| 42 | raise AssertionError('caller tried to read past EOF') |
| 43 | return data |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 44 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 45 | |
| 46 | class HeaderTests(TestCase): |
| 47 | def test_auto_headers(self): |
| 48 | # Some headers are added automatically, but should not be added by |
| 49 | # .request() if they are explicitly set. |
| 50 | |
| 51 | import httplib |
| 52 | |
| 53 | class HeaderCountingBuffer(list): |
| 54 | def __init__(self): |
| 55 | self.count = {} |
| 56 | def append(self, item): |
| 57 | kv = item.split(':') |
| 58 | if len(kv) > 1: |
| 59 | # item is a 'Key: Value' header string |
| 60 | lcKey = kv[0].lower() |
| 61 | self.count.setdefault(lcKey, 0) |
| 62 | self.count[lcKey] += 1 |
| 63 | list.append(self, item) |
| 64 | |
| 65 | for explicit_header in True, False: |
| 66 | for header in 'Content-length', 'Host', 'Accept-encoding': |
| 67 | conn = httplib.HTTPConnection('example.com') |
| 68 | conn.sock = FakeSocket('blahblahblah') |
| 69 | conn._buffer = HeaderCountingBuffer() |
| 70 | |
| 71 | body = 'spamspamspam' |
| 72 | headers = {} |
| 73 | if explicit_header: |
| 74 | headers[header] = str(len(body)) |
| 75 | conn.request('POST', '/', body, headers) |
| 76 | self.assertEqual(conn._buffer.count[header.lower()], 1) |
| 77 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 78 | class BasicTest(TestCase): |
| 79 | def test_status_lines(self): |
| 80 | # Test HTTP status lines |
Jeremy Hylton | 79fa2b6 | 2001-04-13 14:57:44 +0000 | [diff] [blame] | 81 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 82 | body = "HTTP/1.1 200 Ok\r\n\r\nText" |
| 83 | sock = FakeSocket(body) |
| 84 | resp = httplib.HTTPResponse(sock) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 85 | resp.begin() |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 86 | self.assertEqual(resp.read(), 'Text') |
Facundo Batista | 7066590 | 2007-10-18 03:16:03 +0000 | [diff] [blame] | 87 | self.assertTrue(resp.isclosed()) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 88 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 89 | body = "HTTP/1.1 400.100 Not Ok\r\n\r\nText" |
| 90 | sock = FakeSocket(body) |
| 91 | resp = httplib.HTTPResponse(sock) |
| 92 | self.assertRaises(httplib.BadStatusLine, resp.begin) |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 93 | |
Dirkjan Ochtman | ebc73dc | 2010-02-24 04:49:00 +0000 | [diff] [blame] | 94 | def test_bad_status_repr(self): |
| 95 | exc = httplib.BadStatusLine('') |
| 96 | self.assertEquals(repr(exc), '''BadStatusLine("\'\'",)''') |
| 97 | |
Facundo Batista | 7066590 | 2007-10-18 03:16:03 +0000 | [diff] [blame] | 98 | def test_partial_reads(self): |
| 99 | # if we have a lenght, the system knows when to close itself |
| 100 | # same behaviour than when we read the whole thing with read() |
| 101 | body = "HTTP/1.1 200 Ok\r\nContent-Length: 4\r\n\r\nText" |
| 102 | sock = FakeSocket(body) |
| 103 | resp = httplib.HTTPResponse(sock) |
| 104 | resp.begin() |
| 105 | self.assertEqual(resp.read(2), 'Te') |
| 106 | self.assertFalse(resp.isclosed()) |
| 107 | self.assertEqual(resp.read(2), 'xt') |
| 108 | self.assertTrue(resp.isclosed()) |
| 109 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 110 | def test_host_port(self): |
| 111 | # Check invalid host_port |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 112 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 113 | for hp in ("www.python.org:abc", "www.python.org:"): |
| 114 | self.assertRaises(httplib.InvalidURL, httplib.HTTP, hp) |
| 115 | |
Jeremy Hylton | 21d2e59 | 2008-11-29 00:09:16 +0000 | [diff] [blame] | 116 | for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b", |
| 117 | 8000), |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 118 | ("www.python.org:80", "www.python.org", 80), |
| 119 | ("www.python.org", "www.python.org", 80), |
| 120 | ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)): |
Martin v. Löwis | 74a249e | 2004-09-14 21:45:36 +0000 | [diff] [blame] | 121 | http = httplib.HTTP(hp) |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 122 | c = http._conn |
Jeremy Hylton | 21d2e59 | 2008-11-29 00:09:16 +0000 | [diff] [blame] | 123 | if h != c.host: |
| 124 | self.fail("Host incorrectly parsed: %s != %s" % (h, c.host)) |
| 125 | if p != c.port: |
| 126 | self.fail("Port incorrectly parsed: %s != %s" % (p, c.host)) |
Skip Montanaro | 10e6e0e | 2004-09-14 16:32:02 +0000 | [diff] [blame] | 127 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 128 | def test_response_headers(self): |
| 129 | # test response with multiple message headers with the same field name. |
| 130 | text = ('HTTP/1.1 200 OK\r\n' |
Jeremy Hylton | 21d2e59 | 2008-11-29 00:09:16 +0000 | [diff] [blame] | 131 | 'Set-Cookie: Customer="WILE_E_COYOTE";' |
| 132 | ' Version="1"; Path="/acme"\r\n' |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 133 | 'Set-Cookie: Part_Number="Rocket_Launcher_0001"; Version="1";' |
| 134 | ' Path="/acme"\r\n' |
| 135 | '\r\n' |
| 136 | 'No body\r\n') |
| 137 | hdr = ('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"' |
| 138 | ', ' |
| 139 | 'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"') |
| 140 | s = FakeSocket(text) |
| 141 | r = httplib.HTTPResponse(s) |
| 142 | r.begin() |
| 143 | cookies = r.getheader("Set-Cookie") |
| 144 | if cookies != hdr: |
| 145 | self.fail("multiple headers not combined properly") |
Jeremy Hylton | ba60319 | 2003-01-23 18:02:20 +0000 | [diff] [blame] | 146 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 147 | def test_read_head(self): |
| 148 | # Test that the library doesn't attempt to read any data |
| 149 | # from a HEAD request. (Tickles SF bug #622042.) |
| 150 | sock = FakeSocket( |
| 151 | 'HTTP/1.1 200 OK\r\n' |
| 152 | 'Content-Length: 14432\r\n' |
| 153 | '\r\n', |
| 154 | NoEOFStringIO) |
| 155 | resp = httplib.HTTPResponse(sock, method="HEAD") |
| 156 | resp.begin() |
| 157 | if resp.read() != "": |
| 158 | self.fail("Did not expect response from HEAD request") |
Jeremy Hylton | c1b2cb9 | 2003-05-05 16:13:58 +0000 | [diff] [blame] | 159 | |
Martin v. Löwis | 040a927 | 2006-11-12 10:32:47 +0000 | [diff] [blame] | 160 | def test_send_file(self): |
| 161 | expected = 'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \ |
| 162 | 'Accept-Encoding: identity\r\nContent-Length:' |
| 163 | |
| 164 | body = open(__file__, 'rb') |
| 165 | conn = httplib.HTTPConnection('example.com') |
| 166 | sock = FakeSocket(body) |
| 167 | conn.sock = sock |
| 168 | conn.request('GET', '/foo', body) |
| 169 | self.assertTrue(sock.data.startswith(expected)) |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 170 | |
Antoine Pitrou | 7248178 | 2009-09-29 17:48:18 +0000 | [diff] [blame] | 171 | def test_send(self): |
| 172 | expected = 'this is a test this is only a test' |
| 173 | conn = httplib.HTTPConnection('example.com') |
| 174 | sock = FakeSocket(None) |
| 175 | conn.sock = sock |
| 176 | conn.send(expected) |
| 177 | self.assertEquals(expected, sock.data) |
| 178 | sock.data = '' |
| 179 | conn.send(array.array('c', expected)) |
| 180 | self.assertEquals(expected, sock.data) |
| 181 | sock.data = '' |
| 182 | conn.send(StringIO.StringIO(expected)) |
| 183 | self.assertEquals(expected, sock.data) |
| 184 | |
Georg Brandl | 2363503 | 2008-02-24 00:03:22 +0000 | [diff] [blame] | 185 | def test_chunked(self): |
| 186 | chunked_start = ( |
| 187 | 'HTTP/1.1 200 OK\r\n' |
| 188 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 189 | 'a\r\n' |
| 190 | 'hello worl\r\n' |
| 191 | '1\r\n' |
| 192 | 'd\r\n' |
| 193 | ) |
| 194 | sock = FakeSocket(chunked_start + '0\r\n') |
| 195 | resp = httplib.HTTPResponse(sock, method="GET") |
| 196 | resp.begin() |
| 197 | self.assertEquals(resp.read(), 'hello world') |
| 198 | resp.close() |
| 199 | |
| 200 | for x in ('', 'foo\r\n'): |
| 201 | sock = FakeSocket(chunked_start + x) |
| 202 | resp = httplib.HTTPResponse(sock, method="GET") |
| 203 | resp.begin() |
| 204 | try: |
| 205 | resp.read() |
| 206 | except httplib.IncompleteRead, i: |
| 207 | self.assertEquals(i.partial, 'hello world') |
Benjamin Peterson | 7d49bba | 2009-03-02 22:41:42 +0000 | [diff] [blame] | 208 | self.assertEqual(repr(i),'IncompleteRead(11 bytes read)') |
| 209 | self.assertEqual(str(i),'IncompleteRead(11 bytes read)') |
Georg Brandl | 2363503 | 2008-02-24 00:03:22 +0000 | [diff] [blame] | 210 | else: |
| 211 | self.fail('IncompleteRead expected') |
| 212 | finally: |
| 213 | resp.close() |
| 214 | |
Senthil Kumaran | ed920434 | 2010-04-28 17:20:43 +0000 | [diff] [blame] | 215 | def test_chunked_head(self): |
| 216 | chunked_start = ( |
| 217 | 'HTTP/1.1 200 OK\r\n' |
| 218 | 'Transfer-Encoding: chunked\r\n\r\n' |
| 219 | 'a\r\n' |
| 220 | 'hello world\r\n' |
| 221 | '1\r\n' |
| 222 | 'd\r\n' |
| 223 | ) |
| 224 | sock = FakeSocket(chunked_start + '0\r\n') |
| 225 | resp = httplib.HTTPResponse(sock, method="HEAD") |
| 226 | resp.begin() |
| 227 | self.assertEquals(resp.read(), '') |
| 228 | self.assertEquals(resp.status, 200) |
| 229 | self.assertEquals(resp.reason, 'OK') |
Senthil Kumaran | fb69501 | 2010-06-04 17:17:09 +0000 | [diff] [blame^] | 230 | self.assertTrue(resp.isclosed()) |
Senthil Kumaran | ed920434 | 2010-04-28 17:20:43 +0000 | [diff] [blame] | 231 | |
Georg Brandl | 8c460d5 | 2008-02-24 00:14:24 +0000 | [diff] [blame] | 232 | def test_negative_content_length(self): |
Jeremy Hylton | 21d2e59 | 2008-11-29 00:09:16 +0000 | [diff] [blame] | 233 | sock = FakeSocket('HTTP/1.1 200 OK\r\n' |
| 234 | 'Content-Length: -1\r\n\r\nHello\r\n') |
Georg Brandl | 8c460d5 | 2008-02-24 00:14:24 +0000 | [diff] [blame] | 235 | resp = httplib.HTTPResponse(sock, method="GET") |
| 236 | resp.begin() |
| 237 | self.assertEquals(resp.read(), 'Hello\r\n') |
| 238 | resp.close() |
| 239 | |
Benjamin Peterson | 7d49bba | 2009-03-02 22:41:42 +0000 | [diff] [blame] | 240 | def test_incomplete_read(self): |
| 241 | sock = FakeSocket('HTTP/1.1 200 OK\r\nContent-Length: 10\r\n\r\nHello\r\n') |
| 242 | resp = httplib.HTTPResponse(sock, method="GET") |
| 243 | resp.begin() |
| 244 | try: |
| 245 | resp.read() |
| 246 | except httplib.IncompleteRead as i: |
| 247 | self.assertEquals(i.partial, 'Hello\r\n') |
| 248 | self.assertEqual(repr(i), |
| 249 | "IncompleteRead(7 bytes read, 3 more expected)") |
| 250 | self.assertEqual(str(i), |
| 251 | "IncompleteRead(7 bytes read, 3 more expected)") |
| 252 | else: |
| 253 | self.fail('IncompleteRead expected') |
| 254 | finally: |
| 255 | resp.close() |
| 256 | |
Georg Brandl | 2363503 | 2008-02-24 00:03:22 +0000 | [diff] [blame] | 257 | |
Georg Brandl | 4cbd1e3 | 2006-02-17 22:01:08 +0000 | [diff] [blame] | 258 | class OfflineTest(TestCase): |
| 259 | def test_responses(self): |
| 260 | self.assertEquals(httplib.responses[httplib.NOT_FOUND], "Not Found") |
| 261 | |
Gregory P. Smith | 9d32521 | 2010-01-03 02:06:07 +0000 | [diff] [blame] | 262 | |
| 263 | class SourceAddressTest(TestCase): |
| 264 | def setUp(self): |
| 265 | self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 266 | self.port = test_support.bind_port(self.serv) |
| 267 | self.source_port = test_support.find_unused_port() |
| 268 | self.serv.listen(5) |
| 269 | self.conn = None |
| 270 | |
| 271 | def tearDown(self): |
| 272 | if self.conn: |
| 273 | self.conn.close() |
| 274 | self.conn = None |
| 275 | self.serv.close() |
| 276 | self.serv = None |
| 277 | |
| 278 | def testHTTPConnectionSourceAddress(self): |
| 279 | self.conn = httplib.HTTPConnection(HOST, self.port, |
| 280 | source_address=('', self.source_port)) |
| 281 | self.conn.connect() |
| 282 | self.assertEqual(self.conn.sock.getsockname()[1], self.source_port) |
| 283 | |
| 284 | @unittest.skipIf(not hasattr(httplib, 'HTTPSConnection'), |
| 285 | 'httplib.HTTPSConnection not defined') |
| 286 | def testHTTPSConnectionSourceAddress(self): |
| 287 | self.conn = httplib.HTTPSConnection(HOST, self.port, |
| 288 | source_address=('', self.source_port)) |
| 289 | # We don't test anything here other the constructor not barfing as |
| 290 | # this code doesn't deal with setting up an active running SSL server |
| 291 | # for an ssl_wrapped connect() to actually return from. |
| 292 | |
| 293 | |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 294 | class TimeoutTest(TestCase): |
Trent Nelson | e41b006 | 2008-04-08 23:47:30 +0000 | [diff] [blame] | 295 | PORT = None |
Neal Norwitz | 0d4c06e | 2007-04-25 06:30:05 +0000 | [diff] [blame] | 296 | |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 297 | def setUp(self): |
| 298 | self.serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
Trent Nelson | 6c4a7c6 | 2008-04-09 00:34:53 +0000 | [diff] [blame] | 299 | TimeoutTest.PORT = test_support.bind_port(self.serv) |
Facundo Batista | f196629 | 2007-03-25 03:20:05 +0000 | [diff] [blame] | 300 | self.serv.listen(5) |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 301 | |
| 302 | def tearDown(self): |
| 303 | self.serv.close() |
| 304 | self.serv = None |
| 305 | |
| 306 | def testTimeoutAttribute(self): |
| 307 | '''This will prove that the timeout gets through |
| 308 | HTTPConnection and into the socket. |
| 309 | ''' |
Facundo Batista | 4f1b1ed | 2008-05-29 16:39:26 +0000 | [diff] [blame] | 310 | # default -- use global socket timeout |
Benjamin Peterson | 5c8da86 | 2009-06-30 22:57:08 +0000 | [diff] [blame] | 311 | self.assertTrue(socket.getdefaulttimeout() is None) |
Facundo Batista | 4f1b1ed | 2008-05-29 16:39:26 +0000 | [diff] [blame] | 312 | socket.setdefaulttimeout(30) |
| 313 | try: |
| 314 | httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT) |
| 315 | httpConn.connect() |
| 316 | finally: |
| 317 | socket.setdefaulttimeout(None) |
Facundo Batista | 14553b0 | 2007-03-23 20:23:08 +0000 | [diff] [blame] | 318 | self.assertEqual(httpConn.sock.gettimeout(), 30) |
Facundo Batista | f196629 | 2007-03-25 03:20:05 +0000 | [diff] [blame] | 319 | httpConn.close() |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 320 | |
Facundo Batista | 4f1b1ed | 2008-05-29 16:39:26 +0000 | [diff] [blame] | 321 | # no timeout -- do not use global socket default |
Benjamin Peterson | 5c8da86 | 2009-06-30 22:57:08 +0000 | [diff] [blame] | 322 | self.assertTrue(socket.getdefaulttimeout() is None) |
Facundo Batista | 14553b0 | 2007-03-23 20:23:08 +0000 | [diff] [blame] | 323 | socket.setdefaulttimeout(30) |
| 324 | try: |
Trent Nelson | 6c4a7c6 | 2008-04-09 00:34:53 +0000 | [diff] [blame] | 325 | httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, |
| 326 | timeout=None) |
Facundo Batista | 14553b0 | 2007-03-23 20:23:08 +0000 | [diff] [blame] | 327 | httpConn.connect() |
| 328 | finally: |
Facundo Batista | 4f1b1ed | 2008-05-29 16:39:26 +0000 | [diff] [blame] | 329 | socket.setdefaulttimeout(None) |
| 330 | self.assertEqual(httpConn.sock.gettimeout(), None) |
| 331 | httpConn.close() |
| 332 | |
| 333 | # a value |
| 334 | httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30) |
| 335 | httpConn.connect() |
Facundo Batista | 14553b0 | 2007-03-23 20:23:08 +0000 | [diff] [blame] | 336 | self.assertEqual(httpConn.sock.gettimeout(), 30) |
Facundo Batista | f196629 | 2007-03-25 03:20:05 +0000 | [diff] [blame] | 337 | httpConn.close() |
Facundo Batista | 07c78be | 2007-03-23 18:54:07 +0000 | [diff] [blame] | 338 | |
| 339 | |
Facundo Batista | 70f996b | 2007-05-21 17:32:32 +0000 | [diff] [blame] | 340 | class HTTPSTimeoutTest(TestCase): |
| 341 | # XXX Here should be tests for HTTPS, there isn't any right now! |
| 342 | |
| 343 | def test_attributes(self): |
| 344 | # simple test to check it's storing it |
Thomas Wouters | 628e3bb | 2007-08-30 22:35:31 +0000 | [diff] [blame] | 345 | if hasattr(httplib, 'HTTPSConnection'): |
Trent Nelson | e41b006 | 2008-04-08 23:47:30 +0000 | [diff] [blame] | 346 | h = httplib.HTTPSConnection(HOST, TimeoutTest.PORT, timeout=30) |
Thomas Wouters | 628e3bb | 2007-08-30 22:35:31 +0000 | [diff] [blame] | 347 | self.assertEqual(h.timeout, 30) |
Facundo Batista | 70f996b | 2007-05-21 17:32:32 +0000 | [diff] [blame] | 348 | |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 349 | def test_main(verbose=None): |
Trent Nelson | e41b006 | 2008-04-08 23:47:30 +0000 | [diff] [blame] | 350 | test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, |
Gregory P. Smith | 9d32521 | 2010-01-03 02:06:07 +0000 | [diff] [blame] | 351 | HTTPSTimeoutTest, SourceAddressTest) |
Jeremy Hylton | 2c17825 | 2004-08-07 16:28:14 +0000 | [diff] [blame] | 352 | |
Georg Brandl | 71a2089 | 2006-10-29 20:24:01 +0000 | [diff] [blame] | 353 | if __name__ == '__main__': |
| 354 | test_main() |