Add tree parameter to get_build_test_report()
This change adds a new parameter 'tree' to the get_build_test_report() method. This new parameter is not added to the url but instead will be passed via request parameters. Rationale for addding the change is to allow users to get only a subset of fields because for huge test reports getting all fields may cause significant load on the Jenkins server. Change-Id: I0c4c048bdb1c2a3ef75965695d8645cd280ce37e
This commit is contained in:
parent
f29d64f991
commit
8af7e92d47
@ -707,17 +707,22 @@ class Jenkins(object):
|
||||
# This can happen on workflow jobs, or if InjectEnvVars plugin not installed
|
||||
return None
|
||||
|
||||
def get_build_test_report(self, name, number, depth=0):
|
||||
def get_build_test_report(self, name, number, depth=0, tree=None):
|
||||
'''Get test results report.
|
||||
|
||||
:param name: Job name, ``str``
|
||||
:param number: Build number, ``str`` (also accepts ``int``)
|
||||
:param depth: depth parameter for the api/json call, default 0
|
||||
:param tree: tree parameter for the api/json call used to limit returned fields
|
||||
:returns: dictionary of test report results, ``dict`` or None if there is no Test Report
|
||||
'''
|
||||
folder_url, short_name = self._get_job_folder(name)
|
||||
params = {'tree': tree} if tree else {}
|
||||
try:
|
||||
response = self.jenkins_open(requests.Request(
|
||||
'GET', self._build_url(BUILD_TEST_REPORT, locals())))
|
||||
'GET',
|
||||
self._build_url(BUILD_TEST_REPORT, locals()),
|
||||
params=params))
|
||||
if response:
|
||||
return json.loads(response)
|
||||
else:
|
||||
|
@ -811,6 +811,17 @@ class JenkinsBuildArtifactUrlTest(JenkinsTestBase):
|
||||
str(context_manager.exception),
|
||||
'Error in request. Possibly authentication failed [401]: Not Authorised')
|
||||
|
||||
@patch.object(jenkins.Jenkins, 'jenkins_open')
|
||||
def test_tree_param(self, jenkins_mock):
|
||||
jenkins_mock.return_value = '{}'
|
||||
ret = self.j.get_build_test_report(u'Test Job', number='52', tree='suites[name]{0}')
|
||||
self.assertEqual(ret, json.loads(jenkins_mock.return_value))
|
||||
self.assertEqual(
|
||||
jenkins_mock.call_args[0][0].params,
|
||||
{'tree': 'suites[name]{0}'}
|
||||
)
|
||||
self._check_requests(jenkins_mock.call_args_list)
|
||||
|
||||
|
||||
class JenkinsBuildArtifactAsBytesUrlTest(JenkinsTestBase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user