Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(860)

Side by Side Diff: python3/httplib2test.py

Issue 6506074: Making httplib2.Http instances pickleable. (Closed)
Patch Set: Adding in missing args and kwargs to ResponseDict. Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« python3/httplib2/__init__.py ('K') | « python3/httplib2/__init__.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python3 1 #!/usr/bin/env python3
2 """ 2 """
3 httplib2test 3 httplib2test
4 4
5 A set of unit tests for httplib2.py. 5 A set of unit tests for httplib2.py.
6 6
7 Requires Python 3.0 or later 7 Requires Python 3.0 or later
8 """ 8 """
9 9
10 __author__ = "Joe Gregorio (joe@bitworking.org)" 10 __author__ = "Joe Gregorio (joe@bitworking.org)"
11 __copyright__ = "Copyright 2006, Joe Gregorio" 11 __copyright__ = "Copyright 2006, Joe Gregorio"
12 __contributors__ = ["Mark Pilgrim"] 12 __contributors__ = ["Mark Pilgrim"]
13 __license__ = "MIT" 13 __license__ = "MIT"
14 __history__ = """ """ 14 __history__ = """ """
15 __version__ = "0.2 ($Rev: 118 $)" 15 __version__ = "0.2 ($Rev: 118 $)"
16 16
17 import base64 17 import base64
18 import http.client 18 import http.client
19 import httplib2 19 import httplib2
20 import io 20 import io
21 import os 21 import os
22 import pickle
22 import socket 23 import socket
23 import ssl 24 import ssl
24 import sys 25 import sys
25 import time 26 import time
26 import unittest 27 import unittest
27 import urllib.parse 28 import urllib.parse
28 29
29 # The test resources base uri 30 # The test resources base uri
30 base = 'http://bitworking.org/projects/httplib2/test/' 31 base = 'http://bitworking.org/projects/httplib2/test/'
31 #base = 'http://localhost/projects/httplib2/test/' 32 #base = 'http://localhost/projects/httplib2/test/'
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1098
1098 def testConnectionClose(self): 1099 def testConnectionClose(self):
1099 uri = "http://www.google.com/" 1100 uri = "http://www.google.com/"
1100 (response, content) = self.http.request(uri, "GET") 1101 (response, content) = self.http.request(uri, "GET")
1101 for c in self.http.connections.values(): 1102 for c in self.http.connections.values():
1102 self.assertNotEqual(None, c.sock) 1103 self.assertNotEqual(None, c.sock)
1103 (response, content) = self.http.request(uri, "GET", headers={"connection ": "close"}) 1104 (response, content) = self.http.request(uri, "GET", headers={"connection ": "close"})
1104 for c in self.http.connections.values(): 1105 for c in self.http.connections.values():
1105 self.assertEqual(None, c.sock) 1106 self.assertEqual(None, c.sock)
1106 1107
1108 def testPickleHttp(self):
1109 pickled_http = pickle.dumps(self.http)
1110 new_http = pickle.loads(pickled_http)
1111
1112 self.assertEqual(sorted(new_http.__dict__.keys()),
1113 sorted(self.http.__dict__.keys()))
1114 for key in new_http.__dict__:
1115 if key in ('certificates', 'credentials'):
1116 self.assertEqual(new_http.__dict__[key].credentials,
1117 self.http.__dict__[key].credentials)
1118 elif key == 'cache':
1119 self.assertEqual(new_http.__dict__[key].cache,
1120 self.http.__dict__[key].cache)
1121 else:
1122 self.assertEqual(new_http.__dict__[key],
1123 self.http.__dict__[key])
1124
1125 def testPickleHttpWithConnection(self):
1126 self.http.request('http://bitworking.org',
1127 connection_type=_MyHTTPConnection)
1128 pickled_http = pickle.dumps(self.http)
1129 new_http = pickle.loads(pickled_http)
1130
1131 self.assertEqual(list(self.http.connections.keys()),
1132 ['http:bitworking.org'])
1133 self.assertEqual(new_http.connections, {})
1134
1135 def testPickleCustomRequestHttp(self):
1136 def dummy_request(*args, **kwargs):
1137 return new_request(*args, **kwargs)
1138 dummy_request.dummy_attr = 'dummy_value'
1139
1140 self.http.request = dummy_request
1141 pickled_http = pickle.dumps(self.http)
1142 self.assertFalse(b"S'request'" in pickled_http)
1143
1107 try: 1144 try:
1108 import memcache 1145 import memcache
1109 class HttpTestMemCached(HttpTest): 1146 class HttpTestMemCached(HttpTest):
1110 def setUp(self): 1147 def setUp(self):
1111 self.cache = memcache.Client(['127.0.0.1:11211'], debug=0) 1148 self.cache = memcache.Client(['127.0.0.1:11211'], debug=0)
1112 #self.cache = memcache.Client(['10.0.0.4:11211'], debug=1) 1149 #self.cache = memcache.Client(['10.0.0.4:11211'], debug=1)
1113 self.http = httplib2.Http(self.cache) 1150 self.http = httplib2.Http(self.cache)
1114 self.cache.flush_all() 1151 self.cache.flush_all()
1115 # Not exactly sure why the sleep is needed here, but 1152 # Not exactly sure why the sleep is needed here, but
1116 # if not present then some unit tests that rely on caching 1153 # if not present then some unit tests that rely on caching
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 response = {} 1528 response = {}
1492 end2end = httplib2._get_end2end_headers(response) 1529 end2end = httplib2._get_end2end_headers(response)
1493 self.assertEqual(0, len(end2end)) 1530 self.assertEqual(0, len(end2end))
1494 1531
1495 # Degenerate case of connection referrring to a header not passed in· 1532 # Degenerate case of connection referrring to a header not passed in·
1496 response = {'connection': 'content-type'} 1533 response = {'connection': 'content-type'}
1497 end2end = httplib2._get_end2end_headers(response) 1534 end2end = httplib2._get_end2end_headers(response)
1498 self.assertEqual(0, len(end2end)) 1535 self.assertEqual(0, len(end2end))
1499 1536
1500 unittest.main() 1537 unittest.main()
OLDNEW
« python3/httplib2/__init__.py ('K') | « python3/httplib2/__init__.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b