summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Thomas <dthomas@osrfoundation.org>2014-11-21 12:36:12 -0800
committerDirk Thomas <dthomas@osrfoundation.org>2014-11-21 13:00:24 -0800
commit99e16c87ce7e3b4dd96bb64bc1fcc5a69708ca44 (patch)
treeee38dbcadba3dbaefa2cf6b83511675bf1229059
parent84e13c8f7501a190f542b3b8343ede61585e8ba8 (diff)
downloadpython-jenkinsapi-99e16c87ce7e3b4dd96bb64bc1fcc5a69708ca44.tar.gz
python-jenkinsapi-99e16c87ce7e3b4dd96bb64bc1fcc5a69708ca44.tar.bz2
python-jenkinsapi-99e16c87ce7e3b4dd96bb64bc1fcc5a69708ca44.zip
add View.get_config() and tests covering View.get_config() as well as View.update_config()
-rw-r--r--jenkinsapi/view.py8
-rw-r--r--jenkinsapi_tests/systests/test_views.py13
-rw-r--r--jenkinsapi_tests/systests/view_configs.py28
3 files changed, 49 insertions, 0 deletions
diff --git a/jenkinsapi/view.py b/jenkinsapi/view.py
index 69ecbf0..c262804 100644
--- a/jenkinsapi/view.py
+++ b/jenkinsapi/view.py
@@ -170,6 +170,14 @@ class View(JenkinsBase):
def get_config_xml_url(self):
return '%s/config.xml' % self.baseurl
+ def get_config(self):
+ """
+ Return the config.xml from the view
+ """
+ url = self.get_config_xml_url()
+ response = self.get_jenkins_obj().requester.get_and_confirm_status(url)
+ return response.text
+
def update_config(self, config):
"""
Update the config.xml to the view
diff --git a/jenkinsapi_tests/systests/test_views.py b/jenkinsapi_tests/systests/test_views.py
index 6d91c6e..76e948c 100644
--- a/jenkinsapi_tests/systests/test_views.py
+++ b/jenkinsapi_tests/systests/test_views.py
@@ -12,6 +12,7 @@ from jenkinsapi.view import View
from jenkinsapi.views import Views
from jenkinsapi.api import get_view_from_url
from jenkinsapi_tests.systests.base import BaseSystemTest
+from jenkinsapi_tests.systests.view_configs import VIEW_WITH_FILTER_AND_REGEX
from jenkinsapi_tests.test_utils.random_strings import random_string
log = logging.getLogger(__name__)
@@ -59,6 +60,18 @@ class TestViews(BaseSystemTest):
del self.jenkins.views[view1_name]
self.assertNotIn(view1_name, self.jenkins.views)
+ def test_update_view_config(self):
+ view_name = random_string()
+ new_view = self.jenkins.views.create(view_name)
+ self.assertIsInstance(new_view, View)
+ self.assertIn(view_name, self.jenkins.views)
+ config = self.jenkins.views[view_name].get_config().strip()
+ new_view_config = VIEW_WITH_FILTER_AND_REGEX % view_name
+ self.assertNotEquals(config, new_view_config)
+ self.jenkins.views[view_name].update_config(new_view_config)
+ config = self.jenkins.views[view_name].get_config().strip()
+ self.assertEquals(config, new_view_config)
+
def test_make_nested_views(self):
job = self._create_job()
top_view_name = random_string()
diff --git a/jenkinsapi_tests/systests/view_configs.py b/jenkinsapi_tests/systests/view_configs.py
new file mode 100644
index 0000000..66d2aab
--- /dev/null
+++ b/jenkinsapi_tests/systests/view_configs.py
@@ -0,0 +1,28 @@
+"""
+A selection of view objects used in testing.
+"""
+
+VIEW_WITH_FILTER_AND_REGEX = """
+<?xml version="1.0" encoding="UTF-8"?>
+<hudson.model.ListView>
+ <name>%s</name>
+ <filterExecutors>true</filterExecutors>
+ <filterQueue>true</filterQueue>
+ <properties class="hudson.model.View$PropertyList"/>
+ <jobNames>
+ <comparator class="hudson.util.CaseInsensitiveComparator"/>
+ </jobNames>
+ <jobFilters/>
+ <columns>
+ <hudson.views.StatusColumn/>
+ <hudson.views.WeatherColumn/>
+ <hudson.views.JobColumn/>
+ <hudson.views.LastSuccessColumn/>
+ <hudson.views.LastFailureColumn/>
+ <hudson.views.LastDurationColumn/>
+ <hudson.views.BuildButtonColumn/>
+ </columns>
+ <includeRegex>regex</includeRegex>
+ <recurse>false</recurse>
+</hudson.model.ListView>
+""".strip()