Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 base64 | 5 import base64 |
| 6 import json | 6 import json |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 | 9 |
| 10 import webapp2 | 10 import webapp2 |
| 11 import webtest | 11 import webtest |
| 12 | 12 |
| 13 from crash import crash_pipeline | 13 from crash import crash_pipeline |
| 14 from crash.findit import Findit | |
| 14 from crash.test.crash_testcase import CrashTestCase | 15 from crash.test.crash_testcase import CrashTestCase |
| 15 from handlers.crash import crash_handler | 16 from handlers.crash import crash_handler |
| 16 | 17 |
| 17 | 18 |
| 18 class CrashHandlerTest(CrashTestCase): | 19 class CrashHandlerTest(CrashTestCase): |
| 19 app_module = webapp2.WSGIApplication([ | 20 app_module = webapp2.WSGIApplication([ |
| 20 ('/_ah/push-handlers/crash/fracas', crash_handler.CrashHandler), | 21 ('/_ah/push-handlers/crash/fracas', crash_handler.CrashHandler), |
| 21 ], debug=True) | 22 ], debug=True) |
| 22 | 23 |
| 23 def _MockScheduleNewAnalysisForCrash(self, requested_crashes): | |
| 24 def Mocked_ScheduleNewAnalysisForCrash(*crash_data, **_): | |
| 25 requested_crashes.append(crash_data) | |
| 26 self.mock(crash_pipeline, 'ScheduleNewAnalysisForCrash', | |
| 27 Mocked_ScheduleNewAnalysisForCrash) | |
| 28 | |
| 29 def testAnalysisScheduled(self): | 24 def testAnalysisScheduled(self): |
| 30 requested_crashes = [] | 25 requested_crashes = [] |
| 31 self._MockScheduleNewAnalysisForCrash(requested_crashes) | 26 # TODO(wrengr): the old test mocked the function directly, but since |
| 27 # we moved it to a method that's impossible. So how to we make sure | |
| 28 # things get dispatched to this mock? It doesn't look like it was | |
| 29 # called from anywhere... | |
| 30 class _MockFindit(Findit): | |
| 31 def ScheduleNewAnalysis(self, crash_data, **_): | |
| 32 requested_crashes.append(crash_data) | |
| 33 | |
| 32 self.mock_current_user(user_email='test@chromium.org', is_admin=True) | 34 self.mock_current_user(user_email='test@chromium.org', is_admin=True) |
| 33 | 35 |
| 34 client_id = 'fracas' | 36 client_id = 'fracas' |
| 35 channel = 'supported_channel' | 37 channel = 'supported_channel' |
| 36 platform = 'supported_platform' | 38 platform = 'supported_platform' |
| 37 signature = 'signature/here' | 39 signature = 'signature/here' |
| 38 stack_trace = 'frame1\nframe2\nframe3' | 40 stack_trace = 'frame1\nframe2\nframe3' |
| 39 chrome_version = '50.2500.0.0' | 41 chrome_version = '50.2500.0.0' |
| 40 historic_metadata = [{'chrome_version': '50.2500.0.0', 'cpm': 0.6}] | 42 historical_metadata = [{'chrome_version': '50.2500.0.0', 'cpm': 0.6}] |
| 41 | 43 |
| 42 crash_identifiers = { | 44 crash_identifiers = { |
| 43 'chrome_version': chrome_version, | 45 'chrome_version': chrome_version, |
| 44 'signature': signature, | 46 'signature': signature, |
| 45 'channel': channel, | 47 'channel': channel, |
| 46 'platform': platform, | 48 'platform': platform, |
| 47 'process_type': 'renderer' | 49 'process_type': 'renderer' |
| 48 } | 50 } |
| 49 | 51 |
| 50 request_json_data = { | 52 request_json_data = { |
| 51 'message': { | 53 'message': { |
| 52 'data': base64.b64encode(json.dumps({ | 54 'data': base64.b64encode(json.dumps({ |
| 53 'customized_data': { | 55 'customized_data': { |
| 54 'channel': 'supported_channel', | 56 'channel': channel, |
| 55 'historical_metadata': [ | 57 'historical_metadata': historical_metadata, |
| 56 { | |
| 57 'chrome_version': '50.2500.0.0', | |
| 58 'cpm': 0.6 | |
| 59 }, | |
| 60 ] | |
| 61 }, | 58 }, |
| 62 'chrome_version': '50.2500.0.0', | 59 'chrome_version': chrome_version, |
| 63 'signature': 'signature/here', | 60 'signature': signature, |
| 64 'client_id': 'fracas', | 61 'client_id': client_id, |
| 65 'platform': 'supported_platform', | 62 'platform': platform, |
| 66 'crash_identifiers': { | 63 'crash_identifiers': { |
| 67 'chrome_version': '50.2500.0.0', | 64 'chrome_version': chrome_version, |
| 68 'signature': 'signature/here', | 65 'signature': signature, |
| 69 'channel': 'supported_channel', | 66 'channel': channel, |
| 70 'platform': 'supported_platform', | 67 'platform': platform, |
| 71 'process_type': 'renderer' | 68 'process_type': 'renderer', |
| 72 }, | 69 }, |
| 73 'stack_trace': 'frame1\nframe2\nframe3' | 70 'stack_trace': stack_trace, |
| 74 })), | 71 })), |
| 75 'message_id': 'id', | 72 'message_id': 'id', |
| 76 }, | 73 }, |
| 77 'subscription': 'subscription', | 74 'subscription': 'subscription', |
| 78 } | 75 } |
| 79 | 76 |
| 80 self.test_app.post_json('/_ah/push-handlers/crash/fracas', | 77 self.test_app.post_json('/_ah/push-handlers/crash/fracas', |
| 81 request_json_data) | 78 request_json_data) |
| 82 | 79 |
| 83 self.assertEqual(1, len(requested_crashes)) | 80 self.assertEqual(1, len(requested_crashes)) |
|
wrengr
2016/10/18 23:28:10
The mocking of ScheduleNewAnalysis isn't working h
Sharu Jiang
2016/10/19 00:53:07
"/usr/local/google/home/wrengr/chromium-srcs/infra
wrengr
2016/10/19 18:05:16
Except that it's 'crashed_version' for everyone el
Sharu Jiang
2016/10/19 21:03:09
Right, the name is not consistent..., however chan
| |
| 84 self.assertEqual( | 81 self.assertEqual( |
| 85 (crash_identifiers, chrome_version, signature, client_id, | 82 (crash_identifiers, chrome_version, signature, client_id, |
| 86 platform, stack_trace, {'channel': channel, | 83 platform, stack_trace, {'channel': channel, |
| 87 'historical_metadata': historic_metadata}), | 84 'historical_metadata': historical_metadata}), |
| 88 requested_crashes[0]) | 85 requested_crashes[0]) |
| OLD | NEW |