| OLD | NEW |
| 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 copy | 5 import copy |
| 6 import re | 6 import re |
| 7 | 7 |
| 8 import gae_ts_mon | 8 import gae_ts_mon |
| 9 from google.appengine.api import users | 9 from google.appengine.api import users |
| 10 | 10 |
| 11 from crash.crash_data import CrashData | 11 from crash.crash_data import CrashData |
| 12 from crash.findit import Findit | 12 from crash.findit import Findit |
| 13 from crash.type_enums import CrashClient |
| 13 from gae_libs.testcase import TestCase | 14 from gae_libs.testcase import TestCase |
| 14 from libs.gitiles.change_log import ChangeLog | 15 from libs.gitiles.change_log import ChangeLog |
| 15 from libs.gitiles.gitiles_repository import GitilesRepository | 16 from libs.gitiles.gitiles_repository import GitilesRepository |
| 16 from libs.http import retry_http_client | 17 from libs.http import retry_http_client |
| 17 from model.crash.crash_config import CrashConfig | 18 from model.crash.crash_config import CrashConfig |
| 18 from model.crash.crash_analysis import CrashAnalysis | 19 from model.crash.crash_analysis import CrashAnalysis |
| 19 | 20 |
| 20 | 21 |
| 21 DEFAULT_CONFIG_DATA = { | 22 DEFAULT_CONFIG_DATA = { |
| 22 'fracas': { | 23 'fracas': { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 super(PredatorTestCase, self).setUp() | 103 super(PredatorTestCase, self).setUp() |
| 103 CrashConfig.Get().Update( | 104 CrashConfig.Get().Update( |
| 104 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA) | 105 users.User(email='admin@chromium.org'), True, **DEFAULT_CONFIG_DATA) |
| 105 gae_ts_mon.reset_for_unittest(disable=True) | 106 gae_ts_mon.reset_for_unittest(disable=True) |
| 106 | 107 |
| 107 def GetDummyChangeLog(self): | 108 def GetDummyChangeLog(self): |
| 108 return DUMMY_CHANGELOG | 109 return DUMMY_CHANGELOG |
| 109 | 110 |
| 110 def GetMockFindit(self, get_repository=None, config=None, | 111 def GetMockFindit(self, get_repository=None, config=None, |
| 111 client_id='mock_client'): | 112 client_id='mock_client'): |
| 112 """Gets Mocked ``Findit`` object.""" | |
| 113 get_repository = (get_repository or | 113 get_repository = (get_repository or |
| 114 GitilesRepository.Factory(self.GetMockHttpClient())) | 114 GitilesRepository.Factory(self.GetMockHttpClient())) |
| 115 config = config or CrashConfig.Get() | 115 config = config or CrashConfig.Get() |
| 116 | 116 |
| 117 class MockFindit(Findit): # pylint: disable=W0223 | 117 class MockFindit(Findit): # pylint: disable=W0223 |
| 118 """Overwrite abstract method of Findit for testing.""" | 118 """Overwrite abstract method of Findit for testing.""" |
| 119 def __init__(self): | 119 def __init__(self): |
| 120 super(MockFindit, self).__init__(get_repository, config) | 120 super(MockFindit, self).__init__(get_repository, config) |
| 121 | 121 |
| 122 @classmethod | 122 @classmethod |
| 123 def _ClientID(cls): | 123 def _ClientID(cls): |
| 124 return client_id | 124 return client_id |
| 125 | 125 |
| 126 def ProcessResultForPublishing(self, result, key): | 126 def ProcessResultForPublishing(self, result, key): |
| 127 return result | 127 return result |
| 128 | 128 |
| 129 def GetCrashData(self, crash_data): |
| 130 |
| 131 class MockCrashData(CrashData): |
| 132 @property |
| 133 def regression_range(self): |
| 134 return crash_data.get('regression_range') |
| 135 |
| 136 @property |
| 137 def stacktrace(self): |
| 138 return None |
| 139 |
| 140 @property |
| 141 def dependencies(self): |
| 142 return {} |
| 143 |
| 144 @property |
| 145 def dependency_rolls(self): |
| 146 return {} |
| 147 |
| 148 return MockCrashData(crash_data) |
| 149 |
| 129 def GetAnalysis(self, crash_identifiers): | 150 def GetAnalysis(self, crash_identifiers): |
| 130 return CrashAnalysis.Get(crash_identifiers) | 151 return CrashAnalysis.Get(crash_identifiers) |
| 131 | 152 |
| 132 def CreateAnalysis(self, crash_identifiers): | 153 def CreateAnalysis(self, crash_identifiers): |
| 133 return CrashAnalysis.Create(crash_identifiers) | 154 return CrashAnalysis.Create(crash_identifiers) |
| 134 | 155 |
| 135 return MockFindit() | 156 return MockFindit() |
| 136 | 157 |
| 137 def GetDummyCrashData(self, client_id='mock_client', version='1', | 158 def GetDummyChromeCrashData( |
| 138 signature='signature', platform='win', | 159 self, client_id='mock_client', version='1', signature='signature', |
| 139 stack_trace=None, regression_range=None, | 160 platform='win', stack_trace=None, regression_range=None, channel='canary', |
| 140 channel='canary', historical_metadata=None, | 161 historical_metadata=None, process_type='browser'): |
| 141 crash_identifiers=True, process_type='browser'): | 162 crash_identifiers = { |
| 142 """Gets Mocked crashed_data sent by clients.""" | 163 'chrome_version': version, |
| 143 if crash_identifiers is True: # pragma: no cover | 164 'signature': signature, |
| 144 crash_identifiers = { | 165 'channel': channel, |
| 145 'chrome_version': version, | 166 'platform': platform, |
| 146 'signature': signature, | 167 'process_type': process_type, |
| 147 'channel': channel, | 168 } |
| 148 'platform': platform, | 169 customized_data = { |
| 149 'process_type': process_type, | 170 'historical_metadata': historical_metadata, |
| 150 } | 171 'channel': channel, |
| 172 } |
| 173 |
| 151 crash_data = { | 174 crash_data = { |
| 152 'chrome_version': version, | 175 'chrome_version': version, |
| 153 'signature': signature, | 176 'signature': signature, |
| 154 'platform': platform, | 177 'platform': platform, |
| 155 'stack_trace': stack_trace, | 178 'stack_trace': stack_trace, |
| 156 'regression_range': regression_range, | 179 'regression_range': regression_range, |
| 157 'crash_identifiers': crash_identifiers, | 180 'crash_identifiers': crash_identifiers, |
| 158 'customized_data': { | 181 'customized_data': customized_data |
| 159 'historical_metadata': historical_metadata, | |
| 160 'channel': channel, | |
| 161 }, | |
| 162 } | 182 } |
| 163 # This insertion of client_id is used for debugging ScheduleNewAnalysis. | 183 # This insertion of client_id is used for debugging ScheduleNewAnalysis. |
| 164 if client_id is not None: # pragma: no cover | 184 if client_id is not None: # pragma: no cover |
| 165 crash_data['client_id'] = client_id | 185 crash_data['client_id'] = client_id |
| 166 return crash_data | 186 return crash_data |
| OLD | NEW |