Merge lp:~doanac/qa-dashboard/smoke-test-result-api into lp:qa-dashboard

Proposed by Andy Doan
Status: Merged
Approved by: Andy Doan
Approved revision: 713
Merged at revision: 713
Proposed branch: lp:~doanac/qa-dashboard/smoke-test-result-api
Merge into: lp:qa-dashboard
Diff against target: 118 lines (+76/-0)
2 files modified
smokeng/api.py (+28/-0)
smokeng/tests.py (+48/-0)
To merge this branch: bzr merge lp:~doanac/qa-dashboard/smoke-test-result-api
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Joe Talbott Approve
Review via email: mp+205054@code.launchpad.net

Commit message

allow publishing of smoketestresults via REST API

Allow the client to include the UTAH YAML with its SmokeResult object
so that the SmokeTestResult details can also be populated

Description of the change

allow publishing of smoketestresults via REST API

Allow the client to include the UTAH YAML with its SmokeResult object
so that the SmokeTestResult details can also be populated

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:713
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/297/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/297/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'smokeng/api.py'
2--- smokeng/api.py 2013-12-14 21:56:19 +0000
3+++ smokeng/api.py 2014-02-05 22:09:00 +0000
4@@ -20,6 +20,7 @@
5 from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
6
7 from common.models import JenkinsBuild, JenkinsJob
8+from smokeng import utah_utils
9 from smokeng.models import SmokeImage, SmokeResult
10
11
12@@ -111,6 +112,32 @@
13 authorization = WriteAuthorization()
14 allowed_methods = ALLOWED_METHODS
15
16+ def save(self, bundle, skip_errors=False):
17+ test_results = bundle.data.get('results')
18+ obj = bundle.obj
19+ if test_results:
20+ # setup passes, failures, etc
21+ obj.pass_count = test_results.get('passes', 0)
22+ obj.error_count = test_results.get('errors', 0)
23+ obj.fail_count = test_results.get('failures', 0)
24+ obj.total_count = obj.pass_count + obj.error_count + obj.fail_count
25+ else:
26+ if not bundle.data.get('pass_count'):
27+ obj.pass_count = 0
28+ if not bundle.data.get('error_count'):
29+ obj.error_count = 0
30+ if not bundle.data.get('fail_count'):
31+ obj.fail_count = 0
32+ if not bundle.data.get('total_count'):
33+ obj.total_count = 0
34+
35+ r = super(SmokeResultResource, self).save(bundle, skip_errors)
36+
37+ if test_results:
38+ details = []
39+ test_results['result'] = obj
40+ utah_utils._add_test_results(details, test_results)
41+ return r
42
43 v1_api = Api(api_name='v1')
44 v1_api.register(JenkinsJobResource())
45@@ -118,6 +145,7 @@
46 v1_api.register(SmokeImageResource())
47 v1_api.register(SmokeResultResource())
48
49+
50 # for tastypie, a hack to allow us to not require using TZ:
51 # http://github.com/toastdriven/django-tastypie/pull/561#issuecomment-26204496
52 def _now():
53
54=== modified file 'smokeng/tests.py'
55--- smokeng/tests.py 2013-12-12 05:37:09 +0000
56+++ smokeng/tests.py 2014-02-05 22:09:00 +0000
57@@ -18,6 +18,11 @@
58 import mock
59 import urllib2
60
61+# this is required to pull in the tastypie hack at the bottom of
62+# smokeng/api.py. Without this, our tests won't pass
63+import smokeng.api
64+smokeng.api # just to silence pep8 warnings. this does nothing
65+
66 from django.core.urlresolvers import reverse
67 from django.test import TestCase
68 from django.test.client import Client
69@@ -968,6 +973,49 @@
70 self.assertEqual(params['jenkins_build'], obj['jenkins_build'])
71 self.assertEqual(params['image'], obj['image'])
72
73+ def testResultAddWithResults(self):
74+ '''a smokeresult with utah results included'''
75+ params = {
76+ 'ran_at': datetime.datetime.now().isoformat(),
77+ 'status': 0,
78+ 'results': {
79+ 'passes': 2,
80+ 'errors': 1,
81+ 'failures': 1,
82+ 'commands': [
83+ # include one smoketestresult to ensure it can be processed
84+ {
85+ 'command': 'foo-cmd',
86+ 'cmd_type': 'foo-type',
87+ 'testcase': 'foo-testcase',
88+ 'testsuite': 'foo-testsuite',
89+ 'stdout': 'foo-stdout',
90+ 'stderr': 'foo-stderr',
91+ 'returncode': 0,
92+ },
93+ ]
94+ },
95+ 'jenkins_build': ('/smokeng/api/v1/build/%d/' %
96+ self.jenkins_build.id),
97+ 'image': '/smokeng/api/v1/image/%d/' % self.image.id,
98+ 'name': 'the-test-result-name',
99+ }
100+ loc = self._post('/smokeng/api/v1/result/', params)
101+ obj = self._get(loc)
102+ self.assertEqual(params['name'], obj['name'])
103+ self.assertEqual(params['ran_at'], obj['ran_at'])
104+ self.assertEqual(params['status'], obj['status'])
105+ self.assertEqual(4, obj['total_count'])
106+ self.assertEqual(2, obj['pass_count'])
107+ self.assertEqual(1, obj['error_count'])
108+ self.assertEqual(1, obj['fail_count'])
109+ self.assertEqual(params['jenkins_build'], obj['jenkins_build'])
110+ self.assertEqual(params['image'], obj['image'])
111+
112+ # make sure one SmokeTestResult from above was created
113+ obj = SmokeResult.objects.get(pk=obj['id'])
114+ self.assertEqual(1, len(obj.smoketestresult_set.values()))
115+
116 def _testResultState(self, state):
117 resource = '/smokeng/api/v1/result/%d/' % self.result.id
118 params = {

Subscribers

People subscribed via source and target branches