|
| 1 | +# |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 3 | +# not use this file except in compliance with the License. You may obtain |
| 4 | +# a copy of the License at |
| 5 | +# |
| 6 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | +# |
| 8 | +# Unless required by applicable law or agreed to in writing, software |
| 9 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 10 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 11 | +# License for the specific language governing permissions and limitations |
| 12 | +# under the License. |
| 13 | +# |
| 14 | + |
| 15 | + |
| 16 | +from openstackclient.tests.volume.v1 import fakes as service_fakes |
| 17 | +from openstackclient.volume.v1 import service |
| 18 | + |
| 19 | + |
| 20 | +class TestService(service_fakes.TestService): |
| 21 | + |
| 22 | + def setUp(self): |
| 23 | + super(TestService, self).setUp() |
| 24 | + |
| 25 | + # Get a shortcut to the ServiceManager Mock |
| 26 | + self.service_mock = self.app.client_manager.volume.services |
| 27 | + self.service_mock.reset_mock() |
| 28 | + |
| 29 | + |
| 30 | +class TestServiceList(TestService): |
| 31 | + |
| 32 | + # The service to be listed |
| 33 | + services = service_fakes.FakeService.create_one_service() |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + super(TestServiceList, self).setUp() |
| 37 | + |
| 38 | + self.service_mock.list.return_value = [self.services] |
| 39 | + |
| 40 | + # Get the command object to test |
| 41 | + self.cmd = service.ListService(self.app, None) |
| 42 | + |
| 43 | + def test_service_list(self): |
| 44 | + arglist = [ |
| 45 | + '--host', self.services.host, |
| 46 | + '--service', self.services.binary, |
| 47 | + ] |
| 48 | + verifylist = [ |
| 49 | + ('host', self.services.host), |
| 50 | + ('service', self.services.binary), |
| 51 | + ] |
| 52 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 53 | + |
| 54 | + # In base command class Lister in cliff, abstract method take_action() |
| 55 | + # returns a tuple containing the column names and an iterable |
| 56 | + # containing the data to be listed. |
| 57 | + columns, data = self.cmd.take_action(parsed_args) |
| 58 | + |
| 59 | + expected_columns = [ |
| 60 | + 'Binary', |
| 61 | + 'Host', |
| 62 | + 'Zone', |
| 63 | + 'Status', |
| 64 | + 'State', |
| 65 | + 'Updated At', |
| 66 | + ] |
| 67 | + |
| 68 | + # confirming if all expected columns are present in the result. |
| 69 | + self.assertEqual(expected_columns, columns) |
| 70 | + |
| 71 | + datalist = (( |
| 72 | + self.services.binary, |
| 73 | + self.services.host, |
| 74 | + self.services.zone, |
| 75 | + self.services.status, |
| 76 | + self.services.state, |
| 77 | + self.services.updated_at, |
| 78 | + ), ) |
| 79 | + |
| 80 | + # confirming if all expected values are present in the result. |
| 81 | + self.assertEqual(datalist, tuple(data)) |
| 82 | + |
| 83 | + # checking if proper call was made to list services |
| 84 | + self.service_mock.list.assert_called_with( |
| 85 | + self.services.host, |
| 86 | + self.services.binary, |
| 87 | + ) |
| 88 | + |
| 89 | + # checking if prohibited columns are present in output |
| 90 | + self.assertNotIn("Disabled Reason", columns) |
| 91 | + self.assertNotIn(self.services.disabled_reason, |
| 92 | + tuple(data)) |
| 93 | + |
| 94 | + def test_service_list_with_long_option(self): |
| 95 | + arglist = [ |
| 96 | + '--host', self.services.host, |
| 97 | + '--service', self.services.binary, |
| 98 | + '--long' |
| 99 | + ] |
| 100 | + verifylist = [ |
| 101 | + ('host', self.services.host), |
| 102 | + ('service', self.services.binary), |
| 103 | + ('long', True) |
| 104 | + ] |
| 105 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 106 | + |
| 107 | + # In base command class Lister in cliff, abstract method take_action() |
| 108 | + # returns a tuple containing the column names and an iterable |
| 109 | + # containing the data to be listed. |
| 110 | + columns, data = self.cmd.take_action(parsed_args) |
| 111 | + |
| 112 | + expected_columns = [ |
| 113 | + 'Binary', |
| 114 | + 'Host', |
| 115 | + 'Zone', |
| 116 | + 'Status', |
| 117 | + 'State', |
| 118 | + 'Updated At', |
| 119 | + 'Disabled Reason' |
| 120 | + ] |
| 121 | + |
| 122 | + # confirming if all expected columns are present in the result. |
| 123 | + self.assertEqual(expected_columns, columns) |
| 124 | + |
| 125 | + datalist = (( |
| 126 | + self.services.binary, |
| 127 | + self.services.host, |
| 128 | + self.services.zone, |
| 129 | + self.services.status, |
| 130 | + self.services.state, |
| 131 | + self.services.updated_at, |
| 132 | + self.services.disabled_reason, |
| 133 | + ), ) |
| 134 | + |
| 135 | + # confirming if all expected values are present in the result. |
| 136 | + self.assertEqual(datalist, tuple(data)) |
| 137 | + |
| 138 | + self.service_mock.list.assert_called_with( |
| 139 | + self.services.host, |
| 140 | + self.services.binary, |
| 141 | + ) |
0 commit comments