def testBasic(self):
        test_key_browsers = (
            ('apple', 'Firefox 3.0'),
            ('coconut', 'Firefox 3.0'),
        )
        ranker_values = (
            (1, 5, '2|3'),
            (101, 7, '101|99|101|2|988|3|101'),
        )
        params = {
            'category': self.test_set.category,
            'test_key_browsers_json': simplejson.dumps(test_key_browsers),
            'ranker_values_json': simplejson.dumps(ranker_values),
            'time_limit': 10,
        }
        time.clock().AndReturn(0)
        test_browsers = [
            (self.apple_test, 'Firefox 3.0'),
            (self.coconut_test, 'Firefox 3.0'),
        ]
        result_ranker.GetOrCreateRankers(test_browsers, None).AndReturn(
            [self.apple_ranker, self.coconut_ranker])
        time.clock().AndReturn(0.5)
        self.apple_ranker.GetMedianAndNumScores().AndReturn((1, 2))
        self.apple_ranker.SetValues([2, 3], 5)
        time.clock().AndReturn(1)  # under timelimit
        self.coconut_ranker.GetMedianAndNumScores().AndReturn((50, 5))
        self.coconut_ranker.SetValues([101, 99, 101, 2, 988, 3, 101], 7)

        self.mox.ReplayAll()
        response = self.client.get('/admin/rankers/upload', params)
        self.mox.VerifyAll()
        self.assertEqual(simplejson.dumps({}), response.content)
        self.assertEqual(200, response.status_code)
Example #2
0
def UploadRankers(request):
    """Rebuild rankers."""
    time_limit = int(request.REQUEST.get('time_limit', 8))
    category = request.REQUEST.get('category')
    params_str = request.REQUEST.get('params_str')
    test_key_browsers_json = request.REQUEST.get('test_key_browsers_json')
    ranker_values_json = request.REQUEST.get('ranker_values_json')

    if not category:
        return http.HttpResponseServerError('Must send "category".')
    if not test_key_browsers_json:
        return http.HttpResponseServerError(
            'Must send "test_key_browsers_json".')
    if not ranker_values_json:
        return http.HttpResponseServerError('Must send "ranker_values_json".')

    test_key_browsers = simplejson.loads(test_key_browsers_json)
    ranker_values = simplejson.loads(ranker_values_json)
    start_time = time.clock()

    message = None
    test_set = all_test_sets.GetTestSet(category)
    test_browsers = [(test_set.GetTest(test_key), browser)
                     for test_key, browser in test_key_browsers]
    rankers = result_ranker.GetOrCreateRankers(test_browsers, params_str)

    for ranker, (median, num_scores,
                 values_str) in zip(rankers, ranker_values):
        if time.clock() - start_time > time_limit:
            message = 'Over time limit'
            break
        if ranker.GetMedianAndNumScores() == (median, num_scores):
            logging.info('Skipping ranker with unchanged values: %s',
                         ranker.key().name())
            continue
        values = map(int, values_str.split('|'))
        try:
            ranker.SetValues(values, num_scores)
        except db.Timeout:
            message = 'db.Timeout'
            break
    response_params = {}
    if message:
        logging.info('message: %s', message)
        response_params['message'] = message
    return http.HttpResponse(simplejson.dumps(response_params))
 def testSkipUnchangedValues(self):
     test_key_browsers = (
         ('apple', 'Firefox 3.0'),
         ('coconut', 'Firefox 3.0'),
     )
     ranker_values = (
         (1, 5, '2|3'),
         (101, 7, '101|99|101|2|988|3|101'),
     )
     params = {
         'category': self.test_set.category,
         'test_key_browsers_json': simplejson.dumps(test_key_browsers),
         'ranker_values_json': simplejson.dumps(ranker_values),
         'time_limit': 10,
     }
     time.clock().AndReturn(0)
     test_browsers = [
         (self.apple_test, 'Firefox 3.0'),
         (self.coconut_test, 'Firefox 3.0'),
     ]
     result_ranker.GetOrCreateRankers(test_browsers, None).AndReturn(
         [self.apple_ranker, self.coconut_ranker])
     time.clock().AndReturn(0.5)
     self.apple_ranker.GetMedianAndNumScores().AndReturn((1, 5))
     self.apple_ranker.key().AndReturn(self.apple_ranker_key)
     self.apple_ranker_key.name().AndReturn('appl')
     time.clock().AndReturn(1)
     self.coconut_ranker.GetMedianAndNumScores().AndReturn((101, 7))
     self.coconut_ranker.key().AndReturn(self.coconut_ranker_key)
     self.coconut_ranker_key.name().AndReturn('coco')
     self.mox.ReplayAll()
     response = self.client.get('/admin/rankers/upload', params)
     logging.info('response: %s', response)
     self.mox.VerifyAll()
     self.assertEqual('{}', response.content)
     self.assertEqual(200, response.status_code)
Example #4
0
 def GetOrCreateRankers(self, browsers, params_str=None):
   test_browsers = [(self, b) for b in browsers]
   return result_ranker.GetOrCreateRankers(test_browsers, params_str)