summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-12-29 14:30:17 +0000
committerGerrit Code Review <review@openstack.org>2018-12-29 14:30:17 +0000
commit46ff3fd009822ac99bb3001773b5678e6be4374a (patch)
treedc2797267b47a0f481aebe329fb36a57a8e57f50
parentea3e777469a67fb3c55041df22f46f79a4f91f7c (diff)
parente2a2a2fd06bfffd30b1acfcd58cf2f5a30512271 (diff)
Merge "Add type check for zuul conf"
-rw-r--r--tests/fixtures/zuul.conf3
-rw-r--r--tests/unit/test_default_config.py37
-rw-r--r--zuul/lib/config.py7
3 files changed, 46 insertions, 1 deletions
diff --git a/tests/fixtures/zuul.conf b/tests/fixtures/zuul.conf
index 5d79378..d915e38 100644
--- a/tests/fixtures/zuul.conf
+++ b/tests/fixtures/zuul.conf
@@ -30,3 +30,6 @@ server=localhost
30port=25 30port=25
31default_from=zuul@example.com 31default_from=zuul@example.com
32default_to=you@example.com 32default_to=you@example.com
33
34[web]
35static_cache_expiry=1200
diff --git a/tests/unit/test_default_config.py b/tests/unit/test_default_config.py
new file mode 100644
index 0000000..afdd12d
--- /dev/null
+++ b/tests/unit/test_default_config.py
@@ -0,0 +1,37 @@
1# Copyright 2018 EasyStack, Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import os
16
17import configparser
18
19from tests.base import BaseTestCase
20from tests.base import FIXTURE_DIR
21from zuul.lib.config import get_default
22
23
24class TestDefaultConfigValue(BaseTestCase):
25 config_file = 'zuul.conf'
26
27 def setUp(self):
28 super(TestDefaultConfigValue, self).setUp()
29 self.config = configparser.ConfigParser()
30 self.config.read(os.path.join(FIXTURE_DIR, self.config_file))
31
32 def test_default_config_value(self):
33 default_value = get_default(self.config,
34 'web',
35 'static_cache_expiry',
36 default=3600)
37 self.assertEqual(1200, default_value)
diff --git a/zuul/lib/config.py b/zuul/lib/config.py
index 9cdf66e..b13fc3d 100644
--- a/zuul/lib/config.py
+++ b/zuul/lib/config.py
@@ -15,7 +15,12 @@ import os
15 15
16def get_default(config, section, option, default=None, expand_user=False): 16def get_default(config, section, option, default=None, expand_user=False):
17 if config.has_option(section, option): 17 if config.has_option(section, option):
18 value = config.get(section, option) 18 # Need to be ensured that we get suitable
19 # type from config file by default value
20 if isinstance(default, int):
21 value = config.getint(section, option)
22 else:
23 value = config.get(section, option)
19 else: 24 else:
20 value = default 25 value = default
21 if expand_user and value: 26 if expand_user and value: