Skip to content

Commit 50015b9

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "tests: Convert more functional tests to use 'parse_output'"
2 parents d5b6f5a + 38e39b6 commit 50015b9

6 files changed

Lines changed: 105 additions & 113 deletions

File tree

openstackclient/tests/functional/common/test_args.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import json
14-
1513
from tempest.lib import exceptions as tempest_exc
1614

1715
from openstackclient.tests.functional import base
@@ -21,10 +19,11 @@ class ArgumentTests(base.TestCase):
2119
"""Functional tests for command line arguments"""
2220

2321
def test_default_auth_type(self):
24-
cmd_output = json.loads(self.openstack(
25-
'configuration show -f json',
22+
cmd_output = self.openstack(
23+
'configuration show',
2624
cloud='',
27-
))
25+
parse_output=True,
26+
)
2827
self.assertIsNotNone(cmd_output)
2928
self.assertIn(
3029
'auth_type',
@@ -36,10 +35,11 @@ def test_default_auth_type(self):
3635
)
3736

3837
def test_auth_type_none(self):
39-
cmd_output = json.loads(self.openstack(
40-
'configuration show -f json',
38+
cmd_output = self.openstack(
39+
'configuration show',
4140
cloud=None,
42-
))
41+
parse_output=True,
42+
)
4343
self.assertIsNotNone(cmd_output)
4444
self.assertIn(
4545
'auth_type',
@@ -54,7 +54,7 @@ def test_auth_type_token_endpoint_opt(self):
5454
# Make sure token_endpoint is really gone
5555
try:
5656
self.openstack(
57-
'configuration show -f json --os-auth-type token_endpoint',
57+
'configuration show --os-auth-type token_endpoint',
5858
cloud=None,
5959
)
6060
except tempest_exc.CommandFailed as e:
@@ -64,10 +64,11 @@ def test_auth_type_token_endpoint_opt(self):
6464
self.fail('CommandFailed should be raised')
6565

6666
def test_auth_type_password_opt(self):
67-
cmd_output = json.loads(self.openstack(
68-
'configuration show -f json --os-auth-type password',
67+
cmd_output = self.openstack(
68+
'configuration show --os-auth-type password',
6969
cloud=None,
70-
))
70+
parse_output=True,
71+
)
7172
self.assertIsNotNone(cmd_output)
7273
self.assertIn(
7374
'auth_type',

openstackclient/tests/functional/common/test_availability_zone.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import json
14-
1513
from openstackclient.tests.functional import base
1614

1715

1816
class AvailabilityZoneTests(base.TestCase):
1917
"""Functional tests for availability zone. """
2018

2119
def test_availability_zone_list(self):
22-
cmd_output = json.loads(self.openstack(
23-
'availability zone list -f json'))
20+
cmd_output = self.openstack(
21+
'availability zone list',
22+
parse_output=True,
23+
)
2424
zones = [x['Zone Name'] for x in cmd_output]
2525
self.assertIn(
2626
'internal',

openstackclient/tests/functional/common/test_configuration.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13-
import json
1413
import os
1514

1615
from openstackclient.common import configuration
@@ -30,9 +29,7 @@ def test_configuration_show(self):
3029
items = self.parse_listing(raw_output)
3130
self.assert_table_structure(items, BASIC_CONFIG_HEADERS)
3231

33-
cmd_output = json.loads(self.openstack(
34-
'configuration show -f json'
35-
))
32+
cmd_output = self.openstack('configuration show', parse_output=True)
3633
self.assertEqual(
3734
configuration.REDACTED,
3835
cmd_output['auth.password']
@@ -43,18 +40,18 @@ def test_configuration_show(self):
4340
)
4441

4542
# Test show --mask
46-
cmd_output = json.loads(self.openstack(
47-
'configuration show --mask -f json'
48-
))
43+
cmd_output = self.openstack(
44+
'configuration show --mask', parse_output=True,
45+
)
4946
self.assertEqual(
5047
configuration.REDACTED,
5148
cmd_output['auth.password']
5249
)
5350

5451
# Test show --unmask
55-
cmd_output = json.loads(self.openstack(
56-
'configuration show --unmask -f json'
57-
))
52+
cmd_output = self.openstack(
53+
'configuration show --unmask', parse_output=True,
54+
)
5855
# If we are using os-client-config, this will not be set. Rather than
5956
# parse clouds.yaml to get the right value, just make sure
6057
# we are not getting redacted.
@@ -84,10 +81,11 @@ def test_configuration_show(self):
8481
items = self.parse_listing(raw_output)
8582
self.assert_table_structure(items, BASIC_CONFIG_HEADERS)
8683

87-
cmd_output = json.loads(self.openstack(
88-
'configuration show -f json',
84+
cmd_output = self.openstack(
85+
'configuration show',
8986
cloud=None,
90-
))
87+
parse_output=True,
88+
)
9189
self.assertNotIn(
9290
'auth.password',
9391
cmd_output,

openstackclient/tests/functional/common/test_extension.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# License for the specific language governing permissions and limitations
1414
# under the License.
1515

16-
import json
17-
1816
from tempest.lib import exceptions as tempest_exc
1917

2018
from openstackclient.tests.functional import base
@@ -30,23 +28,23 @@ def setUpClass(cls):
3028

3129
def test_extension_list_compute(self):
3230
"""Test compute extension list"""
33-
json_output = json.loads(self.openstack(
34-
'extension list -f json ' +
35-
'--compute'
36-
))
37-
name_list = [item.get('Name') for item in json_output]
31+
output = self.openstack(
32+
'extension list --compute',
33+
parse_output=True,
34+
)
35+
name_list = [item.get('Name') for item in output]
3836
self.assertIn(
3937
'ImageSize',
4038
name_list,
4139
)
4240

4341
def test_extension_list_volume(self):
4442
"""Test volume extension list"""
45-
json_output = json.loads(self.openstack(
46-
'extension list -f json ' +
47-
'--volume'
48-
))
49-
name_list = [item.get('Name') for item in json_output]
43+
output = self.openstack(
44+
'extension list --volume',
45+
parse_output=True,
46+
)
47+
name_list = [item.get('Name') for item in output]
5048
self.assertIn(
5149
'TypesManage',
5250
name_list,
@@ -57,43 +55,29 @@ def test_extension_list_network(self):
5755
if not self.haz_network:
5856
self.skipTest("No Network service present")
5957

60-
json_output = json.loads(self.openstack(
61-
'extension list -f json ' +
62-
'--network'
63-
))
64-
name_list = [item.get('Name') for item in json_output]
58+
output = self.openstack(
59+
'extension list --network',
60+
parse_output=True,
61+
)
62+
name_list = [item.get('Name') for item in output]
6563
self.assertIn(
6664
'Default Subnetpools',
6765
name_list,
6866
)
6967

70-
# NOTE(dtroyer): Only network extensions are currently supported but
71-
# I am going to leave this here anyway as a reminder
72-
# fix that.
73-
# def test_extension_show_compute(self):
74-
# """Test compute extension show"""
75-
# json_output = json.loads(self.openstack(
76-
# 'extension show -f json ' +
77-
# 'ImageSize'
78-
# ))
79-
# self.assertEqual(
80-
# 'OS-EXT-IMG-SIZE',
81-
# json_output.get('Alias'),
82-
# )
83-
8468
def test_extension_show_network(self):
8569
"""Test network extension show"""
8670
if not self.haz_network:
8771
self.skipTest("No Network service present")
8872

8973
name = 'agent'
90-
json_output = json.loads(self.openstack(
91-
'extension show -f json ' +
92-
name
93-
))
74+
output = self.openstack(
75+
'extension show ' + name,
76+
parse_output=True,
77+
)
9478
self.assertEqual(
9579
name,
96-
json_output.get('alias'),
80+
output.get('alias'),
9781
)
9882

9983
def test_extension_show_not_exist(self):

0 commit comments

Comments
 (0)