From: salimfadhley Date: Sat, 12 Oct 2013 17:34:06 +0000 (+0100) Subject: more lint fixes X-Git-Tag: v0.2.23~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=91c964aff0a81c46704d65636b13857d4226a313;p=tools%2Fpython-jenkinsapi.git more lint fixes --- diff --git a/jenkinsapi/jobs.py b/jenkinsapi/jobs.py index fe3bfad..4f14b40 100644 --- a/jenkinsapi/jobs.py +++ b/jenkinsapi/jobs.py @@ -4,7 +4,7 @@ interface for all of the jobs defined on a single Jenkins server. """ import logging from jenkinsapi.job import Job -from jenkinsapi.custom_exceptions import JenkinsAPIException +from jenkinsapi.custom_exceptions import JenkinsAPIException, UnknownJob log = logging.getLogger(__name__) @@ -35,6 +35,9 @@ class Jobs(object): ) self.jenkins.poll() + def __setitem__(self, key, value): + raise NotImplementedError() + def __getitem__(self, job_name): for row in self.jenkins._data.get('jobs', []): if row['name'] == job_name: @@ -42,8 +45,8 @@ class Jobs(object): row['url'], row['name'], self.jenkins) - else: - return None + + raise UnknownJob(job_name) def iteritems(self): """ diff --git a/jenkinsapi/utils/krb_requester.py b/jenkinsapi/utils/krb_requester.py index bf27297..0fce891 100644 --- a/jenkinsapi/utils/krb_requester.py +++ b/jenkinsapi/utils/krb_requester.py @@ -1,9 +1,11 @@ +""" +Kerberos aware Requester +""" from jenkinsapi.utils.requester import Requester from requests_kerberos import HTTPKerberosAuth, OPTIONAL class KrbRequester(Requester): - """ A class which carries out HTTP requests with Kerberos/GSSAPI authentication. """ diff --git a/jenkinsapi_tests/unittests/test_jenkins.py b/jenkinsapi_tests/unittests/test_jenkins.py index 6bf70bb..641002d 100644 --- a/jenkinsapi_tests/unittests/test_jenkins.py +++ b/jenkinsapi_tests/unittests/test_jenkins.py @@ -1,10 +1,10 @@ import mock import unittest +from jenkinsapi.plugins import Plugins from jenkinsapi.utils.requester import Requester -from jenkinsapi.custom_exceptions import JenkinsAPIException from jenkinsapi.jenkins import Jenkins, JenkinsBase, Job -from jenkinsapi.plugins import Plugins +from jenkinsapi.custom_exceptions import JenkinsAPIException, UnknownJob class TestJenkins(unittest.TestCase): @@ -37,45 +37,6 @@ class TestJenkins(unittest.TestCase): requester=mock_requester) J.poll() -# TODO: Refactor this to use Requests, not urllib2 - # @mock.patch.object(Jenkins, '_poll') - # def test_unauthorised_reload(self, _poll): - # def fail_get_url(url): - # raise urllib2.HTTPError(url=url, code=403, - # msg='You are not authorized to reload this server', - # hdrs=None, fp=None) - - # _poll.return_value = {} - # mock_requester = Requester(username='foouser', password='foopassword') - # mock_requester.get_url = mock.MagicMock(return_value='', - # side_effect=fail_get_url) - # J = Jenkins('http://localhost:8080/', - # username='foouser', password='foopassword', - # requester=mock_requester) - # with self.assertRaises(NotAuthorized) as na: - # J.reload() - - # self.assertEquals(na.exception.message, - # 'You are not authorized to reload this server') - - # @mock.patch.object(Jenkins, '_poll') - # def test_httperror_reload(self, _poll): - # def fail_get_url(url): - # raise urllib2.HTTPError(url=url, code=500, - # msg='Because I said so!', hdrs=None, fp=None) - - # _poll.return_value = {} - # mock_requester = Requester(username='foouser', password='foopassword') - # mock_requester.get_url = mock.MagicMock(return_value='', - # side_effect=fail_get_url) - # J = Jenkins('http://localhost:8080/', - # username='foouser', password='foopassword', - # requester=mock_requester) - # with self.assertRaises(urllib2.HTTPError) as ar: - # J.poll() - # http_error = ar.exception - # self.assertEquals(http_error.code, 500) - @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @mock.patch.object(Job, '_poll') @@ -153,6 +114,24 @@ class TestJenkins(unittest.TestCase): @mock.patch.object(JenkinsBase, '_poll') @mock.patch.object(Jenkins, '_poll') @mock.patch.object(Job, '_poll') + def test_get_job_that_does_not_exist(self, _base_poll, _poll, _job_poll): + _poll.return_value = { + 'jobs': [ + {'name': 'job_one', 'url': 'http://localhost:8080/job_one'}, + {'name': 'job_two', 'url': 'http://localhost:8080/job_two'}, + ] + } + _base_poll.return_value = _poll.return_value + _job_poll.return_value = {} + J = Jenkins('http://localhost:8080/', + username='foouser', password='foopassword') + + with self.assertRaises(UnknownJob): + job = J.get_job('job_three') + + @mock.patch.object(JenkinsBase, '_poll') + @mock.patch.object(Jenkins, '_poll') + @mock.patch.object(Job, '_poll') def test_has_job(self, _base_poll, _poll, _job_poll): _poll.return_value = { 'jobs': [