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

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: Fix 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..cc6a7491ae59aa0a512a16d24f362554e77d2a00 100644
--- a/infra_libs/test/httplib2_utils_test.py
+++ b/infra_libs/test/httplib2_utils_test.py
@@ -129,6 +129,44 @@ class GetAuthenticatedHttp(unittest.TestCase):
'creds_malformed.json',
service_accounts_creds_root=DATA_DIR)
+class RetriableHttplib2Test(unittest.TestCase):
+ def setUp(self):
+ super(RetriableHttplib2Test, self).setUp()
+ self.http = infra_libs.RetriableHttp()
+ self.http._request = mock.create_autospec(self.http._request, spec_set=True)
+
+ _MOCK_REQUEST = mock.call(mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY,
Sergey Berezin 2016/07/06 22:35:49 nit: mock.call(*([mock.ANY] * 9))
tnn 2016/07/06 22:44:36 Done.
+ mock.ANY, mock.ANY, mock.ANY, mock.ANY)
+
+ def test_succeed(self):
+ self.http._request.return_value = (
+ httplib2.Response({'status': 400}), 'content')
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(400, response.status)
+ self.http._request.assert_has_calls([ self._MOCK_REQUEST ])
+
+ def test_retry_succeed(self):
+ self.http._request.side_effect = [
+ (httplib2.Response({'status': 500}), 'content'),
+ httplib2.HttpLib2Error,
+ (httplib2.Response({'status': 200}), 'content')
+ ].__iter__()
Sergey Berezin 2016/07/06 22:35:49 nit: it's cleaner to write ... = iter([...])
tnn 2016/07/06 22:44:36 Done.
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(200, response.status)
+ self.http._request.assert_has_calls([ self._MOCK_REQUEST ] * 3)
+
+ def test_fail_exception(self):
+ self.http._request.side_effect = httplib2.HttpLib2Error
+ self.assertRaises(httplib2.HttpLib2Error, self.http.request, 'http://foo/')
+ self.http._request.assert_has_calls([ self._MOCK_REQUEST ] * 5)
+
+ def test_fail_status_code(self):
+ self.http._request.return_value = (
+ httplib2.Response({'status': 500}), 'content')
+ response, _ = self.http.request('http://foo/')
+ self.assertEqual(500, response.status)
+ self.http._request.assert_has_calls([ self._MOCK_REQUEST ] * 5)
+
class InstrumentedHttplib2Test(unittest.TestCase):
def setUp(self):

Powered by Google App Engine
This is Rietveld 408576698