1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
"""Tests for httplib2 on Google App Engine."""
import mock
import os
import sys
import unittest
APP_ENGINE_PATH = "/usr/local/google_appengine"
sys.path.insert(0, APP_ENGINE_PATH)
import dev_appserver
dev_appserver.fix_sys_path()
from google.appengine.ext import testbed
# Ensure that we are not loading the httplib2 version included in the Google
# App Engine SDK.
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
class AberrationsTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
def tearDown(self):
self.testbed.deactivate()
@mock.patch.dict("os.environ", {"SERVER_SOFTWARE": ""})
def testConnectionInit(self):
global httplib2
import httplib2
self.assertNotEqual(
httplib2.SCHEME_TO_CONNECTION["https"], httplib2.AppEngineHttpsConnection
)
self.assertNotEqual(
httplib2.SCHEME_TO_CONNECTION["http"], httplib2.AppEngineHttpConnection
)
del globals()["httplib2"]
class AppEngineHttpTest(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
global httplib2
import httplib2
reload(httplib2)
def tearDown(self):
self.testbed.deactivate()
del globals()["httplib2"]
def testConnectionInit(self):
self.assertEqual(
httplib2.SCHEME_TO_CONNECTION["https"], httplib2.AppEngineHttpsConnection
)
self.assertEqual(
httplib2.SCHEME_TO_CONNECTION["http"], httplib2.AppEngineHttpConnection
)
def testGet(self):
http = httplib2.Http()
response, content = http.request("http://www.google.com")
self.assertEqual(
httplib2.SCHEME_TO_CONNECTION["https"], httplib2.AppEngineHttpsConnection
)
self.assertEquals(1, len(http.connections))
self.assertEquals(response.status, 200)
self.assertEquals(response["status"], "200")
def testProxyInfoIgnored(self):
http = httplib2.Http(proxy_info=mock.MagicMock())
response, content = http.request("http://www.google.com")
self.assertEquals(response.status, 200)
if __name__ == "__main__":
unittest.main()
|