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

Side by Side 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 unified diff | Download patch
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 6
7 from testing_utils import testing 7 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
8 8
9 from lib import time_util 9 from lib import time_util
10 from libs.http import retry_http_client
10 11
11 12
12 class FinditTestCase(testing.AppengineTestCase): # pragma: no cover. 13 class MockHttpClient(retry_http_client.RetryHttpClient): # pragma: no cover.
14
15 def __init__(self, response_for_url=None):
16 super(MockHttpClient, self).__init__()
17 if response_for_url is None:
18 self.response_for_url = {}
19
20 def SetResponseForUrl(self, url, response):
21 self.response_for_url[url] = response
22
23 def GetBackoff(self, *_):
24 """Override to avoid sleep."""
25 return 0
26
27 def _Get(self, url, *_):
28 response = self.response_for_url.get(url)
29 if response is None:
30 return 404, 'Not Found'
31 else:
32 return 200, response
33
34 def _Post(self, *_):
35 pass
36
37 def _Put(self, *_):
38 pass
39
40
41 class TestCase(testing.AppengineTestCase): # pragma: no cover.
13 # Setup the customized queues. 42 # Setup the customized queues.
14 taskqueue_stub_root_path = os.path.join( 43 taskqueue_stub_root_path = os.path.join(
15 os.path.dirname(__file__), os.path.pardir) 44 os.path.dirname(__file__), os.path.pardir)
16 45
17 def MockPipeline( 46 def MockPipeline(
18 self, pipeline_class, result, expected_args, expected_kwargs=None): 47 self, pipeline_class, result, expected_args, expected_kwargs=None):
19 """Mocks a pipeline to return a value and asserts the expected parameters. 48 """Mocks a pipeline to return a value and asserts the expected parameters.
20 49
21 Args: 50 Args:
22 pipeline_class (class): The class of the pipeline to be mocked. 51 pipeline_class (class): The class of the pipeline to be mocked.
(...skipping 12 matching lines...) Expand all
35 64
36 self.mock(pipeline_class, 'run', Mocked_run) 65 self.mock(pipeline_class, 'run', Mocked_run)
37 66
38 def MockUTCNow(self, mocked_utcnow): 67 def MockUTCNow(self, mocked_utcnow):
39 """Mocks utcnow with the given value for testing.""" 68 """Mocks utcnow with the given value for testing."""
40 self.mock(time_util, 'GetUTCNow', lambda: mocked_utcnow) 69 self.mock(time_util, 'GetUTCNow', lambda: mocked_utcnow)
41 70
42 def MockUTCNowWithTimezone(self, mocked_utcnow): 71 def MockUTCNowWithTimezone(self, mocked_utcnow):
43 """Mocks utcnow with the given value for testing.""" 72 """Mocks utcnow with the given value for testing."""
44 self.mock(time_util, 'GetUTCNowWithTimezone', lambda: mocked_utcnow) 73 self.mock(time_util, 'GetUTCNowWithTimezone', lambda: mocked_utcnow)
74
75 def GetMockHttpClient(self, response_for_url=None):
76 """Return mocked http client class."""
77 return MockHttpClient(response_for_url)
OLDNEW
« 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