From: Aleksey Maksimov Date: Sat, 29 Mar 2014 17:07:25 +0000 (+0800) Subject: Simplified get_job_url function X-Git-Tag: v0.2.23~28^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb8f0928a7564e0fddca2375055da89cd525fca2;p=tools%2Fpython-jenkinsapi.git Simplified get_job_url function --- diff --git a/jenkinsapi/view.py b/jenkinsapi/view.py index f8bf5db..4351ca5 100644 --- a/jenkinsapi/view.py +++ b/jenkinsapi/view.py @@ -6,6 +6,7 @@ import logging from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.job import Job +from jenkinsapi.custom_exceptions import NotFound log = logging.getLogger(__name__) @@ -71,13 +72,13 @@ class View(JenkinsBase): return len(self.get_job_dict().keys()) def get_job_url(self, str_job_name): - try: - job_dict = self.get_job_dict() - return job_dict[str_job_name] - except KeyError: + if str_job_name in self: + return self.get_job_dict()[str_job_name] + else: # noinspection PyUnboundLocalVariable - all_views = ", ".join(job_dict.keys()) - raise KeyError("Job %s is not known - available: %s" % (str_job_name, all_views)) + views_jobs = ", ".join(self.get_job_dict().keys()) + raise NotFound("Job %s is not known, available jobs" + " in view are: %s" % (str_job_name, views_jobs)) def get_jenkins_obj(self): return self.jenkins_obj diff --git a/jenkinsapi_tests/unittests/test_view.py b/jenkinsapi_tests/unittests/test_view.py index 4fdd433..0c193c0 100644 --- a/jenkinsapi_tests/unittests/test_view.py +++ b/jenkinsapi_tests/unittests/test_view.py @@ -5,6 +5,7 @@ from jenkinsapi.jenkinsbase import JenkinsBase from jenkinsapi.jenkins import Jenkins from jenkinsapi.view import View from jenkinsapi.job import Job +from jenkinsapi.custom_exceptions import NotFound class TestView(unittest.TestCase): @@ -109,7 +110,7 @@ class TestView(unittest.TestCase): self.assertEquals(self.v.get_job_url('foo'), 'http://halob:8080/job/foo/') def test_wrong_get_job_url(self): - with self.assertRaises(KeyError): + with self.assertRaises(NotFound): self.v.get_job_url('bar') # We have to re-patch JenkinsBase here because by the time