virt.virt_test_utils: run_autotest - 'tar' needs relative paths to strip the leading '/'
[autotest-zwu.git] / frontend / tko / resources.py
blob99b7267ad8ee45d9384d03ceed9176d31e737a77
1 from autotest_lib.frontend.shared import query_lib, resource_lib
2 from autotest_lib.frontend.tko import models
4 class TestResult(resource_lib.InstanceEntry):
5 model = models.Test
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')
16 @classmethod
17 def from_uri_args(cls, request, test_id, **kwargs):
18 return cls(request, models.Test.objects.get(pk=test_id))
21 def _uri_args(self):
22 return {'test_id': self.instance.pk}
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,
33 return rep
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
44 class TestResultCollection(resource_lib.Collection):
45 queryset = models.Test.objects.order_by('-test_idx')
46 entry_class = TestResult
49 class ResourceDirectory(resource_lib.Resource):
50 _permitted_methods = ('GET',)
52 def handle_request(self):
53 result = self.link()
54 result.update({
55 'test_results': TestResultCollection(self._request).link(),
57 return self._basic_response(result)