Skip to content

Commit d7bf159

Browse files
author
zhiyong.dai
committed
Functional test for configuration
Using json format output in configuration show functional test. Change-Id: I005b361ae70ced3f6cef77291db1d39dafb0793c
1 parent e35c97a commit d7bf159

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

openstackclient/tests/functional/common/test_configuration.py

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

13+
import json
1314
import os
1415

1516
from openstackclient.common import configuration
@@ -20,25 +21,47 @@
2021

2122

2223
class ConfigurationTests(base.TestCase):
23-
24-
opts = "-f value -c auth.password"
24+
"""Functional test for configuration."""
2525

2626
def test_configuration_show(self):
27+
28+
# Test show without option
2729
raw_output = self.openstack('configuration show')
2830
items = self.parse_listing(raw_output)
2931
self.assert_table_structure(items, BASIC_CONFIG_HEADERS)
3032

31-
def test_configuration_show_unmask(self):
32-
raw_output = self.openstack('configuration show --unmask ' + self.opts)
33+
cmd_output = json.loads(self.openstack(
34+
'configuration show -f json'
35+
))
36+
self.assertEqual(
37+
configuration.REDACTED,
38+
cmd_output['auth.password']
39+
)
40+
41+
# Test show --mask
42+
cmd_output = json.loads(self.openstack(
43+
'configuration show --mask -f json'
44+
))
45+
self.assertEqual(
46+
configuration.REDACTED,
47+
cmd_output['auth.password']
48+
)
49+
50+
# Test show --unmask
51+
cmd_output = json.loads(self.openstack(
52+
'configuration show --unmask -f json'
53+
))
3354
# If we are using os-client-config, this will not be set. Rather than
3455
# parse clouds.yaml to get the right value, just make sure
3556
# we are not getting redacted.
3657
passwd = os.environ.get('OS_PASSWORD')
3758
if passwd:
38-
self.assertEqual(passwd + '\n', raw_output)
59+
self.assertEqual(
60+
passwd,
61+
cmd_output['auth.password']
62+
)
3963
else:
40-
self.assertNotEqual(configuration.REDACTED + '\n', raw_output)
41-
42-
def test_configuration_show_mask(self):
43-
raw_output = self.openstack('configuration show --mask ' + self.opts)
44-
self.assertEqual(configuration.REDACTED + '\n', raw_output)
64+
self.assertNotEqual(
65+
configuration.REDACTED,
66+
cmd_output['auth.password']
67+
)

0 commit comments

Comments
 (0)