2cf11f014c
* Create jenkins_jobs.config module with JJBConfig class. * Move DEFAULT_CONF from jenkins_jobs.cmd into jenkins_jobs.config * Move configuration initialization into JJBConfig * Create method, "do_magical_things" to handle arbitration between config file and arguments as well as setting default values for config file settings if it doesn't contain the expected keys. * Move JenkinsJobs.create_parser into its own module, jenkins_jobs.cli.parser, it can be used to provide default settings in the JJBConfig class when an argparse namespace object is not provided; this is primarily necessary because most of the original configuration initialization code relies on this being a namespace object (simple descendant of the object class). At this point JJBConfig isn't much more than an object-oriented version of the way configuration handling happened previously. Its current form, however, is more amenable to the ultimate goal of the 2.0 refactorings--namely, being able to pass a single config object around rather than breaking it up into apparently arbitrary settings necessary to instantiate the Builder class and its delegate objects. Change-Id: Ic0147e1dccbe620aaaba039a434e7cea6c670054
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
import os
|
|
|
|
import testtools
|
|
from jenkins_jobs.cli import entry
|
|
from tests.base import LoggingFixture
|
|
from tests.base import mock
|
|
|
|
|
|
class CmdTestsBase(LoggingFixture, testtools.TestCase):
|
|
|
|
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
|
|
|
def setUp(self):
|
|
super(CmdTestsBase, self).setUp()
|
|
|
|
# Testing the cmd module can sometimes result in the CacheStorage class
|
|
# attempting to create the cache directory multiple times as the tests
|
|
# are run in parallel. Stub out the CacheStorage to ensure that each
|
|
# test can safely create the cache directory without risk of
|
|
# interference.
|
|
cache_patch = mock.patch('jenkins_jobs.builder.CacheStorage',
|
|
autospec=True)
|
|
self.cache_mock = cache_patch.start()
|
|
self.addCleanup(cache_patch.stop)
|
|
|
|
self.default_config_file = os.path.join(self.fixtures_path,
|
|
'empty_builder.ini')
|
|
|
|
def execute_jenkins_jobs_with_args(self, args):
|
|
jenkins_jobs = entry.JenkinsJobs(args)
|
|
jenkins_jobs.execute()
|
|
|
|
|
|
class TestCmd(CmdTestsBase):
|
|
|
|
def test_with_empty_args(self):
|
|
"""
|
|
User passes no args, should fail with SystemExit
|
|
"""
|
|
with mock.patch('sys.stderr'):
|
|
self.assertRaises(SystemExit, entry.JenkinsJobs, [])
|