Esempio n. 1
0
    def testBeacon(self):
        for test_set in all_test_sets.GetAllTestSets():
            # Don't test our larger (and therefore serially slower) tests in the SDK.
            if len(test_set.tests) > 100:
                continue

            category = test_set.category
            csrf_token = self.client.get('/get_csrf').content
            # Constructs a reasonably random result set
            results = [
                '%s=%s' %
                (test.key, random.randrange(test.min_value, test.max_value))
                for test in test_set.tests
            ]
            params = {
                'category': category,
                'results': ','.join(results),
                'csrf_token': csrf_token,
            }
            logging.info('params: %s' % params)
            response = self.client.get('/beacon', params,
                                       **mock_data.UNIT_TEST_UA)
            self.assertEqual('', response.content)
            self.assertEqual(204, response.status_code)

            # Did a ResultParent get created?
            query = db.Query(ResultParent)
            query.filter('category =', category)
            result_parent = query.get()
            self.assertNotEqual(result_parent, None)

            # Were the right number of ResultTimes created?
            result_times = result_parent.GetResultTimes()
            self.assertEqual(len(test_set.tests), len(result_times))
Esempio n. 2
0
 def testTestsDefinedWithRequireAttributes(self):
     for test_set in all_test_sets.GetAllTestSets():
         # Make sure category name is a string and that it is capitalized.
         self.assert_(len(test_set.tests))
         for test in test_set.tests:
             for attr in ('key', 'name', 'url', 'score_type', 'doc',
                          'min_value', 'max_value'):
                 self.assert_(hasattr(test, attr))
Esempio n. 3
0
 def testCategoryNamesCapitalized(self):
     for test_set in all_test_sets.GetAllTestSets():
         # Make sure category name is a string and that it is capitalized.
         self.assertEqual(
             ' '.join([
                 '%s%s' % (x[0].capitalize(), x[1:])
                 for x in test_set.category_name.split(' ')
             ]), test_set.category_name)
Esempio n. 4
0
 def testAboutPageWorks(self):
     client = Client()
     for test_set in all_test_sets.GetAllTestSets():
         category = test_set.category
         logging.info('category: %s' % category)
         response = self.client.get('/%s/about' % category, {},
                                    **mock_data.UNIT_TEST_UA)
         self.assertEqual(200, response.status_code,
                          'No about for %s' % category)
Esempio n. 5
0
def DumpScores(db):
    cursor = db.cursor()
    cursor.execute(CREATE_TEMP_SCORES_SQL)
    cursor.execute(TEMP_CATEGORY_COUNTS_SQL)
    for category, count in cursor.fetchall():
        logging.info("Num scores for category, %s: %s", category, count)
    cursor.execute(BROWSERS_SQL)
    browser_parts = cursor.fetchall()
    for test_set in all_test_sets.GetAllTestSets():
        category = test_set.category
        logging.info("Dump scores for category: %s", category)
        for family, v1, v2, v3 in browser_parts:
            v_clauses = ''
            for column, value in (('v1', v1), ('v2', v2), ('v3', v3)):
                if value is None:
                    v_clauses += ' AND %s IS NULL' % column
                else:
                    v_clauses += ' AND %s = "%s"' % (column, value)
            max_num_scores = 0
            medians = []
            for test in test_set.tests:
                sql_params = {
                    'category': category,
                    'test': test.key,
                    'family': family,
                }
                sql = TEMP_SCORES_SQL % {
                    'columns': 'count(*)',
                    'v_clauses': v_clauses,
                    'limit_clause': '',
                }
                sql = re.sub(r'\s+', ' ', sql)
                #print sql, str(sql_params)
                cursor.execute(sql, sql_params)
                num_scores = cursor.fetchone()[0]
                if num_scores:
                    max_num_scores = max(max_num_scores, num_scores)
                    sql = TEMP_SCORES_SQL % {
                        'columns': 'score',
                        'v_clauses': v_clauses,
                        'limit_clause': 'limit %d,1' % (num_scores / 2),
                    }
                    #print sql, str(sql_params)
                    cursor.execute(sql, sql_params)
                    medians.append(cursor.fetchone()[0])
                else:
                    medians.append(None)
            if max_num_scores > 0:
                print '%s,"%s",%s,%s' % (
                    category, pretty_print(family, v1, v2, v3), ','.join(
                        map(str, medians)), max_num_scores)
Esempio n. 6
0
def GetCategories():
    return [test_set.category for test_set in all_test_sets.GetAllTestSets()]
Esempio n. 7
0
 def testTestPageWorks(self):
     for test_set in all_test_sets.GetAllTestSets():
         response = self.client.get('/%s/test' % test_set.category, {},
                                    **mock_data.UNIT_TEST_UA)
         self.assertEqual(200, response.status_code)
Esempio n. 8
0
 def testCategoriesMatch(self):
     self.assertEqual(settings.CATEGORIES + settings.CATEGORIES_BETA,
                      [x.category for x in all_test_sets.GetAllTestSets()])