Skip to content

Commit f576cb6

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Use consistent shortcut to fake compute client"
2 parents 14a4f89 + 187a454 commit f576cb6

31 files changed

Lines changed: 772 additions & 762 deletions

openstackclient/compute/v2/server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,8 +1575,8 @@ def _match_image(image_api, wanted_properties):
15751575
if parsed_args.description:
15761576
if compute_client.api_version < api_versions.APIVersion("2.19"):
15771577
msg = _(
1578-
"Description is not supported for "
1579-
"--os-compute-api-version less than 2.19"
1578+
'--os-compute-api-version 2.19 or greater is '
1579+
'required to support the --description option'
15801580
)
15811581
raise exceptions.CommandError(msg)
15821582

@@ -4964,8 +4964,8 @@ def take_action(self, parsed_args):
49644964
if parsed_args.description:
49654965
if compute_client.api_version < api_versions.APIVersion("2.19"):
49664966
msg = _(
4967-
"Description is not supported for "
4968-
"--os-compute-api-version less than 2.19"
4967+
'--os-compute-api-version 2.19 or greater is '
4968+
'required to support the --description option'
49694969
)
49704970
raise exceptions.CommandError(msg)
49714971
compute_client.servers.update(

openstackclient/tests/unit/common/test_availability_zone.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ def setUp(self):
8787
super().setUp()
8888

8989
self.app.client_manager.sdk_connection.compute = mock.Mock()
90-
self.compute_client = self.app.client_manager.sdk_connection.compute
91-
self.compute_client.availability_zones = mock.Mock()
90+
self.compute_sdk_client = (
91+
self.app.client_manager.sdk_connection.compute
92+
)
93+
self.compute_sdk_client.availability_zones = mock.Mock()
9294

9395

9496
class TestAvailabilityZoneList(TestAvailabilityZone):
@@ -109,7 +111,9 @@ class TestAvailabilityZoneList(TestAvailabilityZone):
109111
def setUp(self):
110112
super().setUp()
111113

112-
self.compute_client.availability_zones.return_value = self.compute_azs
114+
self.compute_sdk_client.availability_zones.return_value = (
115+
self.compute_azs
116+
)
113117
self.volume_sdk_client.availability_zones.return_value = (
114118
self.volume_azs
115119
)
@@ -128,7 +132,9 @@ def test_availability_zone_list_no_options(self):
128132
# containing the data to be listed.
129133
columns, data = self.cmd.take_action(parsed_args)
130134

131-
self.compute_client.availability_zones.assert_called_with(details=True)
135+
self.compute_sdk_client.availability_zones.assert_called_with(
136+
details=True
137+
)
132138
self.volume_sdk_client.availability_zones.assert_called_with()
133139
self.network_client.availability_zones.assert_called_with()
134140

@@ -156,7 +162,9 @@ def test_availability_zone_list_long(self):
156162
# containing the data to be listed.
157163
columns, data = self.cmd.take_action(parsed_args)
158164

159-
self.compute_client.availability_zones.assert_called_with(details=True)
165+
self.compute_sdk_client.availability_zones.assert_called_with(
166+
details=True
167+
)
160168
self.volume_sdk_client.availability_zones.assert_called_with()
161169
self.network_client.availability_zones.assert_called_with()
162170

@@ -190,7 +198,9 @@ def test_availability_zone_list_compute(self):
190198
# containing the data to be listed.
191199
columns, data = self.cmd.take_action(parsed_args)
192200

193-
self.compute_client.availability_zones.assert_called_with(details=True)
201+
self.compute_sdk_client.availability_zones.assert_called_with(
202+
details=True
203+
)
194204
self.volume_sdk_client.availability_zones.assert_not_called()
195205
self.network_client.availability_zones.assert_not_called()
196206

@@ -214,7 +224,7 @@ def test_availability_zone_list_volume(self):
214224
# containing the data to be listed.
215225
columns, data = self.cmd.take_action(parsed_args)
216226

217-
self.compute_client.availability_zones.assert_not_called()
227+
self.compute_sdk_client.availability_zones.assert_not_called()
218228
self.volume_sdk_client.availability_zones.assert_called_with()
219229
self.network_client.availability_zones.assert_not_called()
220230

@@ -238,7 +248,7 @@ def test_availability_zone_list_network(self):
238248
# containing the data to be listed.
239249
columns, data = self.cmd.take_action(parsed_args)
240250

241-
self.compute_client.availability_zones.assert_not_called()
251+
self.compute_sdk_client.availability_zones.assert_not_called()
242252
self.volume_sdk_client.availability_zones.assert_not_called()
243253
self.network_client.availability_zones.assert_called_with()
244254

openstackclient/tests/unit/common/test_limits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class TestComputeLimits(compute_fakes.TestComputev2):
2727
def setUp(self):
2828
super().setUp()
2929
self.app.client_manager.volume_endpoint_enabled = False
30-
self.compute = self.app.client_manager.compute
30+
self.compute_client = self.app.client_manager.compute
3131

3232
self.fake_limits = compute_fakes.FakeLimits()
33-
self.compute.limits.get.return_value = self.fake_limits
33+
self.compute_client.limits.get.return_value = self.fake_limits
3434

3535
def test_compute_show_absolute(self):
3636
arglist = ['--absolute']

openstackclient/tests/unit/common/test_quota.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ def setUp(self):
4848
self.projects_mock.reset_mock()
4949
self.projects_mock.get.return_value = self.projects[0]
5050

51-
self.compute_quotas_mock = self.app.client_manager.compute.quotas
51+
self.compute_client = self.app.client_manager.compute
52+
self.compute_quotas_mock = self.compute_client.quotas
5253
self.compute_quotas_mock.reset_mock()
53-
self.compute_quotas_class_mock = (
54-
self.app.client_manager.compute.quota_classes
55-
)
54+
self.compute_quotas_class_mock = self.compute_client.quota_classes
5655
self.compute_quotas_class_mock.reset_mock()
5756

5857
self.volume_quotas_mock = self.volume_client.quotas
@@ -125,8 +124,7 @@ def setUp(self):
125124
compute_fakes.create_one_default_comp_quota(),
126125
compute_fakes.create_one_default_comp_quota(),
127126
]
128-
self.compute = self.app.client_manager.compute
129-
self.compute.quotas.defaults = mock.Mock(
127+
self.compute_client.quotas.defaults = mock.Mock(
130128
side_effect=self.compute_default_quotas,
131129
)
132130

@@ -221,7 +219,7 @@ def test_quota_list_details_compute(self):
221219
detailed_quota
222220
)
223221

