deb-heat/heat/tests/test_image.py
Steve Baker 956632844a Move glance_utils functions to glance client plugin
The glance client plugin is a more obvious home for this sort
of function, and this change makes mocking of these functions
much easier since a mocked client is no longer needed.

To access the methods defined in the client plugin the method
Resource.client_plugin has been added. When all clients are
contributed by plugins then method Resource.client will call
Resource.client_plugin.

glance_utils can be deleted since it was only added at the
beginning of the Juno cycle.

The image constraint has also been moved to the glance plugin.

Change-Id: Id31ccd605411ca034addc67d8aadf7cea0904bfd
2014-07-21 13:00:26 -04:00

39 lines
1.4 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from heat.common import exception
from heat.engine.clients.os import glance
from heat.tests.common import HeatTestCase
from heat.tests import utils
class ImageConstraintTest(HeatTestCase):
def setUp(self):
super(ImageConstraintTest, self).setUp()
self.ctx = utils.dummy_context()
self.mock_get_image = mock.Mock()
self.ctx.clients.client_plugin(
'glance').get_image_id = self.mock_get_image
self.constraint = glance.ImageConstraint()
def test_validation(self):
self.mock_get_image.return_value = "id1"
self.assertTrue(self.constraint.validate("foo", self.ctx))
def test_validation_error(self):
self.mock_get_image.side_effect = exception.ImageNotFound(
image_name='bar')
self.assertFalse(self.constraint.validate("bar", self.ctx))