From 07c5bd1cc39716365797ad405beda32a822cfbbb Mon Sep 17 00:00:00 2001 From: Darragh Bailey Date: Sat, 3 May 2014 14:35:55 +0100 Subject: [PATCH] Test creation of multiple jobs from templates Concatenate each job XML created from the parsed yaml when using the YamlParser class for testing. Ensures that multiple jobs created from a single yaml file can be tested. Remove erroneous multiple job from scm_remote_deep_bug test. Change-Id: I2732a7303fefff1f321a1a5b7eef9144d168e39a --- doc/source/configuration.rst | 24 +-------- .../fixtures/scm_remote_deep_bug.yaml | 4 -- tests/yamlparser/fixtures/templates001.xml | 50 +++++++++++++++++++ tests/yamlparser/fixtures/templates001.yaml | 23 +++++++++ tests/yamlparser/test_yamlparser.py | 5 +- 5 files changed, 78 insertions(+), 28 deletions(-) create mode 100644 tests/yamlparser/fixtures/templates001.xml create mode 100644 tests/yamlparser/fixtures/templates001.yaml diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index fcf48a87b..f7a516b5a 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -152,29 +152,7 @@ with those values. The example above would create the job called The ``jobs:`` list can also allow for specifying job-specific substitutions as follows:: - - job-template: - name: '{name}-unit-tests' - builders: - - shell: unittest - publishers: - - email: - recipients: '{mail-to}' - - - job-template: - name: '{name}-perf-tests' - builders: - - shell: perftest - publishers: - - email: - recipients: '{mail-to}' - - - project: - name: project-name - jobs: - - '{name}-unit-tests': - mail-to: developer@nowhere.net - - '{name}-perf-tests': - mail-to: projmanager@nowhere.net +.. literalinclude:: /../../tests/yamlparser/fixtures/templates001.yaml If a variable is a list, the job template will be realized with the variable set to each value in the list. Multiple lists will lead to diff --git a/tests/yamlparser/fixtures/scm_remote_deep_bug.yaml b/tests/yamlparser/fixtures/scm_remote_deep_bug.yaml index 1f3bd21e3..8db596884 100644 --- a/tests/yamlparser/fixtures/scm_remote_deep_bug.yaml +++ b/tests/yamlparser/fixtures/scm_remote_deep_bug.yaml @@ -4,10 +4,6 @@ - git: url: 'http://example.org/' -- job: - name: 'scm_remote_deep_bug_job' - defaults: 'scm_remote_deep_bug_defs' - - job-template: name: 'scm_remote_deep_bug_tpl' defaults: 'scm_remote_deep_bug_defs' diff --git a/tests/yamlparser/fixtures/templates001.xml b/tests/yamlparser/fixtures/templates001.xml new file mode 100644 index 000000000..f2d687698 --- /dev/null +++ b/tests/yamlparser/fixtures/templates001.xml @@ -0,0 +1,50 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + perftest + + + + + projmanager@nowhere.net + false + false + + + + + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + unittest + + + + + developer@nowhere.net + false + false + + + + diff --git a/tests/yamlparser/fixtures/templates001.yaml b/tests/yamlparser/fixtures/templates001.yaml new file mode 100644 index 000000000..e2012fd87 --- /dev/null +++ b/tests/yamlparser/fixtures/templates001.yaml @@ -0,0 +1,23 @@ +- job-template: + name: '{name}-unit-tests' + builders: + - shell: unittest + publishers: + - email: + recipients: '{mail-to}' + +- job-template: + name: '{name}-perf-tests' + builders: + - shell: perftest + publishers: + - email: + recipients: '{mail-to}' + +- project: + name: project-name + jobs: + - '{name}-unit-tests': + mail-to: developer@nowhere.net + - '{name}-perf-tests': + mail-to: projmanager@nowhere.net diff --git a/tests/yamlparser/test_yamlparser.py b/tests/yamlparser/test_yamlparser.py index c8700c8af..395d45152 100644 --- a/tests/yamlparser/test_yamlparser.py +++ b/tests/yamlparser/test_yamlparser.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. +import operator import os from ConfigParser import ConfigParser from testtools import TestCase @@ -51,8 +52,10 @@ class TestCaseModuleYamlInclude(TestWithScenarios, TestCase, BaseTestCase): # Generate the XML tree parser.generateXML() + parser.jobs.sort(key=operator.attrgetter('name')) + # Prettify generated XML - pretty_xml = parser.jobs[0].output() + pretty_xml = "\n".join(job.output() for job in parser.jobs) self.assertThat( pretty_xml,