|
10 | 10 | # License for the specific language governing permissions and limitations |
11 | 11 | # under the License. |
12 | 12 |
|
| 13 | +import json |
13 | 14 | import os |
14 | 15 |
|
15 | 16 | from openstackclient.common import configuration |
|
20 | 21 |
|
21 | 22 |
|
22 | 23 | class ConfigurationTests(base.TestCase): |
23 | | - |
24 | | - opts = "-f value -c auth.password" |
| 24 | + """Functional test for configuration.""" |
25 | 25 |
|
26 | 26 | def test_configuration_show(self): |
| 27 | + |
| 28 | + # Test show without option |
27 | 29 | raw_output = self.openstack('configuration show') |
28 | 30 | items = self.parse_listing(raw_output) |
29 | 31 | self.assert_table_structure(items, BASIC_CONFIG_HEADERS) |
30 | 32 |
|
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 | + )) |
33 | 54 | # If we are using os-client-config, this will not be set. Rather than |
34 | 55 | # parse clouds.yaml to get the right value, just make sure |
35 | 56 | # we are not getting redacted. |
36 | 57 | passwd = os.environ.get('OS_PASSWORD') |
37 | 58 | if passwd: |
38 | | - self.assertEqual(passwd + '\n', raw_output) |
| 59 | + self.assertEqual( |
| 60 | + passwd, |
| 61 | + cmd_output['auth.password'] |
| 62 | + ) |
39 | 63 | 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