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

Unified Diff: appengine/findit/libs/testcase.py

Issue 2521773004: [Culprit-finder] Refactor findit testcase and move it to libs. (Closed)
Patch Set: . Created 4 years, 1 month 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: appengine/findit/libs/testcase.py
diff --git a/appengine/findit/common/findit_testcase.py b/appengine/findit/libs/testcase.py
similarity index 63%
rename from appengine/findit/common/findit_testcase.py
rename to appengine/findit/libs/testcase.py
index 75f15506783728426a9c81ef76f1cd0a28ca90ba..f2cbe2effc42ae2d3a72dc8e72f64b7153e5bc17 100644
--- a/appengine/findit/common/findit_testcase.py
+++ b/appengine/findit/libs/testcase.py
@@ -7,9 +7,38 @@ import os
from testing_utils import testing
stgao 2016/11/23 20:24:53 But this depends on App Engine local test setup, w
Sharu Jiang 2016/11/23 20:55:00 Right, that makes sense, move it in another cl htt
from lib import time_util
+from libs.http import retry_http_client
-class FinditTestCase(testing.AppengineTestCase): # pragma: no cover.
+class MockHttpClient(retry_http_client.RetryHttpClient): # pragma: no cover.
+
+ def __init__(self, response_for_url=None):
+ super(MockHttpClient, self).__init__()
+ if response_for_url is None:
+ self.response_for_url = {}
+
+ def SetResponseForUrl(self, url, response):
+ self.response_for_url[url] = response
+
+ def GetBackoff(self, *_):
+ """Override to avoid sleep."""
+ return 0
+
+ def _Get(self, url, *_):
+ response = self.response_for_url.get(url)
+ if response is None:
+ return 404, 'Not Found'
+ else:
+ return 200, response
+
+ def _Post(self, *_):
+ pass
+
+ def _Put(self, *_):
+ pass
+
+
+class TestCase(testing.AppengineTestCase): # pragma: no cover.
# Setup the customized queues.
taskqueue_stub_root_path = os.path.join(
os.path.dirname(__file__), os.path.pardir)
@@ -42,3 +71,7 @@ class FinditTestCase(testing.AppengineTestCase): # pragma: no cover.
def MockUTCNowWithTimezone(self, mocked_utcnow):
"""Mocks utcnow with the given value for testing."""
self.mock(time_util, 'GetUTCNowWithTimezone', lambda: mocked_utcnow)
+
+ def GetMockHttpClient(self, response_for_url=None):
+ """Return mocked http client class."""
+ return MockHttpClient(response_for_url)
« no previous file with comments | « appengine/findit/lib/gitiles/test/gitiles_repository_test.py ('k') | appengine/findit/model/crash/test/crash_config_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698