Skip to content

Commit dd5a21f

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Use consistent shortcut to fake volume client"
2 parents b884e83 + 4cabf6f commit dd5a21f

41 files changed

Lines changed: 305 additions & 523 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openstackclient/tests/unit/common/test_availability_zone.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def setUp(self):
8787
self.compute_client.availability_zones = mock.Mock()
8888

8989
self.app.client_manager.sdk_connection.volume = mock.Mock()
90-
self.volume_client = self.app.client_manager.sdk_connection.volume
91-
self.volume_client.availability_zones = mock.Mock()
90+
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume
91+
self.volume_sdk_client.availability_zones = mock.Mock()
9292

9393

9494
class TestAvailabilityZoneList(TestAvailabilityZone):
@@ -110,7 +110,9 @@ def setUp(self):
110110
super().setUp()
111111

112112
self.compute_client.availability_zones.return_value = self.compute_azs
113-
self.volume_client.availability_zones.return_value = self.volume_azs
113+
self.volume_sdk_client.availability_zones.return_value = (
114+
self.volume_azs
115+
)
114116
self.network_client.availability_zones.return_value = self.network_azs
115117

116118
# Get the command object to test
@@ -127,7 +129,7 @@ def test_availability_zone_list_no_options(self):
127129
columns, data = self.cmd.take_action(parsed_args)
128130

129131
self.compute_client.availability_zones.assert_called_with(details=True)
130-
self.volume_client.availability_zones.assert_called_with()
132+
self.volume_sdk_client.availability_zones.assert_called_with()
131133
self.network_client.availability_zones.assert_called_with()
132134

133135
self.assertEqual(self.short_columnslist, columns)
@@ -155,7 +157,7 @@ def test_availability_zone_list_long(self):
155157
columns, data = self.cmd.take_action(parsed_args)
156158

157159
self.compute_client.availability_zones.assert_called_with(details=True)
158-
self.volume_client.availability_zones.assert_called_with()
160+
self.volume_sdk_client.availability_zones.assert_called_with()
159161
self.network_client.availability_zones.assert_called_with()
160162

161163
self.assertEqual(self.long_columnslist, columns)
@@ -189,7 +191,7 @@ def test_availability_zone_list_compute(self):
189191
columns, data = self.cmd.take_action(parsed_args)
190192

191193
self.compute_client.availability_zones.assert_called_with(details=True)
192-
self.volume_client.availability_zones.assert_not_called()
194+
self.volume_sdk_client.availability_zones.assert_not_called()
193195
self.network_client.availability_zones.assert_not_called()
194196

195197
self.assertEqual(self.short_columnslist, columns)
@@ -213,7 +215,7 @@ def test_availability_zone_list_volume(self):
213215
columns, data = self.cmd.take_action(parsed_args)
214216

215217
self.compute_client.availability_zones.assert_not_called()
216-
self.volume_client.availability_zones.assert_called_with()
218+
self.volume_sdk_client.availability_zones.assert_called_with()
217219
self.network_client.availability_zones.assert_not_called()
218220

219221
self.assertEqual(self.short_columnslist, columns)
@@ -237,7 +239,7 @@ def test_availability_zone_list_network(self):
237239
columns, data = self.cmd.take_action(parsed_args)
238240

239241
self.compute_client.availability_zones.assert_not_called()
240-
self.volume_client.availability_zones.assert_not_called()
242+
self.volume_sdk_client.availability_zones.assert_not_called()
241243
self.network_client.availability_zones.assert_called_with()
242244

243245
self.assertEqual(self.short_columnslist, columns)

openstackclient/tests/unit/common/test_limits.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,9 @@ class TestVolumeLimits(volume_fakes.TestVolume):
7474
def setUp(self):
7575
super().setUp()
7676
self.app.client_manager.compute_endpoint_enabled = False
77-
self.volume = self.app.client_manager.volume
7877

