'Ensure the environment parameter_defaults are preserved.
Use a template with existing flag and ensure the environment
parameter_defaults are preserved.'

def test_stack_update_existing_parameter_defaults(self):

    stack_name = 'service_update_test_stack_existing_param_defaults'
    intial_params = {'encrypted_param_names': [], 'parameter_defaults': {'mydefault': 123}, 'parameters': {}, 'resource_registry': {}}
    update_params = {'encrypted_param_names': [], 'parameter_defaults': {'default2': 456}, 'parameters': {}, 'resource_registry': {}}
    api_args = {rpc_api.PARAM_TIMEOUT: 60, rpc_api.PARAM_EXISTING: True}
    t = template_format.parse(tools.wp_template)
    stk = utils.parse_stack(t, stack_name=stack_name, params=intial_params)
    stk.set_stack_user_project_id('1234')
    expected_env = {'encrypted_param_names': [], 'parameter_defaults': {'mydefault': 123, 'default2': 456}, 'parameters': {}, 'event_sinks': [], 'resource_registry': {'resources': {}}}
    with mock.patch('heat.engine.stack.Stack') as mock_stack:
        stk.update = mock.Mock()
        mock_stack.load.return_value = stk
        mock_stack.validate.return_value = None
        result = self.man.update_stack(self.ctx, stk.identifier(), t, update_params, None, api_args)
        tmpl = mock_stack.call_args[0][2]
        self.assertEqual(expected_env, tmpl.env.env_as_dict())
        self.assertEqual(stk.identifier(), result)
