@mock.patch.object(resource_objects.Resource, 'get_all_by_stack')
def test_iter_resources_with_nested(self, mock_db_call):
    tpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'StackResourceType'}, 'B': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'test_stack', template.Template(tpl), status_reason='blarg')
    self.stack.store()
    mock_rsc_a = mock.MagicMock(current_template_id=self.stack.t.id)
    mock_rsc_a.name = 'A'
    mock_rsc_b = mock.MagicMock(current_template_id=self.stack.t.id)
    mock_rsc_b.name = 'B'
    mock_db_call.return_value = {'A': mock_rsc_a, 'B': mock_rsc_b}

    def get_more(nested_depth=0, filters=None):
        (yield 'X')
        (yield 'Y')
        (yield 'Z')
    mock_nested = self.patchobject(generic_rsrc.StackResourceType, 'nested')
    mock_nested.return_value.iter_resources = mock.MagicMock(side_effect=get_more)
    resource_generator = self.stack.iter_resources()
    self.assertIsNot(resource_generator, list)
    first_level_resources = list(resource_generator)
    self.assertEqual(2, len(first_level_resources))
    all_resources = list(self.stack.iter_resources(1))
    self.assertEqual(5, len(all_resources))
@mock.patch.object(resource_objects.Resource, 'get_all_by_stack')
def test_iter_resources_with_nested(self, mock_db_call):
    tpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'StackResourceType'}, 'B': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'test_stack', template.Template(tpl), status_reason='blarg')
    self.stack.store()
    mock_rsc_a = mock.MagicMock(current_template_id=self.stack.t.id)
    mock_rsc_a.name = 'A'
    mock_rsc_b = mock.MagicMock(current_template_id=self.stack.t.id)
    mock_rsc_b.name = 'B'
    mock_db_call.return_value = {'A': mock_rsc_a, 'B': mock_rsc_b}

    def get_more(nested_depth=0, filters=None):
        (yield 'X')
        (yield 'Y')
        (yield 'Z')
    mock_nested = self.patchobject(generic_rsrc.StackResourceType, 'nested')
    mock_nested.return_value.iter_resources = mock.MagicMock(side_effect=get_more)
    resource_generator = self.stack.iter_resources()
    self.assertIsNot(resource_generator, list)
    first_level_resources = list(resource_generator)
    self.assertEqual(2, len(first_level_resources))
    all_resources = list(self.stack.iter_resources(1))
    self.assertEqual(5, len(all_resources))