@mock.patch.object(resource_objects.Resource, 'get_all_by_stack')
def test_resource_get_db_fallback(self, gabs):
    tpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'test_stack', template.Template(tpl), status_reason='blarg')
    self.stack.store()
    tpl2 = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}}}
    t2 = template.Template(tpl2)
    t2.store(self.ctx)
    db_resources = {'A': mock.MagicMock(), 'B': mock.MagicMock(current_template_id=t2.id), 'C': mock.MagicMock(current_template_id=t2.id)}
    db_resources['A'].name = 'A'
    db_resources['B'].name = 'B'
    db_resources['C'].name = 'C'
    gabs.return_value = db_resources
    self.assertEqual('A', self.stack.resource_get('A').name)
    self.assertEqual('B', self.stack.resource_get('B').name)
    self.assertIsNone(self.stack.resource_get('C'))
    self.assertIsNone(self.stack.resource_get('D'))
@mock.patch.object(resource_objects.Resource, 'get_all_by_stack')
def test_resource_get_db_fallback(self, gabs):
    tpl = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'GenericResourceType'}}}
    self.stack = stack.Stack(self.ctx, 'test_stack', template.Template(tpl), status_reason='blarg')
    self.stack.store()
    tpl2 = {'HeatTemplateFormatVersion': '2012-12-12', 'Resources': {'A': {'Type': 'GenericResourceType'}, 'B': {'Type': 'GenericResourceType'}}}
    t2 = template.Template(tpl2)
    t2.store(self.ctx)
    db_resources = {'A': mock.MagicMock(), 'B': mock.MagicMock(current_template_id=t2.id), 'C': mock.MagicMock(current_template_id=t2.id)}
    db_resources['A'].name = 'A'
    db_resources['B'].name = 'B'
    db_resources['C'].name = 'C'
    gabs.return_value = db_resources
    self.assertEqual('A', self.stack.resource_get('A').name)
    self.assertEqual('B', self.stack.resource_get('B').name)
    self.assertIsNone(self.stack.resource_get('C'))
    self.assertIsNone(self.stack.resource_get('D'))