Add Plugins#__str__
authorChristophe Bliard <christophe.bliard@smartesting.com>
Fri, 4 Oct 2013 12:23:07 +0000 (14:23 +0200)
committerChristophe Bliard <christophe.bliard@smartesting.com>
Fri, 4 Oct 2013 12:23:07 +0000 (14:23 +0200)
Because when doing jenkins.get_plugins() in an interactive python shell,
the behavior was to use the JenkinsBase#__str__ which throws a
NotImplementedError

jenkinsapi/plugins.py
jenkinsapi_tests/unittests/test_plugins.py

index 06ae7f1..a412a54 100644 (file)
@@ -51,3 +51,7 @@ class Plugins(JenkinsBase):
         """
         return plugin_name in self.keys()
 
+    def __str__(self):
+        plugins = [plugin["shortName"] for plugin in self._data.get("plugins", [])]
+        return str(sorted(plugins))
+
index 2981e2c..8089a6d 100644 (file)
@@ -37,6 +37,20 @@ class TestPlugins(unittest.TestCase):
         self.assertIsInstance(self.J.get_plugins(), Plugins)
 
     @mock.patch.object(Plugins, '_poll')
+    def test_no_plugins_str(self, _poll_plugins):
+        _poll_plugins.return_value = {}
+
+        plugins = self.J.get_plugins()
+        self.assertEquals(str(plugins), "[]")
+
+    @mock.patch.object(Plugins, '_poll')
+    def test_plugins_str(self, _poll_plugins):
+        _poll_plugins.return_value = self.DATA
+
+        plugins = self.J.get_plugins()
+        self.assertEquals(str(plugins), "['maven-plugin', 'subversion']")
+
+    @mock.patch.object(Plugins, '_poll')
     def test_plugins_len(self, _poll_plugins):
         _poll_plugins.return_value = self.DATA