Chromium Code Reviews| 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) |