diff options
author | Joe Gregorio <jcgregorio@google.com> | 2011-06-22 16:43:39 -0400 |
---|---|---|
committer | Joe Gregorio <jcgregorio@google.com> | 2011-06-22 16:43:39 -0400 |
commit | 2149bbfe16b9fc813ad4f32bc582aaa50e5fa58f (patch) | |
tree | ce313ec78de152cd2b3402eff4e8e174ca11c13f /python2/httplib2test_appengine.py | |
parent | b2cfdf6c271f3100fd9789ba74ace0d6e3568e4a (diff) | |
download | httplib2-2149bbfe16b9fc813ad4f32bc582aaa50e5fa58f.tar.gz |
Add unit tests for app engine specific code. Fix bugs found in said tests.
Diffstat (limited to 'python2/httplib2test_appengine.py')
-rw-r--r-- | python2/httplib2test_appengine.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/python2/httplib2test_appengine.py b/python2/httplib2test_appengine.py new file mode 100644 index 0000000..25317e2 --- /dev/null +++ b/python2/httplib2test_appengine.py @@ -0,0 +1,64 @@ +""" +httplib2test_appengine + +A set of unit tests for httplib2.py on Google App Engine + +""" + +__author__ = "Joe Gregorio (joe@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() |