Coverage for manila/tests/image/test_image.py: 95%
38 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
16from unittest import mock
18from manila import context
19from manila.image import glance
20from manila import test
21from manila.tests import utils as test_utils
24class FakeImageClient:
26 class Image:
28 def images(self, *args, **kwargs):
29 return [{'id': 'id1'}, {'id': 'id2'}]
31 def __getattr__(self, item):
32 return None
34 def __init__(self):
35 self.image = self.Image()
38class OpenStackClientTestCase(test.TestCase):
40 @mock.patch('manila.image.glance.openstack.connection.Connection')
41 @mock.patch('manila.image.glance.ks_loading.load_session_from_conf_options') # noqa
42 def test_auth(self, mock_load_session, mock_connection):
43 mock_load_session.return_value = 'fake_session'
44 fake_context = 'fake_context'
45 data = {
46 'glance': {
47 'api_microversion': 'foo_api_microversion',
48 'endpoint_type': 'internal',
49 'region_name': 'foo_region_name'
50 }
51 }
53 with test_utils.create_temp_config_with_opts(data):
54 glance.openstackclient(fake_context)
56 mock_connection.assert_called_once_with(
57 session='fake_session',
58 context=fake_context,
59 image_version=data['glance']['api_microversion'],
60 image_interface=data['glance']['endpoint_type'],
61 region_name=data['glance']['region_name'],
62 )
65class ImageApiTestCase(test.TestCase):
66 def setUp(self):
67 super().setUp()
69 self.api = glance.API()
70 self.imageclient = FakeImageClient()
71 self.ctx = context.get_admin_context()
72 self.mock_object(glance, 'openstackclient',
73 mock.Mock(return_value=self.imageclient))
75 def test_image_list(self):
76 image_list = ['fake', 'image', 'list']
78 class FakeImageClient(object):
79 def images(self):
80 return image_list
82 self.imageclient.image = FakeImageClient()
84 result = self.api.image_list(self.ctx)
86 self.assertEqual(image_list, result)