7978
self.fake_limits = volume_fakes.FakeLimits()
80-
self.volume.limits.get.return_value = self.fake_limits
79+
self.volume_client.limits.get.return_value = self.fake_limits
8180

8281
def test_volume_show_absolute(self):
8382
arglist = ['--absolute']

openstackclient/tests/unit/common/test_quota.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,9 @@ def setUp(self):
5555
)
5656
self.compute_quotas_class_mock.reset_mock()
5757

58-
self.volume_quotas_mock = self.app.client_manager.volume.quotas
58+
self.volume_quotas_mock = self.volume_client.quotas
5959
self.volume_quotas_mock.reset_mock()
60-
self.volume_quotas_class_mock = (
61-
self.app.client_manager.volume.quota_classes
62-
)
60+
self.volume_quotas_class_mock = self.volume_client.quota_classes
6361
self.volume_quotas_class_mock.reset_mock()
6462

6563
self.app.client_manager.auth_ref = mock.Mock()
@@ -180,8 +178,7 @@ def setUp(self):
180178
volume_fakes.create_one_default_vol_quota(),
181179
volume_fakes.create_one_default_vol_quota(),
182180
]
183-
self.volume = self.app.client_manager.volume
184-
self.volume.quotas.defaults = mock.Mock(
181+
self.volume_client.quotas.defaults = mock.Mock(
185182
side_effect=self.volume_default_quotas,
186183
)
187184

@@ -288,7 +285,7 @@ def test_quota_list_details_volume(self):
288285
detailed_quota
289286
)
290287

291-
self.volume.quotas.get = mock.Mock(return_value=detailed_quota)
288+
self.volume_client.quotas.get = mock.Mock(return_value=detailed_quota)
292289

