2014-06-02 15:14:47 -07:00
|
|
|
import os
|
2014-11-10 13:07:55 +00:00
|
|
|
|
2015-05-05 10:23:24 -07:00
|
|
|
from jenkins_jobs.cli import entry
|
2016-06-29 12:20:42 +01:00
|
|
|
from tests import base
|
2015-01-29 21:36:51 +00:00
|
|
|
from tests.base import mock
|
2014-06-02 15:14:47 -07:00
|
|
|
|
|
|
|
|
2016-06-29 12:20:42 +01:00
|
|
|
class CmdTestsBase(base.BaseTestCase):
|
2014-06-02 15:14:47 -07:00
|
|
|
|
|
|
|
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
|
|
|
|
2014-10-29 14:57:21 -07:00
|
|
|
def setUp(self):
|
2014-11-11 23:50:45 -08:00
|
|
|
super(CmdTestsBase, self).setUp()
|
|
|
|
|
2016-05-22 22:56:59 -07:00
|
|
|
# Testing the cmd module can sometimes result in the JobCache class
|
2014-11-11 23:50:45 -08:00
|
|
|
# attempting to create the cache directory multiple times as the tests
|
2016-05-22 22:56:59 -07:00
|
|
|
# are run in parallel. Stub out the JobCache to ensure that each
|
2014-11-11 23:50:45 -08:00
|
|
|
# test can safely create the cache directory without risk of
|
|
|
|
# interference.
|
2016-05-22 22:56:59 -07:00
|
|
|
cache_patch = mock.patch('jenkins_jobs.builder.JobCache',
|
2015-05-08 21:07:23 +01:00
|
|
|
autospec=True)
|
|
|
|
self.cache_mock = cache_patch.start()
|
|
|
|
self.addCleanup(cache_patch.stop)
|
2014-10-29 14:57:21 -07:00
|
|
|
|
2015-05-05 10:23:24 -07:00
|
|
|
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()
|
2014-11-11 23:50:45 -08:00
|
|
|
|
|
|
|
|
2015-12-23 14:58:45 -08:00
|
|
|
class TestCmd(CmdTestsBase):
|
2014-10-29 14:57:21 -07:00
|
|
|
|
2014-06-02 15:14:47 -07:00
|
|
|
def test_with_empty_args(self):
|
|
|
|
"""
|
|
|
|
User passes no args, should fail with SystemExit
|
|
|
|
"""
|
|
|
|
with mock.patch('sys.stderr'):
|
2015-05-05 10:23:24 -07:00
|
|
|
self.assertRaises(SystemExit, entry.JenkinsJobs, [])
|