| 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 logging | 6 import logging |
| 7 | 7 |
| 8 from google.appengine.api import app_identity | 8 from google.appengine.api import app_identity |
| 9 | 9 |
| 10 from crash.findit import Findit | 10 from crash.findit import Findit |
| 11 from crash.type_enums import CrashClient | 11 from crash.type_enums import CrashClient |
| 12 from crash.test.predator_testcase import PredatorTestCase | 12 from crash.test.predator_testcase import PredatorTestCase |
| 13 from model.crash.crash_config import CrashConfig |
| 13 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 14 | 15 |
| 15 | |
| 16 MOCK_GET_REPOSITORY = lambda _: None # pragma: no cover | 16 MOCK_GET_REPOSITORY = lambda _: None # pragma: no cover |
| 17 | 17 |
| 18 | 18 |
| 19 class UnsupportedClient(Findit): # pylint: disable=W0223 | 19 class UnsupportedClient(Findit): # pylint: disable=W0223 |
| 20 # TODO(http://crbug.com/659346): this isn't being called for some reason. | 20 # TODO(http://crbug.com/659346): this isn't being called for some reason. |
| 21 @property | 21 @property |
| 22 def client_id(self): # pragma: no cover | 22 def client_id(self): # pragma: no cover |
| 23 return self._client_id | 23 return self._client_id |
| 24 | 24 |
| 25 @property | 25 @property |
| 26 def config(self): # pragma: no cover | 26 def client_config(self): # pragma: no cover |
| 27 """Don't return None, so that PlatformRename doesn't crash.""" | 27 """Don't return None, so that PlatformRename doesn't crash.""" |
| 28 return {} | 28 return {} |
| 29 | 29 |
| 30 def __init__(self, client_id=None): | 30 def __init__(self, client_id=None, config=None): |
| 31 super(UnsupportedClient, self).__init__(MOCK_GET_REPOSITORY) | |
| 32 if client_id is None: | 31 if client_id is None: |
| 33 client_id = 'unsupported_client' | 32 client_id = 'unsupported_client' |
| 34 self._client_id = client_id | 33 self._client_id = client_id |
| 34 super(UnsupportedClient, self).__init__(MOCK_GET_REPOSITORY, config) |
| 35 | 35 |
| 36 | 36 |
| 37 class MockFindit(Findit): # pylint: disable = W | 37 class MockFindit(Findit): # pylint: disable = W |
| 38 """Overwrite abstract method of Findit for testing.""" | 38 """Overwrite abstract method of Findit for testing.""" |
| 39 | 39 |
| 40 def __init__(self): | 40 def __init__(self, config=None): |
| 41 super(MockFindit, self).__init__(MOCK_GET_REPOSITORY) | 41 super(MockFindit, self).__init__(MOCK_GET_REPOSITORY, config) |
| 42 | 42 |
| 43 @classmethod | 43 @classmethod |
| 44 def _ClientID(cls): | 44 def _ClientID(cls): |
| 45 return CrashClient.FRACAS | 45 return CrashClient.FRACAS |
| 46 | 46 |
| 47 def ProcessResultForPublishing(self, result, key): | 47 def ProcessResultForPublishing(self, result, key): |
| 48 return result | 48 return result |
| 49 | 49 |
| 50 | 50 |
| 51 class FinditTest(PredatorTestCase): | 51 class FinditTest(PredatorTestCase): |
| 52 | 52 |
| 53 def setUp(self): | 53 def setUp(self): |
| 54 super(FinditTest, self).setUp() | 54 super(FinditTest, self).setUp() |
| 55 self.findit = MockFindit() | 55 self.findit = MockFindit(CrashConfig.Get()) |
| 56 | 56 |
| 57 def testPlatformRename(self): | 57 def testPlatformRename(self): |
| 58 self.assertEqual( | 58 self.assertEqual( |
| 59 self.findit.RenamePlatform('linux'), 'unix') | 59 self.findit.RenamePlatform('linux'), 'unix') |
| 60 | 60 |
| 61 def testCheckPolicyUnsupportedClient(self): | 61 def testCheckPolicyUnsupportedClient(self): |
| 62 self.assertIsNone(UnsupportedClient().CheckPolicy(self.GetDummyCrashData( | 62 self.assertIsNone(UnsupportedClient(config=CrashConfig.Get()).CheckPolicy( |
| 63 platform = 'canary', | 63 self.GetDummyCrashData( |
| 64 signature = 'sig', | 64 platform = 'canary', |
| 65 ))) | 65 signature = 'sig', |
| 66 ))) |
| 66 | 67 |
| 67 def testCreateAnalysisForUnsupportedClientId(self): | 68 def testCreateAnalysisForUnsupportedClientId(self): |
| 68 self.assertIsNone(UnsupportedClient('unsupported_id').CreateAnalysis( | 69 unsupported_client = UnsupportedClient('unsupported_id', |
| 69 {'signature': 'sig'})) | 70 config=CrashConfig.Get()) |
| 71 self.assertIsNone(unsupported_client.CreateAnalysis({'signature': 'sig'})) |
| 70 | 72 |
| 71 def testGetAnalysisForUnsuportedClient(self): | 73 def testGetAnalysisForUnsuportedClient(self): |
| 72 crash_identifiers = {'signature': 'sig'} | 74 crash_identifiers = {'signature': 'sig'} |
| 73 # TODO(wrengr): it'd be less fragile to call FinditForFracas.CreateAnalysis | 75 # TODO(wrengr): it'd be less fragile to call FinditForFracas.CreateAnalysis |
| 74 # instead. But then we'd need to make UnsupportedClient inherit that | 76 # instead. But then we'd need to make UnsupportedClient inherit that |
| 75 # implementation, rather than inheriting the one from the Findit | 77 # implementation, rather than inheriting the one from the Findit |
| 76 # base class. | 78 # base class. |
| 77 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 79 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 78 analysis.put() | 80 analysis.put() |
| 81 unsupported_client = UnsupportedClient('Unsupported_client', |
| 82 config=CrashConfig.Get()) |
| 79 self.assertIsNone( | 83 self.assertIsNone( |
| 80 UnsupportedClient('Unsupported_client').GetAnalysis(crash_identifiers), | 84 unsupported_client.GetAnalysis(crash_identifiers), |
| 81 'Unsupported client unexpectedly got analysis %s via identifiers %s' | 85 'Unsupported client unexpectedly got analysis %s via identifiers %s' |
| 82 % (analysis, crash_identifiers)) | 86 % (analysis, crash_identifiers)) |
| 83 | 87 |
| 84 def testGetPublishableResultFoundTrue(self): | 88 def testGetPublishableResultFoundTrue(self): |
| 85 analysis_result = { | 89 analysis_result = { |
| 86 'found': True, | 90 'found': True, |
| 87 'suspected_cls': [ | 91 'suspected_cls': [ |
| 88 {'confidence': 0.21434, | 92 {'confidence': 0.21434, |
| 89 'reasons': ['reason1', 'reason2'], | 93 'reasons': ['reason1', 'reason2'], |
| 90 'other': 'data'} | 94 'other': 'data'} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 121 'client_id': self.findit.client_id, | 125 'client_id': self.findit.client_id, |
| 122 'result': copy.deepcopy(analysis_result), | 126 'result': copy.deepcopy(analysis_result), |
| 123 } | 127 } |
| 124 | 128 |
| 125 analysis = FracasCrashAnalysis.Create(crash_identifiers) | 129 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 126 analysis.result = analysis_result | 130 analysis.result = analysis_result |
| 127 | 131 |
| 128 self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers, | 132 self.assertDictEqual(self.findit.GetPublishableResult(crash_identifiers, |
| 129 analysis), | 133 analysis), |
| 130 expected_processed_result) | 134 expected_processed_result) |
| OLD | NEW |