224-
self.compute.quotas.get = mock.Mock(return_value=detailed_quota)
222+
self.compute_client.quotas.get = mock.Mock(return_value=detailed_quota)
225223

226224
arglist = [
227225
'--detail',
@@ -305,7 +303,7 @@ def test_quota_list_details_volume(self):
305303

306304
def test_quota_list_compute(self):
307305
# Two projects with non-default quotas
308-
self.compute.quotas.get = mock.Mock(
306+
self.compute_client.quotas.get = mock.Mock(
309307
side_effect=self.compute_quotas,
310308
)
311309

@@ -326,7 +324,7 @@ def test_quota_list_compute(self):
326324

327325
def test_quota_list_compute_default(self):
328326
# One of the projects is at defaults
329-
self.compute.quotas.get = mock.Mock(
327+
self.compute_client.quotas.get = mock.Mock(
330328
side_effect=[
331329
self.compute_quotas[0],
332330
compute_fakes.create_one_default_comp_quota(),
@@ -350,7 +348,7 @@ def test_quota_list_compute_default(self):
350348

351349
def test_quota_list_compute_no_project_not_found(self):
352350
# Make one of the projects disappear
353-
self.compute.quotas.get = mock.Mock(
351+
self.compute_client.quotas.get = mock.Mock(
354352
side_effect=[
355353
self.compute_quotas[0],
356354
exceptions.NotFound("NotFound"),
@@ -374,7 +372,7 @@ def test_quota_list_compute_no_project_not_found(self):
374372

375373
def test_quota_list_compute_no_project_4xx(self):
376374
# Make one of the projects disappear
377-
self.compute.quotas.get = mock.Mock(
375+
self.compute_client.quotas.get = mock.Mock(
378376
side_effect=[
379377
self.compute_quotas[0],
380378
exceptions.BadRequest("Bad request"),
@@ -398,7 +396,7 @@ def test_quota_list_compute_no_project_4xx(self):
398396

399397
def test_quota_list_compute_no_project_5xx(self):
400398
# Make one of the projects disappear
401-
self.compute.quotas.get = mock.Mock(
399+
self.compute_client.quotas.get = mock.Mock(
402400
side_effect=[
403401
self.compute_quotas[0],
404402
exceptions.HTTPNotImplemented("Not implemented??"),
@@ -421,7 +419,7 @@ def test_quota_list_compute_no_project_5xx(self):
421419

422420
def test_quota_list_compute_by_project(self):
423421
# Two projects with non-default quotas
424-
self.compute.quotas.get = mock.Mock(
422+
self.compute_client.quotas.get = mock.Mock(
425423
side_effect=self.compute_quotas,
426424
)
427425

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ def setUp(self):
161161
endpoint=fakes.AUTH_URL,
162162
token=fakes.AUTH_TOKEN,
163163
)
164+
self.compute_client = self.app.client_manager.compute
164165

165-
self.app.client_manager.compute.api = compute_v2.APIv2(
166+
self.compute_client.api = compute_v2.APIv2(
166167
session=self.app.client_manager.session,
167168
endpoint=fakes.AUTH_URL,
168169
)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TestAgent(compute_fakes.TestComputev2):
5151
def setUp(self):
5252
super(TestAgent, self).setUp()
5353

54-
self.agents_mock = self.app.client_manager.compute.agents
54+
self.agents_mock = self.compute_client.agents
5555
self.agents_mock.reset_mock()
5656

5757

0 commit comments

Comments
 (0)