blob: 25317e2c29f54706a23f0625acda990e309fef49 [file] [log] [blame]
Joe Gregorio2149bbf2011-06-22 16:43:39 -04001"""
2httplib2test_appengine
3
4A 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
11import os
12import sys
13import unittest
14
15# The test resources base uri
16base = 'http://bitworking.org/projects/httplib2/test/'
17#base = 'http://localhost/projects/httplib2/test/'
18cacheDirName = ".cache"
19APP_ENGINE_PATH='../../google_appengine'
20
21sys.path.insert(0, APP_ENGINE_PATH)
22
23import dev_appserver
24dev_appserver.fix_sys_path()
25
26from google.appengine.ext import testbed
27testbed = testbed.Testbed()
28testbed.activate()
29testbed.init_urlfetch_stub()
30
31import httplib2
32
33class 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
63if __name__ == '__main__':
64 unittest.main()