murano/murano/tests/unit/base.py
LiuNanke e0c1653fa8 make enforce_type=True in CONF.set_override
Method CONF.set_override to change config option's
value with designated value in unit test, but never check if the
designated vaule is valid. Each config option has a type like StrOpt,
BoolOpt, etc. StrOpt with parameter choices only allows values in set
of choices. In short, each config option has limitation for type
and value. In production code, oslo.conf can ensure user's input is
valid, but in unit test, test methods can pass if we use method
CONF.set_override without parameter enforce_type=True even we pass wrong
type or wrong value to config option. This commit makes sure calling
method CONF.set_override with enforce_type=True and fixes violations.

Note: We can't set enforce_type=True by default in oslo.config now, it
may break all project's unit test. We can switch enforce_type=True by
default when all project fix violations like this commit.
Related-Bug: #1517839

Change-Id: Ia9f6b8a04290f93699fc1f613ce0e841f040d4ae
2016-01-13 23:28:26 +08:00

44 lines
1.3 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import fixtures
from oslo_log import log as logging
import testtools
from murano.common import config
from murano.db import api as db_api
CONF = config.CONF
logging.register_options(CONF)
logging.setup(CONF, 'murano')
class MuranoTestCase(testtools.TestCase):
def setUp(self):
super(MuranoTestCase, self).setUp()
self.useFixture(fixtures.FakeLogger('murano'))
def override_config(self, name, override, group=None):
CONF.set_override(name, override, group, enforce_type=True)
self.addCleanup(CONF.clear_override, name, group)
class MuranoWithDBTestCase(MuranoTestCase):
def setUp(self):
super(MuranoWithDBTestCase, self).setUp()
self.override_config('connection', "sqlite://", group='database')
db_api.setup_db()
self.addCleanup(db_api.drop_db)