Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: infra_libs/test/httplib2_utils_test.py

Issue 2114073002: Add HttpsMonitor (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add retryable and other things Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: infra_libs/test/httplib2_utils_test.py
diff --git a/infra_libs/test/httplib2_utils_test.py b/infra_libs/test/httplib2_utils_test.py
index 072565608181dc9c020df95d737642c306ada341..ede28bbb12e0372c7be0a802e4101eb1e121eb39 100644
--- a/infra_libs/test/httplib2_utils_test.py
+++ b/infra_libs/test/httplib2_utils_test.py
@@ -129,6 +129,46 @@ class GetAuthenticatedHttp(unittest.TestCase):
'creds_malformed.json',
service_accounts_creds_root=DATA_DIR)
+class RetryableHttplib2Test(unittest.TestCase):
+ def setUp(self):
+ super(RetryableHttplib2Test, self).setUp()
+ self.http = infra_libs.RetryableHttp(httplib2.Http(), max_tries=5,
+ retrying_statuses=[500])
+ self.http.http_obj.request = mock.Mock()
Sergey Berezin 2016/07/06 20:13:29 Please try to use mock.create_autospec(..., spec_s
tnn 2016/07/06 22:05:18 Done.
+
+ def test_succeed(self):
+ self.http.http_obj.request.return_value = (
+ httplib2.Response({'status': 400}), 'content')
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(400, response.status)
+ self.http.http_obj.request.assert_called_once_with('http://foo/',
+ 'GET', None)
+
+ def test_retry_succeed(self):
+ self.http.http_obj.request.side_effect = [
+ (httplib2.Response({'status': 500}), 'content'),
+ httplib2.HttpLib2Error,
+ (httplib2.Response({'status': 200}), 'content')
+ ]
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(200, response.status)
+ self.http.http_obj.request.assert_has_calls(
+ [ mock.call('http://foo/', 'GET', None) ] * 3)
+
+ def test_fail_exception(self):
+ self.http.http_obj.request.side_effect = httplib2.HttpLib2Error
+ self.assertRaises(httplib2.HttpLib2Error, self.http.request, 'http://foo/')
+ self.http.http_obj.request.assert_has_calls(
+ [ mock.call('http://foo/', 'GET', None) ] * 5)
+
+ def test_fail_status_code(self):
+ self.http.http_obj.request.return_value = (
+ httplib2.Response({'status': 500}), 'content')
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(500, response.status)
+ self.http.http_obj.request.assert_has_calls(
+ [ mock.call('http://foo/', 'GET', None) ] * 5)
+
class InstrumentedHttplib2Test(unittest.TestCase):
def setUp(self):

Powered by Google App Engine
This is Rietveld 408576698