示例#1
0
 def test_check_job_exists(self):
     with patch.object(j.JenkinsAPI, "__init__", lambda v, w, x, y: None):
         jenkins = j.JenkinsAPI(None, None, None)
         jenkins.jenkins_instance = Mock()
         jenkins.jenkins_instance.jobs.__contains__ = Mock(return_value=True)
         exists = jenkins.check_job_exists('example-pipeline1')
         self.assertTrue(exists)
示例#2
0
 def test_get_all_jobs(self):
     with patch.object(j.JenkinsAPI, "__init__", lambda v, w, x, y: None):
         jenkins = j.JenkinsAPI(None, None, None)
         jenkins.jenkins_instance = Mock()
         jenkins.jenkins_instance.get_jobs.return_value = self.create_mock_jobs(['example-pipeline1',
                                                                                 'example-pipeline2'])
         jobs = jenkins.get_all_jobs()
         self.assertTrue(len(jobs) > 1)
         expected_job_list = [job['name'] for job in jobs]
         self.assertTrue('example-pipeline2' in expected_job_list)
示例#3
0
    def test_create_job_json(self):
        '''
            Test helper to create job's JSON load
        '''
        with patch.object(j.JenkinsAPI, "__init__",
                          lambda v, w, x, y, z: None):
            jenkins = j.JenkinsAPI(None, None, None, None)
            jenkins.jenkins_instance = Mock()
            mock_job_list = self.create_mock_jobs(['abc123'])
            _, mock_job = mock_job_list[0]
            job_json = jenkins.create_job_json(mock_job)

            expected_job = {'name': mock_job.name, 'link': mock_job.url}
            self.assertEqual(expected_job, job_json)
示例#4
0
    def test_get_build_statuses(self):
        '''
            Test helper to create job's build status JSON load
        '''
        with patch.object(j.JenkinsAPI, "__init__",
                          lambda v, w, x, y, z: None):
            jenkins = j.JenkinsAPI(None, None, None, None)
            jenkins.jenkins_instance = Mock()
            jenkins.get_last_build_status = Mock(return_value='SUCCESS')
            mock_job_list = self.create_mock_jobs(['abc123'])
            _, mock_job = mock_job_list[0]
            job_json = jenkins.get_build_statuses(mock_job_list)

            expected_job = {'name': mock_job_list[0], 'status': 'SUCCESS'}
            self.assertEqual([expected_job], job_json)
示例#5
0
    def test_get_successful_builds(self, mock_get_requests):
        '''
            Test get_successful_builds with status 'SUCCESS'
        '''
        with patch.object(j.JenkinsAPI, "__init__",
                          lambda v, w, x, y, z: None):
            jenkins = j.JenkinsAPI(None, None, None, None)
            jenkins.jenkins_instance = Mock()
            jenkins.check_job_exists = Mock(return_value=True)
            build_json = {'number': 1, 'name': "test-build", 'id': 123}
            jenkins.create_build_json = Mock(return_value=build_json)
            jenkins.get_job_url_headers = Mock(
                return_value=["https://test.com/job1", {}])
            jenkins.jenkins_instance.jobs.__getitem__ = Mock()

            builds = jenkins.get_successful_builds('job1')
            self.assertTrue(len(builds) == 1)