def test_can_set_config_provider(self): foo_value_provider = mock.Mock(spec=BaseProvider) foo_value_provider.provide.return_value = 'foo' provider = ConfigValueStore(mapping={ 'fake_variable': foo_value_provider, }) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'foo') bar_value_provider = mock.Mock(spec=BaseProvider) bar_value_provider.provide.return_value = 'bar' provider.set_config_provider('fake_variable', bar_value_provider) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'bar')
def _get_config_variable_with_custom_methods(self, logical_name, methods): # If a custom list of methods was supplied we need to perserve the # behavior with the new system. To do so a new chain that is a copy of # the old one will be constructed, but only with the supplied methods # being added to the chain. This chain will be consulted for a value # and then thrown out. This is not efficient, nor is the methods arg # used in botocore, this is just for backwards compatibility. chain_builder = SubsetChainConfigFactory(session=self, methods=methods) mapping = create_botocore_default_config_mapping(self) for name, config_options in self.session_var_map.items(): config_name, env_vars, default, typecast = config_options build_chain_config_args = { 'conversion_func': typecast, 'default': default, } if 'instance' in methods: build_chain_config_args['instance_name'] = name if 'env' in methods: build_chain_config_args['env_var_names'] = env_vars if 'config' in methods: build_chain_config_args['config_property_name'] = config_name mapping[name] = chain_builder.create_config_chain( **build_chain_config_args ) config_store_component = ConfigValueStore( mapping=mapping ) value = config_store_component.get_config_variable(logical_name) return value
def test_config_store_deepcopy(self): config_store = ConfigValueStore() config_store.set_config_provider('foo', ConstantProvider('bar')) config_store_copy = copy.deepcopy(config_store) config_store_copy.set_config_provider('fizz', ConstantProvider('buzz')) assert config_store.get_config_variable('fizz') is None assert config_store_copy.get_config_variable('foo') == 'bar'
def test_can_set_config_provider(self): foo_value_provider = mock.Mock(spec=BaseProvider) foo_value_provider.provide.return_value = 'foo' provider = ConfigValueStore(mapping={ 'fake_variable': foo_value_provider, }) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'foo') bar_value_provider = mock.Mock(spec=BaseProvider) bar_value_provider.provide.return_value = 'bar' provider.set_config_provider('fake_variable', bar_value_provider) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'bar')
def _get_config_variable_with_custom_methods(self, logical_name, methods): # If a custom list of methods was supplied we need to perserve the # behavior with the new system. To do so a new chain that is a copy of # the old one will be constructed, but only with the supplied methods # being added to the chain. This chain will be consulted for a value # and then thrown out. This is not efficient, nor is the methods arg # used in botocore, this is just for backwards compatibility. chain_builder = SubsetChainConfigFactory(session=self, methods=methods) mapping = create_botocore_default_config_mapping( chain_builder ) for name, config_options in self.session_var_map.items(): config_name, env_vars, default, typecast = config_options build_chain_config_args = { 'conversion_func': typecast, 'default': default, } if 'instance' in methods: build_chain_config_args['instance_name'] = name if 'env' in methods: build_chain_config_args['env_var_names'] = env_vars if 'config' in methods: build_chain_config_args['config_property_name'] = config_name mapping[name] = chain_builder.create_config_chain( **build_chain_config_args ) config_store_component = ConfigValueStore( mapping=mapping ) value = config_store_component.get_config_variable(logical_name) return value
def test_does_provide_value_if_variable_exists(self): mock_value_provider = mock.Mock(spec=BaseProvider) mock_value_provider.provide.return_value = 'foo' provider = ConfigValueStore(mapping={ 'fake_variable': mock_value_provider, }) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'foo')
def test_does_provide_value_if_variable_exists(self): mock_value_provider = mock.Mock(spec=BaseProvider) mock_value_provider.provide.return_value = 'foo' provider = ConfigValueStore(mapping={ 'fake_variable': mock_value_provider, }) value = provider.get_config_variable('fake_variable') self.assertEqual(value, 'foo')
def test_can_get_config_provider_non_chain_provider(self): constant_provider = ConstantProvider(value='bar') config_value_store = ConfigValueStore( mapping={ 'fake_variable': constant_provider, }) provider = config_value_store.get_config_provider('fake_variable') value = config_value_store.get_config_variable('fake_variable') self.assertIsInstance(provider, ConstantProvider) self.assertEqual(value, 'bar')
def test_can_set_variable(self): provider = ConfigValueStore() provider.set_config_variable('fake_variable', 'foo') value = provider.get_config_variable('fake_variable') self.assertEquals(value, 'foo')
def test_does_provide_none_if_no_variable_exists(self): provider = ConfigValueStore() value = provider.get_config_variable('fake_variable') self.assertIsNone(value)
def test_can_set_variable(self): provider = ConfigValueStore() provider.set_config_variable('fake_variable', 'foo') value = provider.get_config_variable('fake_variable') self.assertEquals(value, 'foo')
def test_does_provide_none_if_no_variable_exists(self): provider = ConfigValueStore() value = provider.get_config_variable('fake_variable') self.assertIsNone(value)