[httplib2] push by joe.gregorio - Add unit tests for app engine specific code. Fix bugs found in said te... on 2011-06-22 20:43 GMT

3 views
Skip to first unread message

codesite...@google.com

unread,
Jun 22, 2011, 4:44:17 PM6/22/11
to httplib...@googlegroups.com
Revision: b1d391994b33
Author: Joe Gregorio <jcgre...@google.com>
Date: Wed Jun 22 13:43:39 2011
Log: Add unit tests for app engine specific code. Fix bugs found in
said tests.
http://code.google.com/p/httplib2/source/detail?r=b1d391994b33

Added:
/python2/httplib2test_appengine.py
Modified:
/Makefile
/python2/httplib2/__init__.py

=======================================
--- /dev/null
+++ /python2/httplib2test_appengine.py Wed Jun 22 13:43:39 2011
@@ -0,0 +1,64 @@
+"""
+httplib2test_appengine
+
+A set of unit tests for httplib2.py on Google App Engine
+
+"""
+
+__author__ = "Joe Gregorio (j...@bitworking.org)"
+__copyright__ = "Copyright 2011, Joe Gregorio"
+
+import os
+import sys
+import unittest
+
+# The test resources base uri
+base = 'http://bitworking.org/projects/httplib2/test/'
+#base = 'http://localhost/projects/httplib2/test/'
+cacheDirName = ".cache"
+APP_ENGINE_PATH='../../google_appengine'
+
+sys.path.insert(0, APP_ENGINE_PATH)
+
+import dev_appserver
+dev_appserver.fix_sys_path()
+
+from google.appengine.ext import testbed
+testbed = testbed.Testbed()
+testbed.activate()
+testbed.init_urlfetch_stub()
+
+import httplib2
+
+class AppEngineHttpTest(unittest.TestCase):
+ def setUp(self):
+ if os.path.exists(cacheDirName):
+ [os.remove(os.path.join(cacheDirName, file)) for file in
os.listdir(cacheDirName)]
+
+ if sys.version_info < (2, 6):
+ disable_cert_validation = True
+ else:
+ disable_cert_validation = False
+
+ def test(self):
+ h = httplib2.Http()
+ response, content = h.request("http://bitworking.org")
+ self.assertEqual(httplib2.SCHEME_TO_CONNECTION['https'],
+ httplib2.AppEngineHttpsConnection)
+ print h.connections
+ self.assertEquals(1, len(h.connections))
+ self.assertEquals(type(h.connections['http:bitworking.org']),
+ httplib2.AppEngineHttpConnection)
+ self.assertEquals(response.status, 200)
+ self.assertEquals(response['status'], '200')
+
+ def test_no_key_or_cert_file(self):
+ h = httplib2.Http(proxy_info='foo.txt')
+ try:
+ response, content = h.request("http://bitworking.org")
+ self.fail('Should raise exception.')
+ except httplib2.NotSupportedOnThisPlatform:
+ pass
+
+if __name__ == '__main__':
+ unittest.main()
=======================================
--- /Makefile Thu Jun 16 07:08:15 2011
+++ /Makefile Wed Jun 22 13:43:39 2011
@@ -2,7 +2,9 @@
cd python2 && python2.4 httplib2test.py
-cd python2 && python2.5 httplib2test.py
cd python2 && python2.6 httplib2test.py
+ cd python2 && python2.6 httplib2test_appengine.py
cd python2 && python2.7 httplib2test.py
+ cd python2 && python2.7 httplib2test_appengine.py
cd python3 && python3.2 httplib2test.py

VERSION = $(shell python setup.py --version)
=======================================
--- /python2/httplib2/__init__.py Mon Jun 13 11:06:23 2011
+++ /python2/httplib2/__init__.py Wed Jun 22 13:43:39 2011
@@ -147,6 +147,7 @@
class ProxiesUnavailableError(HttpLib2Error): pass
class CertificateValidationUnsupported(HttpLib2Error): pass
class SSLHandshakeError(HttpLib2Error): pass
+class NotSupportedOnThisPlatform(HttpLib2Error): pass
class CertificateHostnameMismatch(SSLHandshakeError):
def __init__(self, desc, host, cert):
HttpLib2Error.__init__(self, desc)
@@ -976,7 +977,8 @@
deadline=self.timeout,
validate_certificate=self.validate_certificate)
self.response = ResponseDict(response.headers)
- self.response['status'] = response.status_code
+ self.response['status'] = str(response.status_code)
+ self.response.status = response.status_code
setattr(self.response, 'read', lambda : response.content)

# Make sure the exceptions raised match the exceptions expected.

Reply all
Reply to author
Forward
0 new messages