Revert "Raise exceptions properly on HTTP errors from OAuthRpcServer (which is only used on bots)"

BUG=585632
TBR=agable

Review URL: https://codereview.chromium.org/1686753003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298693 0039d316-1c4b-4281-b951-d872f2087c98
changes/01/332501/1
dsansome@chromium.org 10 years ago
parent 6fa3c67f7e
commit c1eb692f03

@ -416,7 +416,10 @@ class Rietveld(object):
for retry in xrange(self._maxtries): for retry in xrange(self._maxtries):
try: try:
logging.debug('%s' % request_path) logging.debug('%s' % request_path)
return self.rpc_server.Send(request_path, **kwargs) result = self.rpc_server.Send(request_path, **kwargs)
# Sometimes GAE returns a HTTP 200 but with HTTP 500 as the content.
# How nice.
return result
except urllib2.HTTPError, e: except urllib2.HTTPError, e:
if retry >= (self._maxtries - 1): if retry >= (self._maxtries - 1):
raise raise
@ -525,11 +528,6 @@ class OAuthRpcServer(object):
payload: request is a POST if not None, GET otherwise payload: request is a POST if not None, GET otherwise
timeout: in seconds timeout: in seconds
extra_headers: (dict) extra_headers: (dict)
Returns: the HTTP response body as a string
Raises:
urllib2.HTTPError
""" """
# This method signature should match upload.py:AbstractRpcServer.Send() # This method signature should match upload.py:AbstractRpcServer.Send()
method = 'GET' method = 'GET'
@ -545,6 +543,7 @@ class OAuthRpcServer(object):
try: try:
if timeout: if timeout:
self._http.timeout = timeout self._http.timeout = timeout
# TODO(pgervais) implement some kind of retry mechanism (see upload.py).
url = self.host + request_path url = self.host + request_path
if kwargs: if kwargs:
url += "?" + urllib.urlencode(kwargs) url += "?" + urllib.urlencode(kwargs)
@ -573,10 +572,6 @@ class OAuthRpcServer(object):
continue continue
break break
if ret[0].status != 200:
raise urllib2.HTTPError(
request_path, int(ret[0]['status']), ret[1], None, None)
return ret[1] return ret[1]
finally: finally:

@ -5,23 +5,19 @@
"""Unit tests for rietveld.py.""" """Unit tests for rietveld.py."""
import httplib
import logging import logging
import os import os
import socket import socket
import ssl import ssl
import StringIO
import sys import sys
import time import time
import traceback import traceback
import unittest import unittest
import urllib2
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support.patches_data import GIT, RAW from testing_support.patches_data import GIT, RAW
from testing_support import auto_stub from testing_support import auto_stub
from third_party import httplib2
import patch import patch
import rietveld import rietveld
@ -494,30 +490,6 @@ class DefaultTimeoutTest(auto_stub.TestCase):
self.rietveld.post('/api/1234', [('key', 'data')]) self.rietveld.post('/api/1234', [('key', 'data')])
self.assertNotEqual(self.sleep_time, 0) self.assertNotEqual(self.sleep_time, 0)
class OAuthRpcServerTest(auto_stub.TestCase):
def setUp(self):
super(OAuthRpcServerTest, self).setUp()
self.rpc_server = rietveld.OAuthRpcServer(
'http://www.example.com', 'foo', 'bar')
def set_mock_response(self, status):
def MockHttpRequest(*args, **kwargs):
return (httplib2.Response({'status': status}), 'body')
self.mock(self.rpc_server._http, 'request', MockHttpRequest)
def test_404(self):
self.set_mock_response(404)
with self.assertRaises(urllib2.HTTPError) as ctx:
self.rpc_server.Send('/foo')
self.assertEquals(404, ctx.exception.code)
def test_200(self):
self.set_mock_response(200)
ret = self.rpc_server.Send('/foo')
self.assertEquals('body', ret)
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(level=[ logging.basicConfig(level=[
logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))]) logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])

Loading…
Cancel
Save