1# Copyright (c) 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 json 6import os 7 8import dashboard_project 9 10import webapp2 11from webapp2 import Route 12 13 14def _RelPathToUnixPath(p): 15 return p.replace(os.sep, '/') 16 17 18class TestListHandler(webapp2.RequestHandler): 19 20 def get(self, *args, **kwargs): # pylint: disable=unused-argument 21 project = dashboard_project.DashboardProject() 22 test_relpaths = ['/' + _RelPathToUnixPath(x) 23 for x in project.FindAllTestModuleRelPaths()] 24 25 tests = {'test_relpaths': test_relpaths} 26 tests_as_json = json.dumps(tests) 27 self.response.content_type = 'application/json' 28 return self.response.write(tests_as_json) 29 30 31class DashboardDevServerConfig(object): 32 33 def __init__(self): 34 self.project = dashboard_project.DashboardProject() 35 36 def GetName(self): 37 return 'dashboard' 38 39 def GetRunUnitTestsUrl(self): 40 return '/dashboard/tests.html' 41 42 def AddOptionstToArgParseGroup(self, g): 43 g.add_argument('--dashboard-data-dir', 44 default=self.project.dashboard_test_data_path) 45 46 def GetRoutes(self, args): # pylint: disable=unused-argument 47 return [ 48 Route('/dashboard/tests', TestListHandler), 49 ] 50 51 def GetSourcePaths(self, args): # pylint: disable=unused-argument 52 return list(self.project.source_paths) 53 54 def GetTestDataPaths(self, args): # pylint: disable=unused-argument 55 return [ 56 ('/dashboard/test_data/', args.data_dir), 57 ] 58