Browse Source

Add support for All view-type

Change-Id: I49774d6d177382f30f117dab3836619a40d0e895
Signed-off-by: Thanh Ha <zxiiro@linux.com>
tags/2.8.0
Thanh Ha 7 months ago
parent
commit
8c99e569b5
No account linked to committer's email address

+ 49
- 0
jenkins_jobs/modules/view_all.py View File

@@ -0,0 +1,49 @@
1
+# Copyright 2018 Openstack Foundation
2
+
3
+# Licensed under the Apache License, Version 2.0 (the "License");
4
+# you may not use this file except in compliance with the License.
5
+# You may obtain a copy of the License at
6
+#
7
+#     http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+# Unless required by applicable law or agreed to in writing, software
10
+# distributed under the License is distributed on an "AS IS" BASIS,
11
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+# See the License for the specific language governing permissions and
13
+# limitations under the License.
14
+
15
+"""
16
+View support for All view-type.
17
+
18
+To create an all view specify ``all`` in the ``view-type`` attribute
19
+to the :ref:`view_all` definition.
20
+
21
+Example:
22
+
23
+    .. literalinclude::
24
+        /../../tests/views/fixtures/view-all-minimal.yaml
25
+"""
26
+
27
+import xml.etree.ElementTree as XML
28
+import jenkins_jobs.modules.base
29
+import jenkins_jobs.modules.helpers as helpers
30
+
31
+
32
+class All(jenkins_jobs.modules.base.Base):
33
+    sequence = 0
34
+
35
+    def root_xml(self, data):
36
+        root = XML.Element('hudson.model.AllView')
37
+
38
+        mapping = [
39
+            ('name', 'name', None),
40
+            ('description', 'description', ''),
41
+            ('filter-executors', 'filterExecutors', False),
42
+            ('filter-queue', 'filterQueue', False),
43
+        ]
44
+        helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True)
45
+
46
+        XML.SubElement(root, 'properties',
47
+                       {'class': 'hudson.model.View$PropertyList'})
48
+
49
+        return root

+ 1
- 0
setup.cfg View File

@@ -62,6 +62,7 @@ jenkins_jobs.projects =
62 62
     pipeline=jenkins_jobs.modules.project_pipeline:Pipeline
63 63
     workflow=jenkins_jobs.modules.project_workflow:Workflow
64 64
 jenkins_jobs.views =
65
+    all=jenkins_jobs.modules.view_all:All
65 66
     list=jenkins_jobs.modules.view_list:List
66 67
     pipeline=jenkins_jobs.modules.view_pipeline:Pipeline
67 68
 jenkins_jobs.builders =

+ 4
- 1
tests/base.py View File

@@ -43,6 +43,7 @@ from jenkins_jobs.modules import project_matrix
43 43
 from jenkins_jobs.modules import project_maven
44 44
 from jenkins_jobs.modules import project_multibranch
45 45
 from jenkins_jobs.modules import project_multijob
46
+from jenkins_jobs.modules import view_all
46 47
 from jenkins_jobs.modules import view_list
47 48
 from jenkins_jobs.modules import view_pipeline
48 49
 from jenkins_jobs.parser import YamlParser
@@ -197,7 +198,9 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
197 198
                 project = project_externaljob.ExternalJob(registry)
198 199
 
199 200
         if 'view-type' in yaml_content:
200
-            if yaml_content['view-type'] == "list":
201
+            if yaml_content['view-type'] == "all":
202
+                project = view_all.All(None)
203
+            elif yaml_content['view-type'] == "list":
201 204
                 project = view_list.List(None)
202 205
             elif yaml_content['view-type'] == "pipeline":
203 206
                 project = view_pipeline.Pipeline(None)

+ 8
- 0
tests/views/fixtures/view-all-minimal.xml View File

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

+ 2
- 0
tests/views/fixtures/view-all-minimal.yaml View File

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

+ 7
- 0
tests/views/test_views.py View File

@@ -13,11 +13,18 @@
13 13
 # limitations under the License.import os
14 14
 
15 15
 import os
16
+from jenkins_jobs.modules import view_all
16 17
 from jenkins_jobs.modules import view_list
17 18
 from jenkins_jobs.modules import view_pipeline
18 19
 from tests import base
19 20
 
20 21
 
22
+class TestCaseModuleViewAll(base.BaseScenariosTestCase):
23
+    fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
24
+    scenarios = base.get_scenarios(fixtures_path)
25
+    klass = view_all.All
26
+
27
+
21 28
 class TestCaseModuleViewList(base.BaseScenariosTestCase):
22 29
     fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
23 30
     scenarios = base.get_scenarios(fixtures_path)

Loading…
Cancel
Save