| OLD | NEW |
| (Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import copy |
| 6 import logging |
| 7 |
| 8 from crash.findit import Findit |
| 9 from crash.type_enums import CrashClient |
| 10 from crash.test.crash_pipeline_test import DummyCrashData |
| 11 from crash.test.crash_testcase import CrashTestCase |
| 12 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 13 |
| 14 # In production we'd use CrashWrapperPipeline. And that'd work fine here, |
| 15 # since we never actually call the method that uses it. But just to be |
| 16 # absolutely sure we don't go over the wire due to some mocking failure, |
| 17 # we'll use this dummy class instead. (In fact, since it's never used, |
| 18 # we don't even need to give a real class; |None| works just fine.) |
| 19 MOCK_PIPELINE_CLS = None |
| 20 |
| 21 MOCK_REPOSITORY = None |
| 22 |
| 23 class UnsupportedClient(Findit): # pylint: disable=W0223 |
| 24 # TODO(http://crbug.com/659346): this isn't being called for some reason. |
| 25 @property |
| 26 def client_id(self): # pragma: no cover |
| 27 return self._client_id |
| 28 |
| 29 @property |
| 30 def config(self): # pragma: no cover |
| 31 """Don't return None, so that PlatformRename doesn't crash.""" |
| 32 return {} |
| 33 |
| 34 def __init__(self, client_id=None): |
| 35 super(UnsupportedClient, self).__init__(MOCK_REPOSITORY, MOCK_PIPELINE_CLS) |
| 36 if client_id is None: |
| 37 client_id = 'unsupported_client' |
| 38 self._client_id = client_id |
| 39 |
| 40 |
| 41 class FinditTest(CrashTestCase): |
| 42 |
| 43 def testPlatformRename(self): |
| 44 class _MockFindit(Findit): # pylint: disable=W0223 |
| 45 @classmethod |
| 46 def _ClientID(cls): |
| 47 return CrashClient.FRACAS |
| 48 |
| 49 self.assertEqual( |
| 50 _MockFindit(MOCK_REPOSITORY, MOCK_PIPELINE_CLS).RenamePlatform('linux'), |
| 51 'unix') |
| 52 |
| 53 def testScheduleNewAnalysisWithFailingPolicy(self): |
| 54 class _MockFindit(Findit): # pylint: disable=W0223 |
| 55 def __init__(self): |
| 56 super(_MockFindit, self).__init__(MOCK_REPOSITORY, MOCK_PIPELINE_CLS) |
| 57 |
| 58 def CheckPolicy(self, crash_data): |
| 59 """This is the same as inherited, but just to be explicit.""" |
| 60 return None |
| 61 |
| 62 def _NeedsNewAnalysis(self, _crash_data): |
| 63 raise AssertionError('testScheduleNewAnalysisWithFailingPolicy: ' |
| 64 "called _MockFindit._NeedsNewAnalysis, when it shouldn't.") |
| 65 |
| 66 self.assertFalse(_MockFindit().ScheduleNewAnalysis(DummyCrashData())) |
| 67 |
| 68 def testScheduleNewAnalysisWithPlatformRename(self): |
| 69 original_crash_data = DummyCrashData( |
| 70 version = None, |
| 71 platform = 'unix', |
| 72 crash_identifiers = {}) |
| 73 renamed_crash_data = copy.deepcopy(original_crash_data) |
| 74 renamed_crash_data['platform'] = 'linux' |
| 75 |
| 76 testcase = self |
| 77 class _MockFindit(Findit): # pylint: disable=W0223 |
| 78 def __init__(self): |
| 79 super(_MockFindit, self).__init__(MOCK_REPOSITORY, MOCK_PIPELINE_CLS) |
| 80 |
| 81 @property |
| 82 def config(self): |
| 83 """Make PlatformRename work as expected.""" |
| 84 return {'platform_rename': {'unix': 'linux'}} |
| 85 |
| 86 def CheckPolicy(self, crash_data): |
| 87 """Call PlatformRename, and return successfully. |
| 88 |
| 89 N.B., if we did not override this method, then our overridden |
| 90 ``_NeedsNewAnalysis`` would never be called either.""" |
| 91 # TODO(wrengr): should we clone |crash_data| rather than mutating it? |
| 92 crash_data['platform'] = self.RenamePlatform(crash_data['platform']) |
| 93 return crash_data |
| 94 |
| 95 def _NeedsNewAnalysis(self, new_crash_data): |
| 96 logging.debug('Called _MockFindit._NeedsNewAnalysis, as desired') |
| 97 testcase.assertDictEqual(new_crash_data, renamed_crash_data) |
| 98 return False |
| 99 |
| 100 self.assertFalse(_MockFindit().ScheduleNewAnalysis(original_crash_data)) |
| 101 |
| 102 def testCheckPolicyUnsupportedClient(self): |
| 103 self.assertIsNone(UnsupportedClient().CheckPolicy(DummyCrashData( |
| 104 platform = 'canary', |
| 105 signature = 'sig', |
| 106 ))) |
| 107 |
| 108 def testCreateAnalysisForUnsupportedClientId(self): |
| 109 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis( |
| 110 {'signature': 'sig'})) |
| 111 |
| 112 def testGetAnalysisForUnsuportedClient(self): |
| 113 crash_identifiers = {'signature': 'sig'} |
| 114 # TODO(wrengr): it'd be less fragile to call FinditForFracas.CreateAnalysis |
| 115 # instead. But then we'd need to make UnsupportedClient inherit that |
| 116 # implementation, rather than inheriting the one from the Findit |
| 117 # base class. |
| 118 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 119 analysis.put() |
| 120 self.assertIsNone( |
| 121 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers), |
| 122 'Unsupported client unexpectedly got analysis %s via identifiers %s' |
| 123 % (analysis, crash_identifiers)) |
| OLD | NEW |