def test_loading_getter(self): called_opts = [] vals = { 'a-int': 44, 'a-bool': False, 'a-float': 99.99, 'a-str': 'value' } val = uuid.uuid4().hex def _getter(opt): called_opts.append(opt.name) # return str because oslo.config should convert them back return str(vals[opt.name]) p = utils.MockLoader().load_from_options_getter(_getter, other=val) self.assertEqual(set(vals), set(called_opts)) for k, v in vals.items(): # replace - to _ because it's the dest used to create kwargs self.assertEqual(v, p[k.replace('-', '_')]) # check that additional kwargs get passed through self.assertEqual(val, p['other'])
def test_other_params(self, m): m.return_value = utils.MockManager(utils.MockLoader()) driver_name = uuid.uuid4().hex opts = loading.get_auth_plugin_conf_options(utils.MockLoader()) self.conf_fixture.register_opts(opts, group=self.GROUP) self.conf_fixture.config(auth_type=driver_name, group=self.GROUP, **self.TEST_VALS) a = loading.load_auth_from_conf_options(self.conf_fixture.conf, self.GROUP) self.assertTestVals(a) m.assert_called_once_with(namespace=loading.PLUGIN_NAMESPACE, name=driver_name, invoke_on_load=True)
def test_same_section(self, m): opts = loading.get_auth_plugin_conf_options(utils.MockLoader()) self.conf_fixture.register_opts(opts, group=self.GROUP) loading.register_auth_conf_options(self.conf_fixture.conf, group=self.GROUP) self.conf_fixture.config(auth_type=uuid.uuid4().hex, group=self.GROUP, **self.TEST_VALS) a = loading.load_auth_from_conf_options(self.conf_fixture.conf, self.GROUP) self.assertTestVals(a)
def test_diff_section(self, m): section = uuid.uuid4().hex self.conf_fixture.config(auth_section=section, group=self.GROUP) loading.register_auth_conf_options(self.conf_fixture.conf, group=self.GROUP) self.conf_fixture.register_opts(to_oslo_opts( utils.MockLoader().get_options()), group=section) self.conf_fixture.config(group=section, auth_type=uuid.uuid4().hex, **self.TEST_VALS) a = loading.load_auth_from_conf_options(self.conf_fixture.conf, self.GROUP) self.assertTestVals(a)
def test_loading_getter_with_kwargs(self): called_opts = set() vals = {'a-bool': False, 'a-float': 99.99} def _getter(opt): called_opts.add(opt.name) # return str because oslo.config should convert them back return str(vals[opt.name]) p = utils.MockLoader().load_from_options_getter(_getter, a_int=66, a_str='another') # only the options not passed by kwargs should get passed to getter self.assertEqual(set(('a-bool', 'a-float')), called_opts) self.assertEqual(False, p['a_bool']) self.assertEqual(99.99, p['a_float']) self.assertEqual('another', p['a_str']) self.assertEqual(66, p['a_int'])
def test_with_default_type_value(self, m): default = utils.MockLoader() klass = loading.register_auth_argparse_arguments(self.p, [], default=default) self.assertIsInstance(klass, utils.MockLoader) self.assertEqual(0, m.call_count)