| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2015 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 import calendar |
| 5 import base64 |
| 6 import copy |
| 7 from datetime import datetime |
| 8 from datetime import time |
| 9 from datetime import timedelta |
| 10 import json |
| 11 |
| 12 from google.appengine.api import users |
| 13 import webapp2 |
| 14 |
| 15 from testing_utils import testing |
| 16 |
| 17 from common import time_util |
| 18 from handlers.crash import fracas_result_feedback |
| 19 from model import analysis_status |
| 20 from model import result_status |
| 21 from model import triage_status |
| 22 from model.crash.fracas_crash_analysis import FracasCrashAnalysis |
| 23 |
| 24 |
| 25 class FracasResultFeedbackTest(testing.AppengineTestCase): |
| 26 app_module = webapp2.WSGIApplication( |
| 27 [('/fracas-result-feedback', |
| 28 fracas_result_feedback.FracasResultFeedback)], debug=True) |
| 29 |
| 30 def setUp(self): |
| 31 super(FracasResultFeedbackTest, self).setUp() |
| 32 analysis = FracasCrashAnalysis.Create({'signature': 'signature'}) |
| 33 analysis.signature = 'signature' |
| 34 analysis.crashed_version = '53.0.2750.0' |
| 35 analysis.stack_trace = 'dummy\nframe1\nframe2' |
| 36 analysis.platform = 'android' |
| 37 analysis.channel = 'canary' |
| 38 analysis.client_id = 'fracas' |
| 39 analysis.status = analysis_status.COMPLETED |
| 40 analysis.historical_metadata = [ |
| 41 {'chrome_version': '53.0.2748.0', 'cpm': 0}, |
| 42 {'chrome_version': '53.0.2749.0', 'cpm': 0}, |
| 43 {'chrome_version': '53.0.2750.0', 'cpm': 0.8} |
| 44 ] |
| 45 |
| 46 suspected_cl = { |
| 47 'url': 'https://chromium.googlesource.com/chromium/src/+/346a', |
| 48 'review_url': 'https://review', |
| 49 'revision': '346a', |
| 50 'project_path': 'src/', |
| 51 'author': 'a@chromium.org', |
| 52 'time': '2016-06-04 00:00:00 UTC', |
| 53 'reason': 'some reason', |
| 54 'confidence': 1 |
| 55 } |
| 56 analysis.result = {'found': True, |
| 57 'suspected_cls': [suspected_cl], |
| 58 'suspected_components': ['Blink>API', 'Blink>DOM'], |
| 59 'suspected_project': 'chromium', |
| 60 'regression_range': ['53.0.2749.0', '53.0.2750.0']} |
| 61 analysis.found_suspects = True |
| 62 analysis.note = 'This is a note.' |
| 63 analysis.put() |
| 64 |
| 65 self.analysis = analysis |
| 66 |
| 67 def testFracasDashBoardHandler(self): |
| 68 response = self.test_app.get('/fracas-result-feedback?key=%s' % |
| 69 self.analysis.key.urlsafe()) |
| 70 self.assertEqual(200, response.status_int) |
| 71 |
| 72 def _GenerateDisplayData(self): |
| 73 analysis = self.analysis |
| 74 return { |
| 75 'signature': analysis.signature, |
| 76 'version': analysis.crashed_version, |
| 77 'channel': analysis.channel, |
| 78 'platform': analysis.platform, |
| 79 'regression_range': ( |
| 80 analysis.result['regression_range'] if 'regression_range' in |
| 81 analysis.result else None), |
| 82 'culprit_regression_range': analysis.culprit_regression_range, |
| 83 'historical_metadata': analysis.historical_metadata, |
| 84 'stack_trace': analysis.stack_trace, |
| 85 'suspected_cls': ( |
| 86 analysis.result['suspected_cls'] if 'suspected_cls' in |
| 87 analysis.result else None), |
| 88 'culprit_cls': analysis.culprit_cls, |
| 89 'suspected_project': ( |
| 90 analysis.result['suspected_project'] if 'suspected_project' in |
| 91 analysis.result else None), |
| 92 'culprit_project': analysis.culprit_project, |
| 93 'suspected_components': ( |
| 94 analysis.result['suspected_components'] if 'suspected_components' |
| 95 in analysis.result else None), |
| 96 'culprit_components': analysis.culprit_components, |
| 97 'request_time': time_util.FormatDatetime(analysis.requested_time), |
| 98 'triage_history': fracas_result_feedback._GetTriageHistory(analysis), |
| 99 'analysis_completed': analysis.completed, |
| 100 'analysis_failed': analysis.failed, |
| 101 'analysis_correct': { |
| 102 'regression_range': analysis.regression_range_triage_status, |
| 103 'suspected_cls': analysis.suspected_cls_triage_status, |
| 104 'suspected_project': analysis.suspected_project_triage_status, |
| 105 'suspected_components': analysis.suspected_components_triage_status, |
| 106 }, |
| 107 'note': analysis.note, |
| 108 'key': analysis.key.urlsafe(), |
| 109 } |
| 110 |
| 111 def testDisplayAnanlysisResult(self): |
| 112 expected_result = self._GenerateDisplayData() |
| 113 response_json = self.test_app.get('/fracas-result-feedback?format=json&' |
| 114 'key=%s' % self.analysis.key.urlsafe()) |
| 115 self.assertEqual(200, response_json.status_int) |
| 116 self.assertEqual(expected_result, response_json.json_body) |
| 117 |
| 118 def testDisplayTriageHistory(self): |
| 119 |
| 120 def _MockIsCurrectUserAdmin(*_): |
| 121 return True |
| 122 |
| 123 self.mock(users, 'is_current_user_admin', _MockIsCurrectUserAdmin) |
| 124 |
| 125 self.analysis.triage_history = [{ |
| 126 'triage_timestamp': calendar.timegm(datetime.utcnow().timetuple()), |
| 127 'result_property': 'regression_range', |
| 128 'user_name': 'test', |
| 129 'triage_status': triage_status.TRIAGED_CORRECT |
| 130 }] |
| 131 self.analysis.put() |
| 132 expected_result = self._GenerateDisplayData() |
| 133 response_json = self.test_app.get('/fracas-result-feedback?format=json&' |
| 134 'key=%s' % self.analysis.key.urlsafe()) |
| 135 self.assertEqual(200, response_json.status_int) |
| 136 self.assertEqual(expected_result, response_json.json_body) |
| 137 |
| 138 |
| OLD | NEW |