Add support for All view-type

Change-Id: I49774d6d177382f30f117dab3836619a40d0e895
Signed-off-by: Thanh Ha <zxiiro@linux.com>
This commit is contained in:
Thanh Ha 2018-11-12 16:26:12 +08:00
parent 2854caec9e
commit 8c99e569b5
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
6 changed files with 71 additions and 1 deletions

View File

@ -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

View File

@ -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 =

View File

@ -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)

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<hudson.model.AllView>
<name>All</name>
<description/>
<filterExecutors>false</filterExecutors>
<filterQueue>false</filterQueue>
<properties class="hudson.model.View$PropertyList"/>
</hudson.model.AllView>

View File

@ -0,0 +1,2 @@
name: All
view-type: all

View File

@ -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)