From 8a5fd48736f96de277e3439a7809a079620f0ba5 Mon Sep 17 00:00:00 2001 From: Kien Ha Date: Thu, 21 Jul 2016 20:54:17 -0400 Subject: [PATCH] Update hue light plugin to use convert xml - Rename test file to be more descriptive - Update doc unnecessary new lines Change-Id: I78f75c5fa0ea8cacb8acd6f591f0c11a4416e4a5 Signed-off-by: Kien Ha --- jenkins_jobs/modules/publishers.py | 35 +++++++++---------- .../{hue-light002.xml => hue-light-full.xml} | 0 ...{hue-light002.yaml => hue-light-full.yaml} | 0 3 files changed, 17 insertions(+), 18 deletions(-) rename tests/publishers/fixtures/{hue-light002.xml => hue-light-full.xml} (100%) rename tests/publishers/fixtures/{hue-light002.yaml => hue-light-full.yaml} (100%) diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index c880aabbd..18e9c8cf6 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -223,35 +223,34 @@ def hue_light(parser, xml_parent, data): :arg string unstable-build: Colour of unstable state (default 'yellow') :arg string bad-build: Colour of unsuccessful state (default 'red') - Example: + Full Example: - .. literalinclude:: - /../../tests/publishers/fixtures/hue-light-minimal.yaml + .. literalinclude:: /../../tests/publishers/fixtures/hue-light-full.yaml :language: yaml - .. literalinclude:: - /../../tests/publishers/fixtures/hue-light001.yaml + Minimal Example: + + .. literalinclude:: /../../tests/publishers/fixtures/hue-light-minimal.yaml :language: yaml """ hue_light = XML.SubElement( xml_parent, 'org.jenkinsci.plugins.hue__light.LightNotifier') hue_light.set('plugin', 'hue-light') - - if 'light-id' not in data: - raise MissingAttributeError('light-id') lightId = XML.SubElement(hue_light, 'lightId') - XML.SubElement(lightId, 'string').text = str(data.get( - 'light-id', '')) - XML.SubElement(hue_light, 'preBuild').text = data.get( - 'pre-build', 'blue') - XML.SubElement(hue_light, 'goodBuild').text = data.get( - 'good-build', 'green') - XML.SubElement(hue_light, 'unstableBuild').text = data.get( - 'unstable-build', 'yellow') - XML.SubElement(hue_light, 'badBuild').text = data.get( - 'bad-build', 'red') + id_mapping = [('light-id', 'string', None)] + helpers.convert_mapping_to_xml( + lightId, data, id_mapping, fail_required=True) + + build_mapping = [ + ('pre-build', 'preBuild', 'blue'), + ('good-build', 'goodBuild', 'green'), + ('unstable-build', 'unstableBuild', 'yellow'), + ('bad-build', 'badBuild', 'red'), + ] + helpers.convert_mapping_to_xml( + hue_light, data, build_mapping, fail_required=True) def campfire(parser, xml_parent, data): diff --git a/tests/publishers/fixtures/hue-light002.xml b/tests/publishers/fixtures/hue-light-full.xml similarity index 100% rename from tests/publishers/fixtures/hue-light002.xml rename to tests/publishers/fixtures/hue-light-full.xml diff --git a/tests/publishers/fixtures/hue-light002.yaml b/tests/publishers/fixtures/hue-light-full.yaml similarity index 100% rename from tests/publishers/fixtures/hue-light002.yaml rename to tests/publishers/fixtures/hue-light-full.yaml