ensure TKO custom fields work with the "extra_info" feature in get_latest_tests. adding tests for get_status_counts and get_latest_tests while i'm at it -- they we're previously untestable, but i recently added a mechanism to implement "if" in sqlite, making them testable
Signed-off-by: Steve Howard <[email protected]> --- autotest/frontend/tko/rpc_interface.py 2010-01-15 13:43:01.000000000 -0800 +++ autotest/frontend/tko/rpc_interface.py 2010-01-15 13:43:01.000000000 -0800 @@ -85,14 +85,17 @@ """ Similar to get_status_counts, but return only the latest test result per group. It still returns the same information (i.e. with pass count etc.) - for compatibility. + for compatibility. It includes an additional field "test_idx" with each + group. @param extra_info a list containing the field names that should be returned with each cell. The fields are returned in the extra_info field of the return dictionary. """ # find latest test per group - query = models.TestView.objects.get_query_set_with_joins(filter_data) - query = models.TestView.query_objects(filter_data, initial_query=query, + initial_query = models.TestView.objects.get_query_set_with_joins( + filter_data) + query = models.TestView.query_objects(filter_data, + initial_query=initial_query, apply_presentation=False) query = query.exclude(status__in=tko_rpc_utils._INVALID_STATUSES) query = query.extra( @@ -108,7 +111,7 @@ # fetch full info for these tests so we can access their statuses all_test_ids = [group['latest_test_idx'] for group in info['groups']] - test_views = models.TestView.objects.in_bulk(all_test_ids) + test_views = initial_query.in_bulk(all_test_ids) for group_dict in info['groups']: test_idx = group_dict.pop('latest_test_idx') --- autotest/frontend/tko/rpc_interface_unittest.py 2010-01-15 13:43:01.000000000 -0800 +++ autotest/frontend/tko/rpc_interface_unittest.py 2010-01-15 13:43:01.000000000 -0800 @@ -317,8 +317,7 @@ counts = rpc_interface.get_group_counts(['job_name']) groups = counts['groups'] self.assertEquals(len(groups), 2) - group1 = groups[0] - group2 = groups[1] + group1, group2 = groups self.assertEquals(group1['group_count'], 2) self.assertEquals(group1['job_name'], 'myjob1') @@ -331,8 +330,7 @@ extra_select_fields=extra) groups = counts['groups'] self.assertEquals(len(groups), 2) - group1 = groups[0] - group2 = groups[1] + group1, group2 = groups self.assertEquals(group1['group_count'], 2) self.assertEquals(group1['header_indices'], [0]) @@ -343,17 +341,31 @@ def test_get_status_counts(self): - """\ - This method cannot be tested with a sqlite3 test framework. The method - relies on the IF function, which is not present in sqlite3. - """ + counts = rpc_interface.get_status_counts(group_by=['job_name']) + group1, group2 = counts['groups'] + self.assertEquals(group1['pass_count'], 1) + self.assertEquals(group1['complete_count'], 2) + self.assertEquals(group1['incomplete_count'], 0) + self.assertEquals(group2['pass_count'], 1) + self.assertEquals(group2['complete_count'], 1) + self.assertEquals(group2['incomplete_count'], 0) def test_get_latest_tests(self): - """\ - This method cannot be tested with a sqlite3 test framework. The method - relies on the IF function, which is not present in sqlite3. - """ + counts = rpc_interface.get_latest_tests(group_by=['job_name']) + group1, group2 = counts['groups'] + self.assertEquals(group1['pass_count'], 0) + self.assertEquals(group1['complete_count'], 1) + self.assertEquals(group1['test_idx'], 2) + self.assertEquals(group2['test_idx'], 3) + + + def test_get_latest_tests_extra_info(self): + counts = rpc_interface.get_latest_tests(group_by=['job_name'], + extra_info=['job_tag']) + group1, group2 = counts['groups'] + self.assertEquals(group1['extra_info'], ['1-myjobtag1']) + self.assertEquals(group2['extra_info'], ['2-myjobtag2']) def test_get_job_ids(self): @@ -439,6 +451,14 @@ self.assertEquals(groups[1]['group_count'], 1) + def test_extra_info_test_attributes(self): + counts = rpc_interface.get_latest_tests( + group_by=['test_idx'], extra_info=['attribute_myattr'], + test_attribute_fields=['myattr']) + group1 = counts['groups'][0] + self.assertEquals(group1['extra_info'], ['myval']) + + def test_get_test_label_fields(self): tests = rpc_interface.get_test_views( test_label_fields=['testlabel1', 'testlabel2']) _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
