コード例 #1
0
    def test_property_no_translation_if_user_parameter_missing(self):
        """Test translation in the case of missing parameter"""
        schema = {
            'source': properties.Schema(properties.Schema.STRING),
            'destination': properties.Schema(properties.Schema.STRING)
        }

        class DummyStack(dict):
            @property
            def parameters(self):
                return mock.Mock()

        param = hot_funcs.GetParam(DummyStack(), 'get_param', 'source_param')

        param.parameters = {}

        data = {'source': param, 'destination': ''}
        props = properties.Properties(schema, data, resolver=function.resolve)

        rule = translation.TranslationRule(props,
                                           translation.TranslationRule.REPLACE,
                                           ['destination'],
                                           value_path=['source'])

        rule.execute_rule()

        # ensure that translation rule was not applied
        self.assertEqual({'source': param, 'destination': ''}, data)
コード例 #2
0
    def test_property_commadelimitedlist_param_correct_translation(self):
        """Test when property with sub-schema takes comma_delimited_list."""
        schema = {
            'far':
            properties.Schema(properties.Schema.LIST,
                              schema=properties.Schema(
                                  properties.Schema.STRING, )),
            'boo':
            properties.Schema(properties.Schema.STRING)
        }

        class DummyStack(dict):
            @property
            def parameters(self):
                return mock.Mock()

        param = hot_funcs.GetParam(DummyStack(list_far='list_far'),
                                   'get_param', 'list_far')
        param.parameters = {
            'list_far':
            parameters.CommaDelimitedListParam('list_far', {
                'Type': 'CommaDelimitedList'
            }, "white,roses").value()
        }
        data = {'far': param, 'boo': 'chrysanthemums'}

        props = properties.Properties(schema, data)

        rule = translation.TranslationRule(props,
                                           translation.TranslationRule.ADD,
                                           ['far'], [props.get('boo')])
        rule.execute_rule()

        self.assertEqual(['white', 'roses', 'chrysanthemums'],
                         props.get('far'))
コード例 #3
0
 def test_validate_depr_properties_required_with_refs(self):
     funct = functions.GetParam(mock.Mock(),
                                'get_param', 'private_subnet_id')
     data = {'network_id': funct}
     p = properties.Properties(subnet.Subnet.properties_schema, data,
                               resolver=lambda d: None)
     # no assert, as we are looking for no exception.
     nr.NeutronResource._validate_depr_property_required(
         p, 'network', 'network_id')
コード例 #4
0
    def test_property_json_param_to_list_correct_translation(self):
        """Test case when list property with sub-schema takes json param."""
        schema = {
            'far': properties.Schema(properties.Schema.LIST,
                                     schema=properties.Schema(
                                         properties.Schema.MAP,
                                         schema={
                                             'bar': properties.Schema(
                                                 properties.Schema.STRING,
                                             ),
                                             'dar': properties.Schema(
                                                 properties.Schema.STRING
                                             )
                                         }
                                     ))
        }

        class DummyStack(dict):
            @property
            def parameters(self):
                return mock.Mock()

        param = hot_funcs.GetParam(DummyStack(json_far='json_far'),
                                   'get_param',
                                   'json_far')
        param.parameters = {
            'json_far': parameters.JsonParam(
                'json_far',
                {'Type': 'Json'},
                '{"dar": "rad"}').value()}
        data = {'far': [param]}

        props = properties.Properties(schema, data, resolver=function.resolve)

        rule = translation.TranslationRule(
            props,
            translation.TranslationRule.REPLACE,
            ['far', 'bar'],
            value_name='dar')

        tran = translation.Translation(props)
        tran.set_rules([rule])
        self.assertTrue(tran.has_translation('far.0.bar'))
        prop_data = props['far']
        result = tran.translate('far.0.bar', prop_data[0]['bar'],
                                prop_data[0])
        self.assertEqual('rad', result)
        self.assertEqual('rad', tran.resolved_translations['far.0.bar'])
コード例 #5
0
    def test_property_json_param_to_list_correct_translation(self):
        """Test case when list property with sub-schema takes json param."""
        schema = {
            'far': properties.Schema(properties.Schema.LIST,
                                     schema=properties.Schema(
                                         properties.Schema.MAP,
                                         schema={
                                             'bar': properties.Schema(
                                                 properties.Schema.STRING,
                                             ),
                                             'dar': properties.Schema(
                                                 properties.Schema.STRING
                                             )
                                         }
                                     ))
        }

        class DummyStack(dict):
            @property
            def parameters(self):
                return mock.Mock()

        param = hot_funcs.GetParam(DummyStack(json_far='json_far'),
                                   'get_param',
                                   'json_far')
        param.parameters = {
            'json_far': parameters.JsonParam(
                'json_far',
                {'Type': 'Json'},
                '{"dar": "rad"}').value()}
        data = {'far': [param]}

        props = properties.Properties(schema, data)

        rule = translation.TranslationRule(
            props,
            translation.TranslationRule.REPLACE,
            ['far', 'bar'],
            value_name='dar')

        rule.execute_rule()

        self.assertEqual([{'dar': None, 'bar': 'rad'}], props.get('far'))
コード例 #6
0
ファイル: test_rsrc_defn.py プロジェクト: srz01/heat
        def get_param_defn(value):
            stack = FakeStack({'Foo': value})
            param_func = hot_funcs.GetParam(stack, 'get_param', 'Foo')

            return rsrc_defn.ResourceDefinition('rsrc', 'SomeType',
                                                {'Foo': param_func})