def test_create_multibranch_pipeline_job(mocker, monkeypatch): def fake_jenkins_poll(cls, tree=None): # pylint: disable=unused-argument # return multibranch jobs and other jobs. # create_multibranch_pipeline_job is supposed to filter out the MULTIBRANCH jobs return { 'jobs': TWO_JOBS_DATA['jobs'] + MULTIBRANCH_JOBS_DATA['jobs'] } def fake_job_poll(cls, tree=None): # pylint: disable=unused-argument return {} monkeypatch.setattr(JenkinsBase, '_poll', fake_jenkins_poll) monkeypatch.setattr(Jenkins, '_poll', fake_jenkins_poll) monkeypatch.setattr(Job, '_poll', fake_job_poll) mock_requester = Requester(username='******', password='******') mock_requester.post_xml_and_confirm_status = mocker.MagicMock( return_value='' ) mock_requester.post_and_confirm_status = mocker.MagicMock( return_value='' ) get_response = namedtuple('get_response', 'text') mock_requester.get_url = mocker.MagicMock( return_value=get_response(text=SCAN_MULTIBRANCH_PIPELINE_LOG) ) jenkins = Jenkins('http://localhost:8080/', username='******', password='******', requester=mock_requester) jobs = jenkins.create_multibranch_pipeline_job("multibranch-repo", "multibranch-xml-content") for idx, job_instance in enumerate(jobs): assert job_instance.name == MULTIBRANCH_JOBS_DATA['jobs'][idx]['name'] # make sure we didn't get more jobs. assert len(MULTIBRANCH_JOBS_DATA['jobs']) == len(jobs)