Commits

Anonymous committed 9eaba43

Fixed behavior when in app-engine environment without urlfetch stub registered.

Comments (0)

Files changed (2)

python/protorpc/transport.py

 
 try:
   from google.appengine.api import urlfetch
+  from google.appengine.api import apiproxy_stub_map
 except ImportError:
   urlfetch = None
 
 
     def _start_request(self, encoded_request):
       """Initiate async call."""
-
       self.__urlfetch_rpc = urlfetch.create_rpc()
 
       headers = {
     super(HttpTransport, self).__init__(protocol=protocol)
     self.__service_url = service_url
 
-    if urlfetch:
+    if urlfetch and apiproxy_stub_map.apiproxy.GetStub('urlfetch'):
       self.__request_type = self.__UrlfetchRequest
     else:
       self.__request_type = self.__UrllibRequest

python/protorpc/transport_test.py

 
   def setUp(self):
     super(HttpTransportUrllibTest, self).setUp()
-    self.original_urlfetch = transport.urlfetch
-    transport.urlfetch = None
 
     self.trans = transport.HttpTransport('http://myserver/myservice',
                                          protocol=protojson)
 
   def tearDown(self):
     super(HttpTransportUrllibTest, self).tearDown()
-    transport.urlfetch = self.original_urlfetch
 
     self.mox.UnsetStubs()
     self.mox.VerifyAll()
     self.assertEquals(None, rpc.error_name)
 
 
+class NoModuleHttpTransportUrllibTest(HttpTransportUrllibTest):
+
+  def setUp(self):
+    self.original_urlfetch = transport.urlfetch
+    transport.urlfetch = None
+    super(NoModuleHttpTransportUrllibTest, self).setUp()
+
+  def tearDown(self):
+    transport.urlfetch = self.original_urlfetch
+    super(NoModuleHttpTransportUrllibTest, self).tearDown()
+
+
 class URLFetchResponse(object):
 
   def __init__(self, content, status_code, headers):
   def setUp(self):
     super(HttpTransportUrlfetchTest, self).setUp()
 
+    # Need to initialize the urlfetch stub so that urlfetch detection works
+    # properly.
+    self.testbed = testbed.Testbed()
+    self.testbed.activate()
+    self.testbed.init_urlfetch_stub()
+
     self.trans = transport.HttpTransport('http://myserver/myservice',
                                          protocol=protojson)
 
   def tearDown(self):
     super(HttpTransportUrlfetchTest, self).tearDown()
 
+    self.testbed.deactivate()
+
     self.mox.UnsetStubs()
     self.mox.VerifyAll()