def find_view(jenkins_url, credentials, view_name): """Locates a view with a given name recursively across a Jenkins instance This helper function has knowledge of view plugins that support sub-views and thus recursively searches these sub-views for the requested view WARNING: This function can be quite slow when executed against a large Jenkins build farm with a large number of views and subviews. :param str jenkins_url: URL of the root Jenkins master :param tuple credentials: 2-tuple containing the user-name and password to authenticate with :param str view_name: name of the view to locate :returns: Reference to the view with the provided name, or None if the view doesn't exist :rtype: :class:`~.view.View` """ from pyjen.plugins.nestedview import NestedView jen = Jenkins.easy_connect(jenkins_url, credentials) parent_view = jen.find_view(view_name) if parent_view is not None: return parent_view for cur_view in jen.views: if cur_view.type == NestedView.type: sub_view = cur_view.find_view(view_name) if sub_view is not None: return sub_view return None
def test_find_job(self): expected_job_name = "JobNumber1" j = Jenkins.easy_connect(self._jenkins_url, None) job = j.find_job(expected_job_name) self.assertEqual(expected_job_name, job.name)
def test_find_view(self): expected_view_name = "ViewNumber1" j = Jenkins.easy_connect(self._jenkins_url, None) v = j.find_view(expected_view_name) self.assertEqual(expected_view_name, v.name)
def test_shutdown(self): j = Jenkins.easy_connect(self._jenkins_url, None) self.assertFalse(j.is_shutting_down) j.prepare_shutdown() self.assertTrue(j.is_shutting_down) j.cancel_shutdown() self.assertFalse(j.is_shutting_down)
def test_create_view(self): new_view_name = "test_create_view" j = Jenkins.easy_connect(self._jenkins_url, None) j.create_view(new_view_name, "hudson.model.ListView") v = j.find_view(new_view_name) self.assertTrue(v is not None) self.assertEqual(v.name, new_view_name)
def test_last_build(self): job_url = self._jenkins_url + "/job/JobNumber1" j = Jenkins.easy_connect(self._jenkins_url, None) job = j.get_job(job_url) #sanity check: make sure our generated URL works correctly self.assertEqual("JobNumber1", job.name) build = job.last_build self.assertEqual(2, build.number)
def test_get_builds(self): job_url = self._jenkins_url + "/job/JobNumber1" j = Jenkins.easy_connect(self._jenkins_url, None) job = j.get_job(job_url) #sanity check: make sure our generated URL works correctly self.assertEqual("JobNumber1", job.name) builds = job.recent_builds self.assertEqual(2, len(builds)) expected_numbers = [1, 2] expected_results = ["SUCCESS", "FAILURE"] for build in builds: self.assertTrue(build.number in expected_numbers) self.assertTrue(build.result in expected_results) expected_numbers.remove(build.number) expected_results.remove(build.result)
def test_default_view(self): j = Jenkins.easy_connect(self._jenkins_url, None) v = j.default_view self.assertIsNotNone(v) self.assertEqual("All", v.name)