| 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 datetime | 5 import datetime |
| 6 import json | 6 import json |
| 7 import mock | 7 import mock |
| 8 import urllib2 | 8 import urllib2 |
| 9 | 9 |
| 10 from google.appengine.datastore import datastore_stub_util | 10 from google.appengine.datastore import datastore_stub_util |
| 11 from google.appengine.ext import ndb | 11 from google.appengine.ext import ndb |
| 12 | 12 |
| 13 import main # Fiddles sys.path so must come first. | 13 import main # Fiddles sys.path so must come first. |
| 14 | 14 |
| 15 from apiclient.errors import HttpError |
| 15 import gae_ts_mon | 16 import gae_ts_mon |
| 16 from handlers.flake_issues import ProcessIssue, CreateFlakyRun | 17 from handlers.flake_issues import ProcessIssue, CreateFlakyRun |
| 17 from model.flake import Flake, FlakyRun, FlakeOccurrence | 18 from model.flake import Flake, FlakyRun, FlakeOccurrence |
| 18 from model.build_run import PatchsetBuilderRuns, BuildRun | 19 from model.build_run import PatchsetBuilderRuns, BuildRun |
| 19 from testing_utils import testing | 20 from testing_utils import testing |
| 20 from time_functions.testing import mock_datetime_utc | 21 from time_functions.testing import mock_datetime_utc |
| 21 | 22 |
| 22 | 23 |
| 23 TEST_TEST_RESULTS_REPLY = json.dumps({ | 24 TEST_TEST_RESULTS_REPLY = json.dumps({ |
| 24 'tests': { | 25 'tests': { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 self.issues = {} | 140 self.issues = {} |
| 140 self.next_issue_id = 100000 | 141 self.next_issue_id = 100000 |
| 141 | 142 |
| 142 def create(self, issue): | 143 def create(self, issue): |
| 143 issue.id = self.next_issue_id | 144 issue.id = self.next_issue_id |
| 144 self.next_issue_id += 1 | 145 self.next_issue_id += 1 |
| 145 self.issues[issue.id] = issue | 146 self.issues[issue.id] = issue |
| 146 return issue | 147 return issue |
| 147 | 148 |
| 148 def getIssue(self, issue_id): | 149 def getIssue(self, issue_id): |
| 150 if issue_id not in self.issues: |
| 151 raise HttpError(mock.Mock(status=404), '') |
| 149 return self.issues[issue_id] | 152 return self.issues[issue_id] |
| 150 | 153 |
| 151 def getComments(self, issue_id): | 154 def getComments(self, issue_id): |
| 152 return self.issues[issue_id].comments | 155 return self.issues[issue_id].comments |
| 153 | 156 |
| 154 def update(self, issue, comment): | 157 def update(self, issue, comment): |
| 155 self.issues[issue.id] = issue | 158 self.issues[issue.id] = issue |
| 156 issue.comments.append( | 159 issue.comments.append( |
| 157 MockComment(datetime.datetime.utcnow(), 'app@ae.org', comment)) | 160 MockComment(datetime.datetime.utcnow(), 'app@ae.org', comment)) |
| 158 | 161 |
| (...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 | 1026 |
| 1024 def test_only_chromium_users_are_allowed_to_change(self): | 1027 def test_only_chromium_users_are_allowed_to_change(self): |
| 1025 self.mock_current_user(user_email='someone@evil-site.com') | 1028 self.mock_current_user(user_email='someone@evil-site.com') |
| 1026 self.test_app.get('/override_issue_id?key=123&issue_id=0', status=401) | 1029 self.test_app.get('/override_issue_id?key=123&issue_id=0', status=401) |
| 1027 | 1030 |
| 1028 def test_validates_issue_id(self): | 1031 def test_validates_issue_id(self): |
| 1029 self.test_app.get('/override_issue_id?issue_id=foobar', status=400) | 1032 self.test_app.get('/override_issue_id?issue_id=foobar', status=400) |
| 1030 self.test_app.get('/override_issue_id?issue_id=-5', status=400) | 1033 self.test_app.get('/override_issue_id?issue_id=-5', status=400) |
| 1031 | 1034 |
| 1032 def test_checks_issue_is_on_crbug(self): | 1035 def test_checks_issue_is_on_crbug(self): |
| 1033 self.test_app.get('/override_issue_id?issue_id=200', status=400) | 1036 self.test_app.get('/override_issue_id?issue_id=200', status=404) |
| 1037 |
| 1038 def test_returns_500_on_non_404_error_from_monorail(self): |
| 1039 self.mock_api.getIssue = mock.Mock( |
| 1040 side_effect=HttpError(mock.Mock(status=500), '')) |
| 1041 self.test_app.get('/override_issue_id?issue_id=200', status=500) |
| 1034 | 1042 |
| 1035 def test_overrides_issue_id(self): | 1043 def test_overrides_issue_id(self): |
| 1036 issue = self.mock_api.create(MockIssue({})) | 1044 issue = self.mock_api.create(MockIssue({})) |
| 1037 key = Flake(name='foobar', issue_id=issue.id).put() | 1045 key = Flake(name='foobar', issue_id=issue.id).put() |
| 1038 self.test_app.get( | 1046 self.test_app.get( |
| 1039 '/override_issue_id?key=%s&issue_id=%d' % (key.urlsafe(), issue.id)) | 1047 '/override_issue_id?key=%s&issue_id=%d' % (key.urlsafe(), issue.id)) |
| 1040 self.assertEqual(key.get().issue_id, issue.id) | 1048 self.assertEqual(key.get().issue_id, issue.id) |
| 1041 | 1049 |
| 1042 def test_overrides_issue_id_with_0(self): | 1050 def test_overrides_issue_id_with_0(self): |
| 1043 key = Flake(name='foobar', issue_id=100000).put() | 1051 key = Flake(name='foobar', issue_id=100000).put() |
| 1044 self.test_app.get( | 1052 self.test_app.get( |
| 1045 '/override_issue_id?key=%s&issue_id=0' % key.urlsafe()) | 1053 '/override_issue_id?key=%s&issue_id=0' % key.urlsafe()) |
| 1046 self.assertEqual(key.get().issue_id, 0) | 1054 self.assertEqual(key.get().issue_id, 0) |
| OLD | NEW |