| 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 from datetime import datetime | 6 from datetime import datetime |
| 6 | 7 |
| 8 from google.appengine.api import app_identity |
| 9 |
| 10 from crash.type_enums import CrashClient |
| 7 from crash.test.crash_testcase import CrashTestCase | 11 from crash.test.crash_testcase import CrashTestCase |
| 8 from model.crash.crash_analysis import CrashAnalysis | |
| 9 from model import analysis_status | 12 from model import analysis_status |
| 10 from model import result_status | 13 from model import result_status |
| 11 from model import triage_status | 14 from model import triage_status |
| 15 from model.crash.crash_analysis import CrashAnalysis |
| 16 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 12 | 17 |
| 13 | 18 |
| 14 class CrashAnalysisTest(CrashTestCase): | 19 class CrashAnalysisTest(CrashTestCase): |
| 15 def testCrashAnalysisStatusIsCompleted(self): | 20 def testCrashAnalysisStatusIsCompleted(self): |
| 16 for status in (analysis_status.COMPLETED, analysis_status.ERROR): | 21 for status in (analysis_status.COMPLETED, analysis_status.ERROR): |
| 17 analysis = CrashAnalysis() | 22 analysis = CrashAnalysis() |
| 18 analysis.status = status | 23 analysis.status = status |
| 19 self.assertTrue(analysis.completed) | 24 self.assertTrue(analysis.completed) |
| 20 | 25 |
| 21 def testCrashAnalysisStatusIsNotCompleted(self): | 26 def testCrashAnalysisStatusIsNotCompleted(self): |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 analysis = CrashAnalysis() | 99 analysis = CrashAnalysis() |
| 95 analysis.Update(update) | 100 analysis.Update(update) |
| 96 self.assertFalse(hasattr(analysis, 'dummy')) | 101 self.assertFalse(hasattr(analysis, 'dummy')) |
| 97 | 102 |
| 98 def testCreateCrashAnalysis(self): | 103 def testCreateCrashAnalysis(self): |
| 99 crash_identifiers = {'signature': 'sig'} | 104 crash_identifiers = {'signature': 'sig'} |
| 100 analysis = CrashAnalysis.Create(crash_identifiers) | 105 analysis = CrashAnalysis.Create(crash_identifiers) |
| 101 analysis.put() | 106 analysis.put() |
| 102 self.assertIsNotNone(analysis) | 107 self.assertIsNotNone(analysis) |
| 103 self.assertEqual(CrashAnalysis.Get(crash_identifiers), analysis) | 108 self.assertEqual(CrashAnalysis.Get(crash_identifiers), analysis) |
| 109 |
| 110 def testGetPublishableResulFoundTrue(self): |
| 111 mock_host = 'https://host.com' |
| 112 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 113 |
| 114 analysis_result = { |
| 115 'found': True, |
| 116 'suspected_cls': [ |
| 117 {'confidence': 0.21434, |
| 118 'reason': ['reason1', 'reason2'], |
| 119 'other': 'data'} |
| 120 ], |
| 121 'other_data': 'data', |
| 122 } |
| 123 |
| 124 processed_analysis_result = copy.deepcopy(analysis_result) |
| 125 processed_analysis_result['feedback_url'] = ( |
| 126 mock_host + '/crash/fracas-result-feedback?' |
| 127 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 128 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 129 |
| 130 for cl in processed_analysis_result['suspected_cls']: |
| 131 cl['confidence'] = round(cl['confidence'], 2) |
| 132 cl.pop('reason', None) |
| 133 |
| 134 crash_identifiers = {'signature': 'sig'} |
| 135 expected_messages_data = { |
| 136 'crash_identifiers': crash_identifiers, |
| 137 'client_id': CrashClient.FRACAS, |
| 138 'result': processed_analysis_result, |
| 139 } |
| 140 |
| 141 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 142 analysis.client_id = CrashClient.FRACAS |
| 143 analysis.result = analysis_result |
| 144 |
| 145 self.assertDictEqual(analysis.ToPublishableResult(crash_identifiers), |
| 146 expected_messages_data) |
| 147 |
| 148 def testToPublishableResultFoundFalse(self): |
| 149 mock_host = 'https://host.com' |
| 150 self.mock(app_identity, 'get_default_version_hostname', lambda: mock_host) |
| 151 |
| 152 analysis_result = { |
| 153 'found': False, |
| 154 } |
| 155 |
| 156 processed_analysis_result = copy.deepcopy(analysis_result) |
| 157 processed_analysis_result['feedback_url'] = ( |
| 158 mock_host + '/crash/fracas-result-feedback?' |
| 159 'key=agx0ZXN0YmVkLXRlc3RyQQsSE0ZyYWNhc0NyYXNoQW5hbHlzaXMiKDMzNTY5MDU3' |
| 160 'M2ZlYTFlZGZhMjViOTVjZmI4OGZhODFlNDk0YTEyODkM') |
| 161 |
| 162 crash_identifiers = {'signature': 'sig'} |
| 163 expected_messages_data = { |
| 164 'crash_identifiers': crash_identifiers, |
| 165 'client_id': CrashClient.FRACAS, |
| 166 'result': processed_analysis_result, |
| 167 } |
| 168 |
| 169 analysis = FracasCrashAnalysis.Create(crash_identifiers) |
| 170 analysis.client_id = CrashClient.FRACAS |
| 171 analysis.result = analysis_result |
| 172 |
| 173 self.assertDictEqual(analysis.ToPublishableResult(crash_identifiers), |
| 174 expected_messages_data) |
| OLD | NEW |