293290
arglist = [
294291
'--detail',
@@ -541,7 +538,7 @@ def test_quota_list_network_by_project(self):
541538

542539
def test_quota_list_volume(self):
543540
# Two projects with non-default quotas
544-
self.volume.quotas.get = mock.Mock(
541+
self.volume_client.quotas.get = mock.Mock(
545542
side_effect=self.volume_quotas,
546543
)
547544

@@ -562,7 +559,7 @@ def test_quota_list_volume(self):
562559

563560
def test_quota_list_volume_default(self):
564561
# Two projects with non-default quotas
565-
self.volume.quotas.get = mock.Mock(
562+
self.volume_client.quotas.get = mock.Mock(
566563
side_effect=[
567564
self.volume_quotas[0],
568565
volume_fakes.create_one_default_vol_quota(),
@@ -586,7 +583,7 @@ def test_quota_list_volume_default(self):
586583

587584
def test_quota_list_volume_no_project(self):
588585
# Two projects with non-default quotas
589-
self.volume.quotas.get = mock.Mock(
586+
self.volume_client.quotas.get = mock.Mock(
590587
side_effect=[
591588
self.volume_quotas[0],
592589
volume_fakes.create_one_default_vol_quota(),
@@ -610,7 +607,7 @@ def test_quota_list_volume_no_project(self):
610607

611608
def test_quota_list_volume_by_project(self):
612609
# Two projects with non-default quotas
613-
self.volume.quotas.get = mock.Mock(
610+
self.volume_client.quotas.get = mock.Mock(
614611
side_effect=self.volume_quotas,
615612
)
616613

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ def setUp(self):
175175
endpoint=fakes.AUTH_URL,
176176
token=fakes.AUTH_TOKEN,
177177
)
178+
self.volume_client = self.app.client_manager.volume
178179

179180

180181
def create_one_aggregate(attrs=None):

openstackclient/tests/unit/compute/v2/test_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ def setUp(self):
9292
self.flavors_mock.reset_mock()
9393

9494
# Get a shortcut to the volume client VolumeManager Mock
95-
self.volumes_mock = self.app.client_manager.volume.volumes
95+
self.volumes_mock = self.volume_client.volumes
9696
self.volumes_mock.reset_mock()
9797

9898
self.app.client_manager.sdk_connection.volume = mock.Mock()
99-
self.sdk_volume_client = self.app.client_manager.sdk_connection.volume
99+
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume
100100

101101
# Get a shortcut to the volume client VolumeManager Mock
102-
self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
102+
self.snapshots_mock = self.volume_client.volume_snapshots
103103
self.snapshots_mock.reset_mock()
104104

105105
# Set object attributes to be tested. Could be overwritten in subclass.
@@ -162,7 +162,7 @@ def setup_sdk_volumes_mock(self, count):
162162
volumes = volume_fakes.create_sdk_volumes(count=count)
163163

164164
# This is the return value for volume_client.find_volume()
165-
self.sdk_volume_client.find_volume.side_effect = volumes
165+
self.volume_sdk_client.find_volume.side_effect = volumes
166166

167167
return volumes
168168

openstackclient/tests/unit/compute/v2/test_server_volume.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def setUp(self):
2929
self.app.client_manager.sdk_connection.compute = mock.Mock()
3030
self.app.client_manager.sdk_connection.volume = mock.Mock()
3131
self.compute_client = self.app.client_manager.sdk_connection.compute
32-
self.volume_client = self.app.client_manager.sdk_connection.volume
32+
self.volume_sdk_client = self.app.client_manager.sdk_connection.volume
3333

3434

3535
class TestServerVolumeList(TestServerVolume):
@@ -243,7 +243,7 @@ def setUp(self):
243243
self.compute_client.find_server.return_value = self.server
244244

245245
self.volume = volume_fakes.create_one_sdk_volume()
246-
self.volume_client.find_volume.return_value = self.volume
246+
self.volume_sdk_client.find_volume.return_value = self.volume
247247

248248
# Get the command object to test
249249
self.cmd = server_volume.UpdateServerVolume(self.app, None)

openstackclient/tests/unit/image/v1/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def setUp(self):
3939
endpoint=fakes.AUTH_URL,
4040
token=fakes.AUTH_TOKEN,
4141
)
42+
self.volume_client = self.app.client_manager.volume
4243

4344

4445
def create_one_image(attrs=None):

openstackclient/tests/unit/image/v1/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def test_image_set_properties(self):
593593

594594
def test_image_update_volume(self):
595595
# Set up VolumeManager Mock
596-
volumes_mock = self.app.client_manager.volume.volumes
596+
volumes_mock = self.volume_client.volumes
597597
volumes_mock.reset_mock()
598598
volumes_mock.get.return_value = fakes.FakeResource(
599599
None,

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def setUp(self):
3737
self.project_mock.reset_mock()
3838
self.domain_mock = self.app.client_manager.identity.domains
3939
self.domain_mock.reset_mock()
40-
self.volumes_mock = self.app.client_manager.volume.volumes
40+
self.volumes_mock = self.volume_client.volumes
4141
fake_body = {
4242
'os-volume_upload_image': {'volume_type': {'name': 'fake_type'}}
4343
}
@@ -369,9 +369,7 @@ class FakeVolume:
369369
@mock.patch('osc_lib.utils.find_resource')
370370
@mock.patch('openstackclient.image.v2.image.get_data_from_stdin')
371371
def test_image_create_from_volume_v31(self, mock_get_data_f, mock_get_vol):
372-
self.app.client_manager.volume.api_version = api_versions.APIVersion(
373-
'3.1'
374-
)
372+
self.volume_client.api_version = api_versions.APIVersion('3.1')
375373

376374
fake_vol_id = 'fake-volume-id'
377375
mock_get_data_f.return_value = None

openstackclient/tests/unit/volume/v1/fakes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def setUp(self):
6161
endpoint=fakes.AUTH_URL,
6262
token=fakes.AUTH_TOKEN,
6363
)
64+
self.volume_client = self.app.client_manager.volume
6465

6566
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client(
6667
endpoint=fakes.AUTH_URL,

0 commit comments

Comments
 (0)