Browse Source

Merge "Add type check for zuul conf"

tags/3.4.0
Zuul 5 months ago
parent
commit
46ff3fd009
3 changed files with 46 additions and 1 deletions
  1. 3
    0
      tests/fixtures/zuul.conf
  2. 37
    0
      tests/unit/test_default_config.py
  3. 6
    1
      zuul/lib/config.py

+ 3
- 0
tests/fixtures/zuul.conf View File

@@ -30,3 +30,6 @@ server=localhost
30 30
 port=25
31 31
 default_from=zuul@example.com
32 32
 default_to=you@example.com
33
+
34
+[web]
35
+static_cache_expiry=1200

+ 37
- 0
tests/unit/test_default_config.py View File

@@ -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
+
15
+import os
16
+
17
+import configparser
18
+
19
+from tests.base import BaseTestCase
20
+from tests.base import FIXTURE_DIR
21
+from zuul.lib.config import get_default
22
+
23
+
24
+class 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)

+ 6
- 1
zuul/lib/config.py View File

@@ -15,7 +15,12 @@ import os
15 15
 
16 16
 def get_default(config, section, option, default=None, expand_user=False):
17 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 24
     else:
20 25
         value = default
21 26
     if expand_user and value:

Loading…
Cancel
Save