Explicit server calls for test paths and test names.
authorMark Cote <mcote@mozilla.com>
Thu, 01 Sep 2011 16:10:59 -0400
changeset 65 0616da69cc665b6984e17947d6586158d07f00af
parent 64 e8095fecb05c494c3c99679777328c8d6c8989a0
child 66 7f1c1b1f88b51778ddbed9360b3440c805151376
push id63
push usermcote@mozilla.com
push dateThu, 01 Sep 2011 20:11:05 +0000
Explicit server calls for test paths and test names.
client/speedtests.py
server/handlers.py
--- a/client/speedtests.py
+++ b/client/speedtests.py
@@ -588,17 +588,17 @@ def main():
     # start tests in specified browsers.  if none given, run all.
     url_prefix = config.local_test_base_url + '/start.html?ip=%s&port=%d' % (config.local_ip, config.local_port)
     if config.testmode:
         url_prefix += '&test=true'
     url_prefix += '&testUrl='
     if not options.tests:
         print 'Getting test list from server...'
         try:
-            tests_url = config.server_api_url + '/tests/'
+            tests_url = config.server_api_url + '/testpaths/'
             print 'Getting test list from %s...' % tests_url
             options.tests = json.loads(urllib2.urlopen(tests_url).read())
         except urllib2.HTTPError, e:
             sys.stderr.write('Could not get test list: %s\n' % e)
             sys.exit(errno.EPERM)
         except urllib2.URLError, e:
             sys.stderr.write('Could not get test list: %s\n' % e.reason)
             sys.exit(e.reason.errno)
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -33,45 +33,51 @@ try:
     RESULTS_ONLY = cfg.get('speedtests', 'results only')
 except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
     RESULTS_ONLY = False
 
 
 db = web.database(dbn='mysql', db='speedtests', user='speedtests',
                   pw='speedtests')
 
-urls = ['/testresults/', 'TestResults']
-if not RESULTS_ONLY:
-    urls.extend([
-        '/tests/', 'TestList',
-        ])
-
+urls = ('/testresults/', 'TestResults',
+        '/machines/', 'Machines',
+        '/testnames/', 'TestNames',
+        '/testpaths/', 'TestPaths')
 
 def query_params():
     params = {}
     if web.ctx.query:
         for q in web.ctx.query[1:].split('&'):
             name, equals, value = q.partition('=')
             if equals:
                 params[name] = value
     return params
                     
 
-def test_list():
+def test_paths():
     """ List of relative paths of test index files. """
     tests = []
     for d in os.listdir(HTML_DIR):
         for f in ('index.html', 'Default.html'):
             if os.path.exists(os.path.join(HTML_DIR, d, f)):
                 tests.append(os.path.join(d, f))
                 break
     tests.sort()
     return tests
 
 
+def test_names():
+    tests = filter(lambda x: x != 'browser',
+                   map(lambda x: x['Tables_in_speedtests'],
+                       db.query('show tables')))
+    tests.sort()
+    return tests
+
+
 def get_browser_id(ua):
     ua = ua.lower()
     platform = 'unknown'
     geckover = 'n/a'
     buildid = 'unknown'
     browserid = 0
     
     if 'firefox' in ua:
@@ -119,21 +125,30 @@ def get_browser_id(ua):
         }
     browser = db.select('browser', where=web.db.sqlwhere(wheredict))
     if not browser:
         db.insert('browser', **wheredict)
         browser = db.select('browser', where=web.db.sqlwhere(wheredict))
     return browser[0].id
         
 
-class TestList(object):
+class TestPaths(object):
+
+    """ Paths of locally served tests. """
 
     @templeton.handlers.json_response
     def GET(self):
-        return test_list()
+        return test_paths()
+
+
+class TestNames(object):
+
+    @templeton.handlers.json_response
+    def GET(self):
+        return test_names()
 
 
 class TestResults(object):
 
     def proxy_request(self):
         headers = {
             'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
             'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
@@ -161,17 +176,17 @@ class TestResults(object):
 
     @templeton.handlers.json_response
     def GET(self):
         args, body = templeton.handlers.get_request_parms()
         tables = args.get('testname', None)
         start = args.get('start', None)
         end = args.get('end', None)
         if not tables:
-            tables = map(lambda x: os.path.dirname(x), test_list())
+            tables = test_names()
         response = {}
         for t in tables:
             wheres = []
             vars = {}
             if start:
                 vars['start'] = start[0]
                 wheres.append('teststart >= $start')
             if end: