'Tests property conversion to parameter values.'

def test_to_parameters(self):

    provider = {'HeatTemplateFormatVersion': '2012-12-12', 'Parameters': {'Foo': {'Type': 'String'}, 'AList': {'Type': 'CommaDelimitedList'}, 'MemList': {'Type': 'CommaDelimitedList'}, 'ListEmpty': {'Type': 'CommaDelimitedList'}, 'ANum': {'Type': 'Number'}, 'AMap': {'Type': 'Json'}}, 'Outputs': {'Foo': {'Value': 'bar'}}}
    files = {'test_resource.template': json.dumps(provider)}
    class DummyResource(generic_rsrc.GenericResource, ):
        attributes_schema = {'Foo': attributes.Schema('A    test    attribute')}
        properties_schema = {'Foo': {'Type': 'String'}, 'AList': {'Type': 'List'}, 'MemList': {'Type': 'List'}, 'ListEmpty': {'Type': 'List'}, 'ANum': {'Type': 'Number'}, 'AMap': {'Type': 'Map'}}
    env = environment.Environment()
    resource._register_class('DummyResource', DummyResource)
    env.load({'resource_registry': {'DummyResource': 'test_resource.template'}})
    stack = parser.Stack(utils.dummy_context(), 'test_stack', template.Template(empty_template, files=files, env=env), stack_id=str(uuid.uuid4()))
    map_prop_val = {'key1': 'val1', 'key2': ['lval1', 'lval2', 'lval3'], 'key3': {'key4': 4, 'key5': False}}
    prop_vals = {'Foo': 'Bar', 'AList': ['one', 'two', 'three'], 'MemList': [collections.OrderedDict([('key', 'name'), ('value', 'three')]), collections.OrderedDict([('key', 'name'), ('value', 'four')])], 'ListEmpty': [], 'ANum': 5, 'AMap': map_prop_val}
    definition = rsrc_defn.ResourceDefinition('test_t_res', 'DummyResource', prop_vals)
    temp_res = template_resource.TemplateResource('test_t_res', definition, stack)
    temp_res.validate()
    converted_params = temp_res.child_params()
    self.assertTrue(converted_params)
    for key in DummyResource.properties_schema:
        self.assertIn(key, converted_params)
    self.assertEqual('Bar', converted_params.get('Foo'))
    self.assertEqual('one,two,three', converted_params.get('AList'))
    mem_exp = '.member.0.key=name,.member.0.value=three,.member.1.key=name,.member.1.value=four'
    self.assertEqual(sorted(mem_exp.split(',')), sorted(converted_params.get('MemList').split(',')))
    self.assertEqual(5, converted_params.get('ANum'))
    self.assertEqual(map_prop_val, converted_params.get('AMap'))
    with mock.patch.object(properties.Properties, 'get_user_value') as m_get:
        m_get.side_effect = ValueError('boom')
        temp_res.action = temp_res.INIT
        converted_params = temp_res.child_params()
        for key in DummyResource.properties_schema:
            self.assertIn(key, converted_params)
        self.assertEqual({}, converted_params['AMap'])
        self.assertEqual(0, converted_params['ANum'])
        temp_res.action = temp_res.CREATE
        self.assertRaises(ValueError, temp_res.child_params)
