STR_TOTALCOUNT = "totalCount"
STR_TPL_NOTESTS_ERR = "%s has status %s, and does not have any test results"
- def __init__(self, url, buildno, job):
+ def __init__(self, url, buildno, job, depth=1):
+ """
+ depth=1 is for backward compatibility consideration
+ """
assert type(buildno) == int
self.buildno = buildno
self.job = job
+ self.depth = depth
JenkinsBase.__init__(self, url)
def _poll(self):
# For build's we need more information for downstream and upstream builds
# so we override the poll to get at the extra data for build objects
- url = self.python_api_url(self.baseurl) + '?depth=1'
+ url = '%s?depth=%s' % (self.python_api_url(self.baseurl), self.depth)
return self.get_data(url)
def __str__(self):
url = self.get_build_dict()[buildnumber]
return Build(url, buildnumber, job=self)
+ def get_build_metadata(self, buildnumber):
+ """
+ Get the build metadata for a given build number. For large builds with
+ tons of tests, this method is faster than get_build by returning less
+ data.
+ """
+ assert type(buildnumber) == int
+ url = self.get_build_dict()[buildnumber]
+ return Build(url, buildnumber, job=self, depth=0)
+
def __getitem__(self, buildnumber):
return self.get_build(buildnumber)
self.assertEquals(self.b.get_duration().microseconds, 782000)
self.assertEquals(str(self.b.get_duration()), '0:00:05.782000')
+ @mock.patch.object(Build, 'get_data')
+ def test_build_depth(self, get_data_mock):
+ build = Build('http://halob:8080/job/foo/98', 98, self.j, depth=0)
+ get_data_mock.assert_called_with('http://halob:8080/job/foo/98/api/python?depth=0')
+
## TEST DISABLED - DOES NOT WORK
# def test_downstream(self):
# expected = ['SingleJob','MultipleJobs']
except ImportError:
import unittest
+import jenkinsapi
from jenkinsapi import config
from jenkinsapi.job import Job
from jenkinsapi.jenkinsbase import JenkinsBase
self.assertEquals(len(params), 2)
self.assertEquals(params, ['param1', 'param2'])
+ def test_get_build(self):
+ buildnumber = 1
+ with mock.patch('jenkinsapi.job.Build') as build_mock:
+ instance = build_mock.return_value
+ build = self.j.get_build(buildnumber)
+ self.assertEquals(build, instance)
+ build_mock.assert_called_with('http://halob:8080/job/foo/1/',
+ buildnumber, job=self.j)
+
+ def test_get_build_metadata(self):
+ buildnumber = 1
+ with mock.patch('jenkinsapi.job.Build') as build_mock:
+ instance = build_mock.return_value
+ build = self.j.get_build_metadata(buildnumber)
+ self.assertEquals(build, instance)
+ build_mock.assert_called_with('http://halob:8080/job/foo/1/',
+ buildnumber, job=self.j, depth=0)
+
if __name__ == '__main__':
unittest.main()