From 08f41aa93ff7dc81f7895d2245938593b1941af7 Mon Sep 17 00:00:00 2001 From: Kevin McDermott Date: Thu, 17 May 2012 16:10:00 +0100 Subject: [PATCH] Fixes for this bug. --- Makefile | 2 ++ jenkins/__init__.py | 5 +++-- tests/__init__.py | 0 tests/helper.py | 5 +++++ tests/test_jenkins.py | 20 ++++++++++++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 tests/__init__.py create mode 100644 tests/helper.py create mode 100644 tests/test_jenkins.py 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')