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 5import unittest 6 7import mock 8import webapp2 9import webtest 10 11from dashboard import bisect_stats 12from dashboard import testing_common 13 14 15class BisectStatsTest(testing_common.TestCase): 16 17 def setUp(self): 18 super(BisectStatsTest, self).setUp() 19 app = webapp2.WSGIApplication( 20 [('/bisect_stats', bisect_stats.BisectStatsHandler)]) 21 self.testapp = webtest.TestApp(app) 22 23 @mock.patch.object( 24 bisect_stats, '_GetLastMondayTimestamp', 25 mock.MagicMock(return_value=1407110400000)) 26 def testGet(self): 27 bisect_stats.UpdateBisectStats('win_bot', 'failed') 28 bisect_stats.UpdateBisectStats('win_bot', 'failed') 29 bisect_stats.UpdateBisectStats('win_bot', 'completed') 30 bisect_stats.UpdateBisectStats('win_bot', 'completed') 31 bisect_stats.UpdateBisectStats('linux_bot', 'failed') 32 bisect_stats.UpdateBisectStats('linux_bot', 'completed') 33 bisect_stats.UpdateBisectStats('mac_bot', 'completed') 34 35 expected_series_data = { 36 'completed': { 37 'linux': [[1407110400000, 1]], 38 'mac': [[1407110400000, 1]], 39 'win': [[1407110400000, 2]], 40 }, 41 'failed': { 42 'linux': [[1407110400000, 1]], 43 'win': [[1407110400000, 2]], 44 }, 45 } 46 47 expected_total_series_data = { 48 'completed': [[1407110400000, 4]], 49 'failed': [[1407110400000, 3]], 50 } 51 52 response = self.testapp.get('/bisect_stats') 53 series_data = self.GetEmbeddedVariable(response, 'SERIES_DATA') 54 total_series_data = self.GetEmbeddedVariable( 55 response, 'TOTAL_SERIES_DATA') 56 57 self.assertEqual(expected_series_data, series_data) 58 self.assertEqual(expected_total_series_data, total_series_data) 59 60 61if __name__ == '__main__': 62 unittest.main() 63