summaryrefslogtreecommitdiffstats
path: root/tests/cmd/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cmd/test_config.py')
-rw-r--r--tests/cmd/test_config.py107
1 files changed, 54 insertions, 53 deletions
diff --git a/tests/cmd/test_config.py b/tests/cmd/test_config.py
index 6cbb6d4d..ecae8a9a 100644
--- a/tests/cmd/test_config.py
+++ b/tests/cmd/test_config.py
@@ -9,25 +9,25 @@ from jenkins_jobs.cli import entry
from jenkins_jobs import builder
-@mock.patch('jenkins_jobs.builder.JenkinsManager.get_plugins_info',
- mock.MagicMock)
+@mock.patch("jenkins_jobs.builder.JenkinsManager.get_plugins_info", mock.MagicMock)
class TestConfigs(CmdTestsBase):
- global_conf = '/etc/jenkins_jobs/jenkins_jobs.ini'
- user_conf = os.path.join(os.path.expanduser('~'), '.config',
- 'jenkins_jobs', 'jenkins_jobs.ini')
- local_conf = os.path.join(os.path.dirname(__file__),
- 'jenkins_jobs.ini')
+ global_conf = "/etc/jenkins_jobs/jenkins_jobs.ini"
+ user_conf = os.path.join(
+ os.path.expanduser("~"), ".config", "jenkins_jobs", "jenkins_jobs.ini"
+ )
+ local_conf = os.path.join(os.path.dirname(__file__), "jenkins_jobs.ini")
def test_use_global_config(self):
"""
Verify that JJB uses the global config file by default
"""
- args = ['test', 'foo']
- conffp = io.open(self.default_config_file, 'r', encoding='utf-8')
+ args = ["test", "foo"]
+ conffp = io.open(self.default_config_file, "r", encoding="utf-8")
+
+ with patch("os.path.isfile", return_value=True) as m_isfile:
- with patch('os.path.isfile', return_value=True) as m_isfile:
def side_effect(path):
if path == self.global_conf:
return True
@@ -35,36 +35,35 @@ class TestConfigs(CmdTestsBase):
m_isfile.side_effect = side_effect
- with patch('io.open', return_value=conffp) as m_open:
+ with patch("io.open", return_value=conffp) as m_open:
entry.JenkinsJobs(args, config_file_required=True)
- m_open.assert_called_with(self.global_conf, 'r',
- encoding='utf-8')
+ m_open.assert_called_with(self.global_conf, "r", encoding="utf-8")
def test_use_config_in_user_home(self):
"""
Verify that JJB uses config file in user home folder
"""
- args = ['test', 'foo']
+ args = ["test", "foo"]
+
+ conffp = io.open(self.default_config_file, "r", encoding="utf-8")
+ with patch("os.path.isfile", return_value=True) as m_isfile:
- conffp = io.open(self.default_config_file, 'r', encoding='utf-8')
- with patch('os.path.isfile', return_value=True) as m_isfile:
def side_effect(path):
if path == self.user_conf:
return True
return False
m_isfile.side_effect = side_effect
- with patch('io.open', return_value=conffp) as m_open:
+ with patch("io.open", return_value=conffp) as m_open:
entry.JenkinsJobs(args, config_file_required=True)
- m_open.assert_called_with(self.user_conf, 'r',
- encoding='utf-8')
+ m_open.assert_called_with(self.user_conf, "r", encoding="utf-8")
def test_non_existing_config_dir(self):
"""
Run test mode and pass a non-existing configuration directory
"""
- args = ['--conf', self.default_config_file, 'test', 'foo']
+ args = ["--conf", self.default_config_file, "test", "foo"]
jenkins_jobs = entry.JenkinsJobs(args)
self.assertRaises(IOError, jenkins_jobs.execute)
@@ -72,8 +71,7 @@ class TestConfigs(CmdTestsBase):
"""
Run test mode and pass a non-existing configuration file
"""
- args = ['--conf', self.default_config_file, 'test',
- 'non-existing.yaml']
+ args = ["--conf", self.default_config_file, "test", "non-existing.yaml"]
jenkins_jobs = entry.JenkinsJobs(args)
self.assertRaises(IOError, jenkins_jobs.execute)
@@ -82,37 +80,42 @@ class TestConfigs(CmdTestsBase):
Run test mode and check config settings from conf file retained
when none of the global CLI options are set.
"""
- config_file = os.path.join(self.fixtures_path,
- 'settings_from_config.ini')
- args = ['--conf', config_file, 'test', 'dummy.yaml']
+ config_file = os.path.join(self.fixtures_path, "settings_from_config.ini")
+ args = ["--conf", config_file, "test", "dummy.yaml"]
jenkins_jobs = entry.JenkinsJobs(args)
jjb_config = jenkins_jobs.jjb_config
- self.assertEqual(jjb_config.jenkins['user'], "jenkins_user")
- self.assertEqual(jjb_config.jenkins['password'], "jenkins_password")
- self.assertEqual(jjb_config.builder['ignore_cache'], True)
- self.assertEqual(jjb_config.builder['flush_cache'], True)
- self.assertEqual(jjb_config.builder['update'], "all")
- self.assertEqual(
- jjb_config.yamlparser['allow_empty_variables'], True)
+ self.assertEqual(jjb_config.jenkins["user"], "jenkins_user")
+ self.assertEqual(jjb_config.jenkins["password"], "jenkins_password")
+ self.assertEqual(jjb_config.builder["ignore_cache"], True)
+ self.assertEqual(jjb_config.builder["flush_cache"], True)
+ self.assertEqual(jjb_config.builder["update"], "all")
+ self.assertEqual(jjb_config.yamlparser["allow_empty_variables"], True)
def test_config_options_overriden_by_cli(self):
"""
Run test mode and check config settings from conf file retained
when none of the global CLI options are set.
"""
- args = ['--user', 'myuser', '--password', 'mypassword',
- '--ignore-cache', '--flush-cache', '--allow-empty-variables',
- 'test', 'dummy.yaml']
+ args = [
+ "--user",
+ "myuser",
+ "--password",
+ "mypassword",
+ "--ignore-cache",
+ "--flush-cache",
+ "--allow-empty-variables",
+ "test",
+ "dummy.yaml",
+ ]
jenkins_jobs = entry.JenkinsJobs(args)
jjb_config = jenkins_jobs.jjb_config
- self.assertEqual(jjb_config.jenkins['user'], "myuser")
- self.assertEqual(jjb_config.jenkins['password'], "mypassword")
- self.assertEqual(jjb_config.builder['ignore_cache'], True)
- self.assertEqual(jjb_config.builder['flush_cache'], True)
- self.assertEqual(
- jjb_config.yamlparser['allow_empty_variables'], True)
-
- @mock.patch('jenkins_jobs.cli.subcommand.update.JenkinsManager')
+ self.assertEqual(jjb_config.jenkins["user"], "myuser")
+ self.assertEqual(jjb_config.jenkins["password"], "mypassword")
+ self.assertEqual(jjb_config.builder["ignore_cache"], True)
+ self.assertEqual(jjb_config.builder["flush_cache"], True)
+ self.assertEqual(jjb_config.yamlparser["allow_empty_variables"], True)
+
+ @mock.patch("jenkins_jobs.cli.subcommand.update.JenkinsManager")
def test_update_timeout_not_set(self, jenkins_mock):
"""Check that timeout is left unset
@@ -120,8 +123,8 @@ class TestConfigs(CmdTestsBase):
provided via the config option.
"""
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- args = ['--conf', self.default_config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ args = ["--conf", self.default_config_file, "update", path]
jenkins_mock.return_value.update_jobs.return_value = ([], 0)
jenkins_mock.return_value.update_views.return_value = ([], 0)
@@ -131,10 +134,9 @@ class TestConfigs(CmdTestsBase):
# contains the expected timeout value.
jjb_config = jenkins_mock.call_args[0][0]
- self.assertEqual(jjb_config.jenkins['timeout'],
- builder._DEFAULT_TIMEOUT)
+ self.assertEqual(jjb_config.jenkins["timeout"], builder._DEFAULT_TIMEOUT)
- @mock.patch('jenkins_jobs.cli.subcommand.update.JenkinsManager')
+ @mock.patch("jenkins_jobs.cli.subcommand.update.JenkinsManager")
def test_update_timeout_set(self, jenkins_mock):
"""Check that timeout is set correctly
@@ -142,10 +144,9 @@ class TestConfigs(CmdTestsBase):
provided via the config option.
"""
- path = os.path.join(self.fixtures_path, 'cmd-002.yaml')
- config_file = os.path.join(self.fixtures_path,
- 'non-default-timeout.ini')
- args = ['--conf', config_file, 'update', path]
+ path = os.path.join(self.fixtures_path, "cmd-002.yaml")
+ config_file = os.path.join(self.fixtures_path, "non-default-timeout.ini")
+ args = ["--conf", config_file, "update", path]
jenkins_mock.return_value.update_jobs.return_value = ([], 0)
jenkins_mock.return_value.update_views.return_value = ([], 0)
@@ -155,4 +156,4 @@ class TestConfigs(CmdTestsBase):
# contains the expected timeout value.
jjb_config = jenkins_mock.call_args[0][0]
- self.assertEqual(jjb_config.jenkins['timeout'], 0.2)
+ self.assertEqual(jjb_config.jenkins["timeout"], 0.2)