diff --git a/jenkins_jobs/modules/view_all.py b/jenkins_jobs/modules/view_all.py new file mode 100644 index 000000000..aa41d5c38 --- /dev/null +++ b/jenkins_jobs/modules/view_all.py @@ -0,0 +1,49 @@ +# Copyright 2018 Openstack Foundation + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +View support for All view-type. + +To create an all view specify ``all`` in the ``view-type`` attribute +to the :ref:`view_all` definition. + +Example: + + .. literalinclude:: + /../../tests/views/fixtures/view-all-minimal.yaml +""" + +import xml.etree.ElementTree as XML +import jenkins_jobs.modules.base +import jenkins_jobs.modules.helpers as helpers + + +class All(jenkins_jobs.modules.base.Base): + sequence = 0 + + def root_xml(self, data): + root = XML.Element('hudson.model.AllView') + + mapping = [ + ('name', 'name', None), + ('description', 'description', ''), + ('filter-executors', 'filterExecutors', False), + ('filter-queue', 'filterQueue', False), + ] + helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True) + + XML.SubElement(root, 'properties', + {'class': 'hudson.model.View$PropertyList'}) + + return root diff --git a/setup.cfg b/setup.cfg index e642b4281..70097582b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -62,6 +62,7 @@ jenkins_jobs.projects = pipeline=jenkins_jobs.modules.project_pipeline:Pipeline workflow=jenkins_jobs.modules.project_workflow:Workflow jenkins_jobs.views = + all=jenkins_jobs.modules.view_all:All list=jenkins_jobs.modules.view_list:List pipeline=jenkins_jobs.modules.view_pipeline:Pipeline jenkins_jobs.builders = diff --git a/tests/base.py b/tests/base.py index 1f233b0a3..514b83c42 100644 --- a/tests/base.py +++ b/tests/base.py @@ -43,6 +43,7 @@ from jenkins_jobs.modules import project_matrix from jenkins_jobs.modules import project_maven from jenkins_jobs.modules import project_multibranch from jenkins_jobs.modules import project_multijob +from jenkins_jobs.modules import view_all from jenkins_jobs.modules import view_list from jenkins_jobs.modules import view_pipeline from jenkins_jobs.parser import YamlParser @@ -197,7 +198,9 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase): project = project_externaljob.ExternalJob(registry) if 'view-type' in yaml_content: - if yaml_content['view-type'] == "list": + if yaml_content['view-type'] == "all": + project = view_all.All(None) + elif yaml_content['view-type'] == "list": project = view_list.List(None) elif yaml_content['view-type'] == "pipeline": project = view_pipeline.Pipeline(None) diff --git a/tests/views/fixtures/view-all-minimal.xml b/tests/views/fixtures/view-all-minimal.xml new file mode 100644 index 000000000..32a30b387 --- /dev/null +++ b/tests/views/fixtures/view-all-minimal.xml @@ -0,0 +1,8 @@ + + + All + + false + false + + diff --git a/tests/views/fixtures/view-all-minimal.yaml b/tests/views/fixtures/view-all-minimal.yaml new file mode 100644 index 000000000..6b512a0fd --- /dev/null +++ b/tests/views/fixtures/view-all-minimal.yaml @@ -0,0 +1,2 @@ +name: All +view-type: all diff --git a/tests/views/test_views.py b/tests/views/test_views.py index 1f9924fc2..4ce73330f 100644 --- a/tests/views/test_views.py +++ b/tests/views/test_views.py @@ -13,11 +13,18 @@ # limitations under the License.import os import os +from jenkins_jobs.modules import view_all from jenkins_jobs.modules import view_list from jenkins_jobs.modules import view_pipeline from tests import base +class TestCaseModuleViewAll(base.BaseScenariosTestCase): + fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') + scenarios = base.get_scenarios(fixtures_path) + klass = view_all.All + + class TestCaseModuleViewList(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') scenarios = base.get_scenarios(fixtures_path)