diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b67626b --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +test: + python -m unittest discover diff --git a/jenkins/__init__.py b/jenkins/__init__.py index a1043a6..023a210 100644 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -336,8 +336,9 @@ class Jenkins(object): :param name: Name of Jenkins job, ``str`` :returns: job configuration (XML format) ''' - get_config_url = self.server + CONFIG_JOB%locals() - return self.jenkins_open(urllib2.Request(get_config_url)) + request = urllib2.Request(self.server + CONFIG_JOB % + {"name": urllib.quote(name)}) + return self.jenkins_open(request) def reconfig_job(self, name, config_xml): ''' diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/helper.py b/tests/helper.py new file mode 100644 index 0000000..c1628a6 --- /dev/null +++ b/tests/helper.py @@ -0,0 +1,5 @@ +import os +import sys +sys.path.insert(0, os.path.abspath('..')) + +import jenkins diff --git a/tests/test_jenkins.py b/tests/test_jenkins.py new file mode 100644 index 0000000..cf1c56f --- /dev/null +++ b/tests/test_jenkins.py @@ -0,0 +1,20 @@ +import unittest +import urllib2 + +from mock import patch, call + +from helper import jenkins + + +class JenkinsTest(unittest.TestCase): + + @patch.object(jenkins.Jenkins, 'jenkins_open') + def test_get_job_config_encodes_job_name(self, jenkins_mock): + """ + The job name parameter specified should be urlencoded properly. + """ + j = jenkins.Jenkins('http://example.com/', 'test', 'test') + j.get_job_config(u'Test Job') + + self.assertEqual(jenkins_mock.call_args[0][0].get_full_url(), + u'http://example.com/job/Test%20Job/config.xml')