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 3# found in the LICENSE file. 4 5import webapp2 6import webtest 7 8# pylint: disable=unused-import 9from dashboard import mock_oauth2_decorator 10# pylint: enable=unused-import 11 12from google.appengine.api import users 13 14from dashboard import bad_bisect 15from dashboard import quick_logger 16from dashboard import testing_common 17from dashboard import xsrf 18from dashboard.models import try_job 19 20 21class BadBisectHandlerTest(testing_common.TestCase): 22 23 def setUp(self): 24 super(BadBisectHandlerTest, self).setUp() 25 app = webapp2.WSGIApplication([ 26 ('/bad_bisect', 27 bad_bisect.BadBisectHandler)]) 28 self.testapp = webtest.TestApp(app) 29 testing_common.SetSheriffDomains(['chromium.org']) 30 testing_common.SetIsInternalUser('test@chromium.com', True) 31 self.SetCurrentUser('test@chromium.org') 32 try_job.TryJob(id=1234).put() 33 34 def testGet_WithNoTryJobId_ShowsError(self): 35 response = self.testapp.get('/bad_bisect') 36 self.assertIn('<h1 class="error">', response.body) 37 38 def testGet_NotLoggedIn_ShowsError(self): 39 self.UnsetCurrentUser() 40 self.testapp.get('/bad_bisect?', {'try_job_id': '1234'}) 41 response = self.testapp.get('/bad_bisect') 42 self.assertEqual(302, response.status_code) 43 44 def testGet_RenderForm(self): 45 response = self.testapp.get('/bad_bisect?', {'try_job_id': '1234'}) 46 self.assertEqual(1, len(response.html('form'))) 47 self.assertIn('1234', response.body) 48 49 def testPost_FeedbackRecorded(self): 50 self.testapp.post('/bad_bisect?', { 51 'try_job_id': '1234', 52 'xsrf_token': xsrf.GenerateToken(users.get_current_user()), 53 }) 54 jobs = try_job.TryJob.query().fetch() 55 self.assertEqual(1, len(jobs)) 56 self.assertEqual({'test@chromium.org'}, jobs[0].bad_result_emails) 57 58 def testPost_LogAdded(self): 59 self.testapp.post('/bad_bisect?', { 60 'try_job_id': '1234', 61 'xsrf_token': xsrf.GenerateToken(users.get_current_user()), 62 }) 63 logs = quick_logger.Get('bad_bisect', 'report') 64 self.assertEqual(1, len(logs)) 65