Allow test command to use conf files

It should be possible to run the `test` command with a custom config.
This allows examination of the XML outputted where config settings can
change the outputted XML. Otherwise any non-default config values will
only be used when running the `update` comand.

Add a simple test to confirm that the custom url that is unlikely to
ever be a valid default value is returned when the command is set to
`test` and a custom config is specified.

Change-Id: I193e83314a35943406bff5b182f20693edd640ba
This commit is contained in:
Darragh Bailey 2014-07-08 23:58:03 +01:00
parent 1df929c58a
commit 1eb343616f
3 changed files with 20 additions and 3 deletions

View File

@ -118,12 +118,12 @@ def setup_config_settings(options):
config = ConfigParser.ConfigParser()
## Load default config always
config.readfp(cStringIO.StringIO(DEFAULT_CONF))
if options.command == 'test':
logger.debug("Not reading config for test output generation")
elif os.path.isfile(conf):
if os.path.isfile(conf):
logger.debug("Reading config from {0}".format(conf))
conffp = open(conf, 'r')
config.readfp(conffp)
elif options.command == 'test':
logger.debug("Not requiring config for test output generation")
else:
raise JenkinsJobsException(
"A valid configuration file is required when not run as a test"

View File

@ -0,0 +1,2 @@
[jenkins]
url=http://test-jenkins.with.non.default.url:8080/

View File

@ -83,3 +83,18 @@ class CmdTests(testtools.TestCase):
'r',
'utf-8').read()
self.assertEqual(console_out.getvalue(), xml_content)
def test_config_with_test(self):
"""
Run test mode and pass a config file
"""
args = self.parser.parse_args(['--conf',
os.path.join(self.fixtures_path,
'cmd-001.conf'),
'test',
os.path.join(self.fixtures_path,
'cmd-001.yaml'),
'foo-job'])
config = cmd.setup_config_settings(args)
self.assertEqual(config.get('jenkins', 'url'),
"http://test-jenkins.with.non.default.url:8080/")