Use fullname in get_job_info_regex

Use full job name in `get_job_info_regex` instead of just the name, so
that matches will work in folders as well.

Closes-Bug: 1685575
Change-Id: I97ba8ca004387b376a511ba52fc9fdd2aeb98a63
This commit is contained in:
Jim Wisniewski 2021-12-14 18:17:53 -05:00
parent 570a143c74
commit dc2b9447de
2 changed files with 17 additions and 3 deletions

View File

@ -498,7 +498,7 @@ class Jenkins(object):
folder_depth_per_request=folder_depth_per_request)
for job in jobs:
if re.search(pattern, job['name']):
result.append(self.get_job_info(job['name'], depth=depth))
result.append(self.get_job_info(job['fullname'], depth=depth))
return result

View File

@ -110,22 +110,36 @@ class JenkinsGetJobInfoTest(JenkinsJobsTestBase):
@patch.object(jenkins.Jenkins, 'jenkins_open')
def test_regex(self, jenkins_mock):
parent_job = {
u'name': u'nested-parent-job',
u'jobs': [{u'name': u'nested-child-job'}],
}
jobs = [
{u'name': u'my-job-1'},
{u'name': u'my-job-2'},
{u'name': u'your-job-1'},
{u'name': u'Your-Job-1'},
{u'name': u'my-project-1'},
parent_job,
]
job_info_to_return = {u'jobs': jobs}
jenkins_mock.return_value = json.dumps(job_info_to_return)
def mock_jenkins_open(req, **kwargs):
return json.dumps(parent_job if parent_job['name'] in req.url else job_info_to_return)
jenkins_mock.side_effect = mock_jenkins_open
self.assertEqual(len(self.j.get_job_info_regex('her-job')), 0)
self.assertEqual(len(self.j.get_job_info_regex('my-job-1')), 1)
self.assertEqual(len(self.j.get_job_info_regex('my-job')), 2)
self.assertEqual(len(self.j.get_job_info_regex('job')), 3)
self.assertEqual(len(self.j.get_job_info_regex('job')), 4)
self.assertEqual(len(self.j.get_job_info_regex('job', folder_depth=1)), 5)
self.assertEqual(len(self.j.get_job_info_regex('project')), 1)
self.assertEqual(len(self.j.get_job_info_regex('[Yy]our-[Jj]ob-1')), 2)
self.assertEqual(len(self.j.get_job_info_regex('nested-.*-job')), 1)
self.assertEqual(len(self.j.get_job_info_regex('nested-.*-job', folder_depth=1)), 2)
self.assertEqual(len(self.j.get_job_info_regex('parent')), 1)
self.assertEqual(len(self.j.get_job_info_regex('child')), 0)
self.assertEqual(len(self.j.get_job_info_regex('child', folder_depth=1)), 1)
self._check_requests(jenkins_mock.call_args_list)
@patch.object(jenkins.Jenkins, 'jenkins_open')