"""
pass
+class UnknownPlugin(KeyError, NotFound):
+ """
+ Jenkins does not recognize the plugin requested.
+ """
+ pass
class NoBuildData(NotFound):
"""
return Node(nodename=name, baseurl=self.get_node_url(nodename=name), jenkins_obj=self)
- def get_plugins_url(self):
+ def get_plugins_url(self, depth):
# This only ever needs to work on the base object
- return '%s/pluginManager/api/python?depth=1' % self.baseurl
+ return '%s/pluginManager/api/python?depth=%i' % (self.baseurl, depth)
- def get_plugins(self):
- url = self.get_plugins_url()
+ def get_plugins(self, depth=1):
+ url = self.get_plugins_url(depth=depth)
return Plugins(url, self)
def has_plugin(self, plugin_name):
def __eq__(self, other):
return self.__dict__ == other.__dict__
+
+ def __str__(self):
+ return self.shortName
+
+ def __repr__(self):
+ return "<%s.%s %s>" % (
+ self.__class__.__module__,
+ self.__class__.__name__,
+ str(self)
+ )
+
from __future__ import print_function
import logging
-
-from jenkinsapi.jenkinsbase import JenkinsBase
from jenkinsapi.plugin import Plugin
+from jenkinsapi.jenkinsbase import JenkinsBase
+from jenkinsapi.custom_exceptions import UnknownPlugin
log = logging.getLogger(__name__)
def keys(self):
return self.get_plugins_dict().keys()
+ __iter__ = keys
+
def iteritems(self):
return self._get_plugins()
return len(self.get_plugins_dict().keys())
def __getitem__(self, plugin_name):
- return self.get_plugins_dict().get(plugin_name, None)
-
+ try:
+ return self.get_plugins_dict()[plugin_name]
+ except KeyError:
+ raise UnknownPlugin(plugin_name)
+
def __contains__(self, plugin_name):
"""
True if plugin_name is the name of a defined plugin
except ImportError:
import unittest
+import logging
import jenkinsapi_tests.systests
from jenkinsapi_tests.systests.job_configs import EMPTY_JOB
from jenkinsapi.jenkins import Jenkins
+log = logging.getLogger(__name__)
+
+DEFAULT_JENKINS_PORT = 8080
class BaseSystemTest(unittest.TestCase):
def setUp(self):
- port = jenkinsapi_tests.systests.state['launcher'].http_port
+ try:
+ port = jenkinsapi_tests.systests.state['launcher'].http_port
+ except KeyError:
+ log.warning("Jenkins was not launched from the test-framework, assuming port %i" % DEFAULT_JENKINS_PORT)
+ port = DEFAULT_JENKINS_PORT
self.jenkins = Jenkins('http://localhost:%d' % port)
self._delete_all_jobs()
self._delete_all_views()
except ImportError:
import unittest
from jenkinsapi.job import Job
+from jenkinsapi.plugin import Plugin
from jenkinsapi.invocation import Invocation
from jenkinsapi_tests.systests.base import BaseSystemTest
from jenkinsapi_tests.systests.job_configs import EMPTY_JOB
def test_get_master_data(self):
master_data = self.jenkins.get_master_data()
self.assertEquals(master_data['totalExecutors'], 2)
+
+ def test_get_missing_plugin(self):
+ plugins = self.jenkins.get_plugins()
+ with self.assertRaises(KeyError):
+ plugins["lsdajdaslkjdlkasj"] # this plugin surely does not exist!
+
+ def test_get_single_plugin(self):
+ plugins = self.jenkins.get_plugins()
+ plugin_name, plugin = next(plugins.iteritems())
+ self.assertIsInstance(plugin_name, str)
+ self.assertIsInstance(plugin, Plugin)
+ self.assertFalse(plugin.dependencies[0])
+
+ def test_get_single_plugin_depth_2(self):
+ plugins = self.jenkins.get_plugins(depth=2)
+ _, plugin = next(plugins.iteritems())
+ self.assertTrue(plugin.dependencies[0])
if __name__ == '__main__':
unittest.main()
self.assertEquals('Jenkins Subversion Plug-in', plugin.longName)
self.assertEquals('http://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin',
plugin.url)
+
+ def test_plugin_repr(self):
+ p = Plugin(
+ {
+ 'shortName': 'subversion',
+ }
+ )
+ self.assertEquals(repr(p), '<jenkinsapi.plugin.Plugin subversion>')
if __name__ == '__main__':
unittest.main()
pip install sphinx
ant release
git tag v`jenkinsapi_version`
-ant doc
\ No newline at end of file
+ant doc