Joe Gregorio | 2149bbf | 2011-06-22 16:43:39 -0400 | [diff] [blame^] | 1 | """ |
| 2 | httplib2test_appengine |
| 3 | |
| 4 | A set of unit tests for httplib2.py on Google App Engine |
| 5 | |
| 6 | """ |
| 7 | |
| 8 | __author__ = "Joe Gregorio (joe@bitworking.org)" |
| 9 | __copyright__ = "Copyright 2011, Joe Gregorio" |
| 10 | |
| 11 | import os |
| 12 | import sys |
| 13 | import unittest |
| 14 | |
| 15 | # The test resources base uri |
| 16 | base = 'http://bitworking.org/projects/httplib2/test/' |
| 17 | #base = 'http://localhost/projects/httplib2/test/' |
| 18 | cacheDirName = ".cache" |
| 19 | APP_ENGINE_PATH='../../google_appengine' |
| 20 | |
| 21 | sys.path.insert(0, APP_ENGINE_PATH) |
| 22 | |
| 23 | import dev_appserver |
| 24 | dev_appserver.fix_sys_path() |
| 25 | |
| 26 | from google.appengine.ext import testbed |
| 27 | testbed = testbed.Testbed() |
| 28 | testbed.activate() |
| 29 | testbed.init_urlfetch_stub() |
| 30 | |
| 31 | import httplib2 |
| 32 | |
| 33 | class AppEngineHttpTest(unittest.TestCase): |
| 34 | def setUp(self): |
| 35 | if os.path.exists(cacheDirName): |
| 36 | [os.remove(os.path.join(cacheDirName, file)) for file in os.listdir(cacheDirName)] |
| 37 | |
| 38 | if sys.version_info < (2, 6): |
| 39 | disable_cert_validation = True |
| 40 | else: |
| 41 | disable_cert_validation = False |
| 42 | |
| 43 | def test(self): |
| 44 | h = httplib2.Http() |
| 45 | response, content = h.request("http://bitworking.org") |
| 46 | self.assertEqual(httplib2.SCHEME_TO_CONNECTION['https'], |
| 47 | httplib2.AppEngineHttpsConnection) |
| 48 | print h.connections |
| 49 | self.assertEquals(1, len(h.connections)) |
| 50 | self.assertEquals(type(h.connections['http:bitworking.org']), |
| 51 | httplib2.AppEngineHttpConnection) |
| 52 | self.assertEquals(response.status, 200) |
| 53 | self.assertEquals(response['status'], '200') |
| 54 | |
| 55 | def test_no_key_or_cert_file(self): |
| 56 | h = httplib2.Http(proxy_info='foo.txt') |
| 57 | try: |
| 58 | response, content = h.request("http://bitworking.org") |
| 59 | self.fail('Should raise exception.') |
| 60 | except httplib2.NotSupportedOnThisPlatform: |
| 61 | pass |
| 62 | |
| 63 | if __name__ == '__main__': |
| 64 | unittest.main() |