From 674fcec8fb9e21685b68b98501901d248b2b1173 Mon Sep 17 00:00:00 2001 From: Christophe Bliard Date: Fri, 4 Oct 2013 14:23:07 +0200 Subject: [PATCH] Add Plugins#__str__ 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 | 4 ++++ jenkinsapi_tests/unittests/test_plugins.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/jenkinsapi/plugins.py b/jenkinsapi/plugins.py index 06ae7f1..a412a54 100644 --- a/jenkinsapi/plugins.py +++ b/jenkinsapi/plugins.py @@ -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)) + diff --git a/jenkinsapi_tests/unittests/test_plugins.py b/jenkinsapi_tests/unittests/test_plugins.py index 2981e2c..8089a6d 100644 --- a/jenkinsapi_tests/unittests/test_plugins.py +++ b/jenkinsapi_tests/unittests/test_plugins.py @@ -36,6 +36,20 @@ class TestPlugins(unittest.TestCase): # Can we produce a repr string for this object 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 -- 2.34.1