fix for python 3, decode job output

Change Ie952617a34c0719e forced utf-8 format but forgot to decode the
xml when passing to update_job. This broke jjb for python 3:

 File "/Users/khaido/PycharmProjects/jenkins-job-builder
     /jenkins_jobs/builder.py", line
 134, in update_job
    self.jenkins.create_job(job_name, xml)

 File "/Users/khaido/PycharmProjects/jenkins-job-builder/.tox
      /py34/lib/python3.4/site-packages/jenkins/__init__.py",
 line 852, in create_job
      config_xml.encode('utf-8'), DEFAULT_HEADERS))
  AttributeError: 'function' object has no attribute 'encode'

Change-Id: Iceda46214bf4709ccd8141ef654cf3ec81e8af06
This commit is contained in:
Khai Do 2015-10-09 13:03:45 -07:00
parent 4672157c05
commit 899bc6c946
2 changed files with 22 additions and 1 deletions

View File

@ -352,7 +352,7 @@ class Builder(object):
self.cache.set(job.name, old_md5)
if self.cache.has_changed(job.name, md5) or self.ignore_cache:
self.jenkins.update_job(job.name, job.output())
self.jenkins.update_job(job.name, job.output().decode('utf-8'))
updated_jobs += 1
self.cache.set(job.name, md5)
else:

View File

@ -15,6 +15,7 @@
# under the License.
import os
import six
from jenkins_jobs import cmd
from jenkins_jobs import builder
@ -39,6 +40,26 @@ class UpdateTests(CmdTestsBase):
cmd.execute(args, self.config)
update_job_mock.assert_called_with([path], [])
@mock.patch('jenkins_jobs.builder.Jenkins.is_job', return_value=True)
@mock.patch('jenkins_jobs.builder.Jenkins.get_jobs')
@mock.patch('jenkins_jobs.builder.Jenkins.get_job_md5')
@mock.patch('jenkins_jobs.builder.Jenkins.update_job')
def test_update_jobs_decode_job_output(self, update_job_mock,
get_job_md5_mock, get_jobs_mock,
is_job_mock):
"""
Test that job xml output has been decoded before attempting to update
"""
# don't care about the value returned here
update_job_mock.return_value = ([], 0)
path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
args = self.parser.parse_args(['update', path])
cmd.execute(args, self.config)
self.assertTrue(isinstance(update_job_mock.call_args[0][1],
six.text_type))
@mock.patch('jenkins_jobs.builder.Jenkins.is_job', return_value=True)
@mock.patch('jenkins_jobs.builder.Jenkins.get_jobs')
@mock.patch('jenkins_jobs.builder.Builder.delete_job')