Add job keyvals to the output dictionary for get_detailed_test_views()

Signed-off-by: James Ren <[email protected]>

--- autotest/frontend/tko/rpc_interface.py      2010-01-15 13:41:06.000000000 
-0800
+++ autotest/frontend/tko/rpc_interface.py      2010-09-07 14:02:59.000000000 
-0700
@@ -173,8 +173,13 @@
             for index in xrange(1, max_iterations + 1)]
 
 
+def _job_keyvals_to_dict(keyvals):
+    return dict((keyval.key, keyval.value) for keyval in keyvals)
+
+
 def get_detailed_test_views(**filter_data):
     test_views = models.TestView.list_objects(filter_data)
+
     tests_by_id = models.Test.objects.in_bulk([test_view['test_idx']
                                                for test_view in test_views])
     tests = tests_by_id.values()
@@ -186,11 +191,22 @@
                                                'iteration_results')
     models.Test.objects.populate_relationships(tests, models.TestLabel,
                                                'labels')
+
+    jobs_by_id = models.Job.objects.in_bulk([test_view['job_idx']
+                                             for test_view in test_views])
+    jobs = jobs_by_id.values()
+    models.Job.objects.populate_relationships(jobs, models.JobKeyval,
+                                              'keyvals')
+
     for test_view in test_views:
         test = tests_by_id[test_view['test_idx']]
         test_view['attributes'] = _attributes_to_dict(test.attributes)
         test_view['iterations'] = _format_iteration_keyvals(test)
         test_view['labels'] = [label.name for label in test.labels]
+
+        job = jobs_by_id[test_view['job_idx']]
+        test_view['job_keyvals'] = _job_keyvals_to_dict(job.keyvals)
+
     return rpc_utils.prepare_for_serialization(test_views)
 
 # graphing view support
--- autotest/frontend/tko/rpc_interface_unittest.py     2010-04-08 
13:30:58.000000000 -0700
+++ autotest/frontend/tko/rpc_interface_unittest.py     2010-09-07 
14:02:59.000000000 -0700
@@ -173,6 +173,8 @@
                                                 status=good_status,
                                                 machine=machine)
 
+        job1.jobkeyval_set.create(key='keyval_key', value='keyval_value')
+
         # create test attributes, test labels, and iterations
         # like Noah's Ark, include two of each...just in case there's a bug 
with
         # multiple related items
@@ -249,6 +251,7 @@
                                                 'perf': {'iresult': 3,
                                                          'iresult2': 4}}])
         self.assertEquals(test['labels'], ['testlabel1', 'testlabel2'])
+        self.assertEquals(test['job_keyvals'], {'keyval_key': 'keyval_value'})
 
 
     def test_test_attributes(self):
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to