# Path: heatclient/common/event_utils.py
# def get_hook_events(hc, stack_id, event_args, nested_depth=0,
#                     hook_type='pre-create'):
# def get_events(hc, stack_id, event_args, nested_depth=0,
#                marker=None, limit=None):
# def _get_nested_ids(hc, stack_id):
# def _get_nested_events(hc, nested_depth, stack_id, event_args):
# def _get_stack_name_from_links(event):
# def _get_stack_events(hc, stack_id, event_args):
# def poll_for_events(hc, stack_name, action=None, poll_period=5, marker=None,
#                     out=None, nested_depth=0):
#     def is_stack_event(event):
# def wait_for_events(ws, stack_name, out=None):
# 
# Path: heatclient/v1/events.py
# DEFAULT_PAGE_SIZE = 20
# class Event(base.Resource):
# class EventManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def list(self, stack_id, resource_name=None, **kwargs):
#     def get(self, stack_id, resource_name, event_id):
# 
# Path: heatclient/v1/resources.py
# DEFAULT_PAGE_SIZE = 20
# class Resource(base.Resource):
# class ResourceManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def stack_name(self):
#     def list(self, stack_id, **kwargs):
#     def get(self, stack_id, resource_name, with_attr=None):
#     def metadata(self, stack_id, resource_name):
#     def signal(self, stack_id, resource_name, data=None):
#     def mark_unhealthy(self, stack_id, resource_name,
#                        mark_unhealthy, resource_status_reason):
#     def generate_template(self, resource_name):


from unittest import mock
from heatclient.common import event_utils
from heatclient.v1 import events as hc_ev
from heatclient.v1 import resources as hc_res
import testtools
    @mock.patch('heatclient.common.event_utils.get_events')
    def test_poll_for_events_stack_get(self, ge):
        mock_client = mock.MagicMock()
        mock_client.stacks.get.return_value.stack_status = 'CREATE_FAILED'

        ge.side_effect = [[
            self._mock_stack_event('1', 'astack', 'CREATE_IN_PROGRESS'),
            self._mock_event('2', 'res_child1', 'CREATE_IN_PROGRESS'),
            self._mock_event('3', 'res_child2', 'CREATE_IN_PROGRESS'),
            self._mock_event('4', 'res_child3', 'CREATE_IN_PROGRESS')
        ], [], []]

        stack_status, msg = event_utils.poll_for_events(
            mock_client, 'astack', action='CREATE', poll_period=0)
        self.assertEqual('CREATE_FAILED', stack_status)
        self.assertEqual('\n Stack astack CREATE_FAILED \n', msg)

    def test_wait_for_events(self):
        ws = FakeWebSocket([
            {'body': {
                'timestamp': '2014-01-06T16:14:26Z',
                'payload': {'resource_action': 'CREATE',
                            'resource_status': 'COMPLETE',
                            'resource_name': 'mystack',
                            'physical_resource_id': 'stackid1',
                            'stack_id': 'stackid1'}}}])
        stack_status, msg = event_utils.wait_for_events(ws, 'mystack')
        self.assertEqual('CREATE_COMPLETE', stack_status)
        self.assertEqual('\n Stack mystack CREATE_COMPLETE \n', msg)


# Path: heatclient/common/event_utils.py
# def get_hook_events(hc, stack_id, event_args, nested_depth=0,
#                     hook_type='pre-create'):
# def get_events(hc, stack_id, event_args, nested_depth=0,
#                marker=None, limit=None):
# def _get_nested_ids(hc, stack_id):
# def _get_nested_events(hc, nested_depth, stack_id, event_args):
# def _get_stack_name_from_links(event):
# def _get_stack_events(hc, stack_id, event_args):
# def poll_for_events(hc, stack_name, action=None, poll_period=5, marker=None,
#                     out=None, nested_depth=0):
#     def is_stack_event(event):
# def wait_for_events(ws, stack_name, out=None):
# 
# Path: heatclient/v1/events.py
# DEFAULT_PAGE_SIZE = 20
# class Event(base.Resource):
# class EventManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def list(self, stack_id, resource_name=None, **kwargs):
#     def get(self, stack_id, resource_name, event_id):
# 
# Path: heatclient/v1/resources.py
# DEFAULT_PAGE_SIZE = 20
# class Resource(base.Resource):
# class ResourceManager(stacks.StackChildManager):
#     def __repr__(self):
#     def update(self, **fields):
#     def delete(self):
#     def data(self, **kwargs):
#     def stack_name(self):
#     def list(self, stack_id, **kwargs):
#     def get(self, stack_id, resource_name, with_attr=None):
#     def metadata(self, stack_id, resource_name):
#     def signal(self, stack_id, resource_name, data=None):
#     def mark_unhealthy(self, stack_id, resource_name,
#                        mark_unhealthy, resource_status_reason):
#     def generate_template(self, resource_name):


# Path: heatclient/tests/unit/test_event_utils.py
from unittest import mock
from heatclient.common import event_utils
from heatclient.v1 import events as hc_ev
from heatclient.v1 import resources as hc_res
import testtools

    @mock.patch('heatclient.common.event_utils.get_events')
    def test_poll_for_events_stack_get(self, ge):
        mock_client = mock.MagicMock()
        mock_client.stacks.get.return_value.stack_status = 'CREATE_FAILED'

        ge.side_effect = [[
            self._mock_stack_event('1', 'astack', 'CREATE_IN_PROGRESS'),
            self._mock_event('2', 'res_child1', 'CREATE_IN_PROGRESS'),
            self._mock_event('3', 'res_child2', 'CREATE_IN_PROGRESS'),
            self._mock_event('4', 'res_child3', 'CREATE_IN_PROGRESS')
        ], [], []]

        stack_status, msg = event_utils.poll_for_events(
            mock_client, 'astack', action='CREATE', poll_period=0)
        self.assertEqual('CREATE_FAILED', stack_status)
        self.assertEqual('\n Stack astack CREATE_FAILED \n', msg)

    def test_wait_for_events(self):
        ws = FakeWebSocket([
            {'body': {
                'timestamp': '2014-01-06T16:14:26Z',
                'payload': {'resource_action': 'CREATE',
                            'resource_status': 'COMPLETE',
                            'resource_name': 'mystack',
                            'physical_resource_id': 'stackid1',
                            'stack_id': 'stackid1'}}}])
        stack_status, msg = event_utils.wait_for_events(ws, 'mystack')
        self.assertEqual('CREATE_COMPLETE', stack_status)
        self.assertEqual('\n Stack mystack CREATE_COMPLETE \n', msg)


    def test_wait_for_events_failed(self):