Test: make enforce_type=True in CONF.set_override and fix error
Each config option has limitation for type and value. We make enforce_type=True to check whether we pass wrong type. Also fixes a type error issue in test_db_manager.py. Change-Id: I6e111e21588525d32b05eeba75b06583d4e605ed Related-Bug: #1517839
This commit is contained in:
parent
4662f248b3
commit
473cee8ad3
|
@ -32,7 +32,8 @@ class FunctionalTest(unittest.TestCase):
|
|||
"""
|
||||
|
||||
def setUp(self):
|
||||
cfg.CONF.set_override("enable_authentication", False)
|
||||
cfg.CONF.set_override("enable_authentication", False,
|
||||
enforce_type=True)
|
||||
self.app = testing.load_test_app(os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
'config.py'
|
||||
|
|
|
@ -47,9 +47,11 @@ class FunctionalTest(base.DbTestCase):
|
|||
def setUp(self):
|
||||
super(FunctionalTest, self).setUp()
|
||||
cfg.CONF.set_override("auth_version", "v2.0",
|
||||
group='keystone_authtoken')
|
||||
group='keystone_authtoken',
|
||||
enforce_type=True)
|
||||
cfg.CONF.set_override("admin_user", "admin",
|
||||
group='keystone_authtoken')
|
||||
group='keystone_authtoken',
|
||||
enforce_type=True)
|
||||
self.app = self._make_app()
|
||||
|
||||
def reset_pecan():
|
||||
|
|
|
@ -120,7 +120,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
|
|||
self.assertEqual(msg, actual_msg)
|
||||
|
||||
def test_hook_server_debug_on_serverfault(self):
|
||||
cfg.CONF.set_override('debug', True)
|
||||
cfg.CONF.set_override('debug', True, enforce_type=True)
|
||||
self.root_convert_mock.side_effect = Exception(self.MSG_WITH_TRACE)
|
||||
|
||||
response = self.get_json('/', path_prefix='', expect_errors=True)
|
||||
|
@ -130,7 +130,7 @@ class TestNoExceptionTracebackHook(api_base.FunctionalTest):
|
|||
self.assertEqual(self.MSG_WITHOUT_TRACE, actual_msg)
|
||||
|
||||
def test_hook_server_debug_on_clientfault(self):
|
||||
cfg.CONF.set_override('debug', True)
|
||||
cfg.CONF.set_override('debug', True, enforce_type=True)
|
||||
client_error = Exception(self.MSG_WITH_TRACE)
|
||||
client_error.code = 400
|
||||
self.root_convert_mock.side_effect = client_error
|
||||
|
|
|
@ -41,7 +41,8 @@ class TestApiUtilsValidScenarios(base.TestCase):
|
|||
]
|
||||
|
||||
def test_validate_limit(self):
|
||||
cfg.CONF.set_override("max_limit", self.max_limit, group="api")
|
||||
cfg.CONF.set_override("max_limit", self.max_limit, group="api",
|
||||
enforce_type=True)
|
||||
actual_limit = v1_utils.validate_limit(self.limit)
|
||||
self.assertEqual(actual_limit, self.expected)
|
||||
|
||||
|
@ -53,7 +54,8 @@ class TestApiUtilsInvalidScenarios(base.TestCase):
|
|||
]
|
||||
|
||||
def test_validate_limit_invalid_cases(self):
|
||||
cfg.CONF.set_override("max_limit", self.max_limit, group="api")
|
||||
cfg.CONF.set_override("max_limit", self.max_limit, group="api",
|
||||
enforce_type=True)
|
||||
self.assertRaises(
|
||||
wsme.exc.ClientSideError, v1_utils.validate_limit, self.limit
|
||||
)
|
||||
|
|
|
@ -410,7 +410,8 @@ class TestListAction(api_base.FunctionalTest):
|
|||
self.assertIn(next_marker, response['next'])
|
||||
|
||||
def test_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
cfg.CONF.set_override('max_limit', 3, 'api',
|
||||
enforce_type=True)
|
||||
for id_ in range(5):
|
||||
obj_utils.create_test_action(self.context, id=id_,
|
||||
uuid=utils.generate_uuid())
|
||||
|
|
|
@ -267,7 +267,8 @@ class TestListActionPlan(api_base.FunctionalTest):
|
|||
self.assertIn(next_marker, response['next'])
|
||||
|
||||
def test_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
cfg.CONF.set_override('max_limit', 3, 'api',
|
||||
enforce_type=True)
|
||||
for id_ in range(5):
|
||||
obj_utils.create_action_plan_without_audit(
|
||||
self.context, id=id_, uuid=utils.generate_uuid(),
|
||||
|
|
|
@ -195,7 +195,8 @@ class TestListAuditTemplate(api_base.FunctionalTest):
|
|||
self.assertIn(next_marker, response['next'])
|
||||
|
||||
def test_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
cfg.CONF.set_override('max_limit', 3, 'api',
|
||||
enforce_type=True)
|
||||
for id_ in range(5):
|
||||
obj_utils.create_test_audit_template(
|
||||
self.context, id=id_, uuid=utils.generate_uuid(),
|
||||
|
|
|
@ -204,7 +204,8 @@ class TestListAudit(api_base.FunctionalTest):
|
|||
self.assertIn(next_marker, response['next'])
|
||||
|
||||
def test_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
cfg.CONF.set_override('max_limit', 3, 'api',
|
||||
enforce_type=True)
|
||||
for id_ in range(5):
|
||||
obj_utils.create_test_audit(self.context, id=id_,
|
||||
uuid=utils.generate_uuid())
|
||||
|
|
|
@ -26,7 +26,7 @@ class TestListGoal(api_base.FunctionalTest):
|
|||
"DUMMY_1": "dummy", "DUMMY_2": "dummy",
|
||||
"DUMMY_3": "dummy", "DUMMY_4": "dummy",
|
||||
},
|
||||
group='watcher_goals')
|
||||
group='watcher_goals', enforce_type=True)
|
||||
|
||||
def _assert_goal_fields(self, goal):
|
||||
goal_fields = ['name', 'strategy']
|
||||
|
@ -65,6 +65,6 @@ class TestListGoal(api_base.FunctionalTest):
|
|||
self.assertEqual(2, len(response['goals']))
|
||||
|
||||
def test_goals_collection_links_default_limit(self):
|
||||
cfg.CONF.set_override('max_limit', 3, 'api')
|
||||
cfg.CONF.set_override('max_limit', 3, 'api', enforce_type=True)
|
||||
response = self.get_json('/goals')
|
||||
self.assertEqual(3, len(response['goals']))
|
||||
|
|
|
@ -34,7 +34,7 @@ from watcher.tests import conf_fixture
|
|||
|
||||
CONF = cfg.CONF
|
||||
log.register_options(CONF)
|
||||
CONF.set_override('use_stderr', False)
|
||||
CONF.set_override('use_stderr', False, enforce_type=True)
|
||||
|
||||
|
||||
class BaseTestCase(testscenarios.WithScenarios, base.BaseTestCase):
|
||||
|
@ -103,7 +103,7 @@ class TestCase(BaseTestCase):
|
|||
"""Override config options for a test."""
|
||||
group = kw.pop('group', None)
|
||||
for k, v in six.iteritems(kw):
|
||||
CONF.set_override(k, v, group)
|
||||
CONF.set_override(k, v, group, enforce_type=True)
|
||||
|
||||
def path_get(self, project_file=None):
|
||||
"""Get the absolute path to a file. Used for testing the API.
|
||||
|
|
|
@ -39,18 +39,18 @@ class TestDBManageRunApp(TestCase):
|
|||
@patch("watcher.cmd.dbmanage.service.prepare_service")
|
||||
@patch("watcher.cmd.dbmanage.sys")
|
||||
def test_run_db_manage_app(self, m_sys, m_prepare_service):
|
||||
# Patch command arguments
|
||||
# Patch command function
|
||||
m_func = Mock()
|
||||
cfg.CONF.register_opt(cfg.Opt("func"), group="command")
|
||||
cfg.CONF.set_override("func", m_func, group="command")
|
||||
cfg.CONF.register_opt(cfg.SubCommandOpt("command"))
|
||||
cfg.CONF.command.func = m_func
|
||||
|
||||
# Only append if the command is not None
|
||||
m_sys.argv = list(filter(None, ["watcher-db-manage", self.command]))
|
||||
|
||||
dbmanage.main()
|
||||
self.assertEqual(m_func.call_count, 1)
|
||||
m_prepare_service.assert_called_once_with(
|
||||
["watcher-db-manage", self.expected]
|
||||
)
|
||||
["watcher-db-manage", self.expected])
|
||||
|
||||
|
||||
class TestDBManageRunCommand(TestCase):
|
||||
|
|
|
@ -49,7 +49,8 @@ class TestCeilometer(BaseTestCase):
|
|||
@mock.patch('ceilometerclient.v2.client.Client', autospec=True)
|
||||
def test_get_ceilometer_v2(self, mock_keystone, mock_ceilometer):
|
||||
cfg.CONF.set_override(
|
||||
'auth_uri', "http://127.0.0.1:9898/v2", group="keystone_authtoken"
|
||||
'auth_uri', "http://127.0.0.1:9898/v2", group="keystone_authtoken",
|
||||
enforce_type=True
|
||||
)
|
||||
c = CeilometerClient(api_version='2')
|
||||
from ceilometerclient.v2 import Client
|
||||
|
|
|
@ -35,7 +35,8 @@ class TestKeystone(BaseTestCase):
|
|||
def test_get_endpoint_v2(self, keystone):
|
||||
expected_endpoint = "http://ip:port/v2"
|
||||
cfg.CONF.set_override(
|
||||
'auth_uri', expected_endpoint, group="keystone_authtoken"
|
||||
'auth_uri', expected_endpoint, group="keystone_authtoken",
|
||||
enforce_type=True
|
||||
)
|
||||
ks = mock.Mock()
|
||||
ks.service_catalog.url_for.return_value = expected_endpoint
|
||||
|
|
|
@ -90,7 +90,8 @@ class Database(fixtures.Fixture):
|
|||
class DbTestCase(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
cfg.CONF.set_override("enable_authentication", False)
|
||||
cfg.CONF.set_override("enable_authentication", False,
|
||||
enforce_type=True)
|
||||
super(DbTestCase, self).setUp()
|
||||
|
||||
self.dbapi = dbapi.get_instance()
|
||||
|
|
|
@ -32,7 +32,8 @@ class TestStrategySelector(TestCase):
|
|||
@patch.object(DefaultStrategyLoader, 'load')
|
||||
def test_define_from_goal(self, mock_call):
|
||||
cfg.CONF.set_override('goals',
|
||||
{"DUMMY": "fake"}, group='watcher_goals')
|
||||
{"DUMMY": "fake"}, group='watcher_goals',
|
||||
enforce_type=True)
|
||||
expected_goal = 'DUMMY'
|
||||
expected_strategy = CONF.watcher_goals.goals[expected_goal]
|
||||
self.strategy_selector.define_from_goal(expected_goal)
|
||||
|
@ -40,7 +41,8 @@ class TestStrategySelector(TestCase):
|
|||
|
||||
@patch.object(DefaultStrategyLoader, 'load')
|
||||
def test_define_from_goal_with_incorrect_mapping(self, mock_call):
|
||||
cfg.CONF.set_override('goals', {}, group='watcher_goals')
|
||||
cfg.CONF.set_override('goals', {}, group='watcher_goals',
|
||||
enforce_type=True)
|
||||
self.assertRaises(WatcherException,
|
||||
self.strategy_selector.define_from_goal,
|
||||
"DUMMY")
|
||||
|
|
|
@ -34,6 +34,7 @@ class PolicyFixture(fixtures.Fixture):
|
|||
'policy.json')
|
||||
with open(self.policy_file_name, 'w') as policy_file:
|
||||
policy_file.write(fake_policy.get_policy_data(self.compat))
|
||||
CONF.set_override('policy_file', self.policy_file_name)
|
||||
CONF.set_override('policy_file', self.policy_file_name,
|
||||
enforce_type=True)
|
||||
w_policy._ENFORCER = None
|
||||
self.addCleanup(w_policy.get_enforcer().clear)
|
||||
|
|
Loading…
Reference in New Issue