| 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 from datetime import datetime | 6 from datetime import datetime |
| 7 | 7 |
| 8 from google.appengine.api import app_identity | |
| 9 | |
| 10 from crash.type_enums import CrashClient | 8 from crash.type_enums import CrashClient |
| 11 from crash.test.crash_testcase import CrashTestCase | 9 from crash.test.crash_testcase import CrashTestCase |
| 12 from model import analysis_status | 10 from model import analysis_status |
| 13 from model import result_status | 11 from model import result_status |
| 14 from model import triage_status | 12 from model import triage_status |
| 15 from model.crash.crash_analysis import CrashAnalysis | 13 from model.crash.crash_analysis import CrashAnalysis |
| 16 from model.crash.fracas_crash_analysis import FracasCrashAnalysis | 14 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 17 | 15 |
| 18 | 16 |
| 19 class CrashAnalysisTest(CrashTestCase): | 17 class CrashAnalysisTest(CrashTestCase): |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 analysis = CrashAnalysis() | 97 analysis = CrashAnalysis() |
| 100 analysis.Update(update) | 98 analysis.Update(update) |
| 101 self.assertFalse(hasattr(analysis, 'dummy')) | 99 self.assertFalse(hasattr(analysis, 'dummy')) |
| 102 | 100 |
| 103 def testCreateCrashAnalysis(self): | 101 def testCreateCrashAnalysis(self): |
| 104 crash_identifiers = {'signature': 'sig'} | 102 crash_identifiers = {'signature': 'sig'} |
| 105 analysis = CrashAnalysis.Create(crash_identifiers) | 103 analysis = CrashAnalysis.Create(crash_identifiers) |
| 106 analysis.put() | 104 analysis.put() |
| 107 self.assertIsNotNone(analysis) | 105 self.assertIsNotNone(analysis) |
| 108 self.assertEqual(CrashAnalysis.Get(crash_identifiers), analysis) | 106 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 |