1 from autotest_lib.frontend.shared import query_lib, resource_lib 2 from autotest_lib.frontend.tko import models 3 4 class TestResult(resource_lib.InstanceEntry): 5 model = models.Test 6 7 8 @classmethod 9 def add_query_selectors(cls, query_processor): 10 query_processor.add_field_selector('afe_job_id', 11 field='job__afe_job_id') 12 query_processor.add_keyval_selector('has_keyval', models.TestAttribute, 13 'attribute', 'value') 14 15 16 @classmethod 17 def from_uri_args(cls, request, test_id, **kwargs): 18 return cls(request, models.Test.objects.get(pk=test_id)) 19 20 21 def _uri_args(self): 22 return {'test_id': self.instance.pk} 23 24 25 def short_representation(self): 26 rep = super(TestResult, self).short_representation() 27 rep.update(id=self.instance.test_idx, 28 test_name=self.instance.test, 29 status=self.instance.status.word, 30 reason=self.instance.reason, 31 afe_job_id=self.instance.job.afe_job_id, 32 ) 33 return rep 34 35 36 def full_representation(self): 37 rep = super(TestResult, self).full_representation() 38 rep['keyvals'] = dict((keyval.attribute, keyval.value) 39 for keyval 40 in self.instance.testattribute_set.all()) 41 return rep 42 43 44 class TestResultCollection(resource_lib.Collection): 45 queryset = models.Test.objects.order_by('-test_idx') 46 entry_class = TestResult 47 48 49 class ResourceDirectory(resource_lib.Resource): 50 _permitted_methods = ('GET',) 51 52 def handle_request(self): 53 result = self.link() 54 result.update({ 55 'test_results': TestResultCollection(self._request).link(), 56 }) 57 return self._basic_response(result) 58