|
5 | 5 | :license: MIT, see LICENSE for more details. |
6 | 6 | """ |
7 | 7 | from SoftLayer.CLI import exceptions |
| 8 | +from SoftLayer.CLI import formatting |
8 | 9 | from SoftLayer import SoftLayerAPIError |
9 | 10 | from SoftLayer import testing |
10 | 11 |
|
11 | | - |
12 | 12 | import json |
13 | 13 | from unittest import mock as mock |
14 | 14 |
|
@@ -135,14 +135,45 @@ def test_volume_list(self): |
135 | 135 | 'IOPs': None, |
136 | 136 | 'ip_addr': '10.1.2.3', |
137 | 137 | 'lunId': None, |
138 | | - 'notes': "{'status': 'availabl", |
| 138 | + 'notes': "{'status': 'available'}", |
139 | 139 | 'rep_partner_count': None, |
140 | 140 | 'storage_type': 'ENDURANCE', |
141 | 141 | 'username': 'username', |
142 | 142 | 'active_transactions': None |
143 | 143 | }], |
144 | 144 | json.loads(result.output)) |
145 | 145 |
|
| 146 | + @mock.patch('SoftLayer.BlockStorageManager.list_block_volumes') |
| 147 | + def test_volume_list_notes_format_output_json(self, list_mock): |
| 148 | + note_mock = 'test ' * 5 |
| 149 | + list_mock.return_value = [ |
| 150 | + {'notes': note_mock} |
| 151 | + ] |
| 152 | + |
| 153 | + result = self.run_command(['--format', 'json', 'block', 'volume-list', '--columns', 'notes']) |
| 154 | + |
| 155 | + self.assert_no_fail(result) |
| 156 | + self.assertEqual( |
| 157 | + [{ |
| 158 | + 'notes': note_mock, |
| 159 | + }], |
| 160 | + json.loads(result.output)) |
| 161 | + |
| 162 | + @mock.patch('SoftLayer.BlockStorageManager.list_block_volumes') |
| 163 | + def test_volume_list_reduced_notes_format_output_table(self, list_mock): |
| 164 | + note_mock = 'test ' * 10 |
| 165 | + expected_reduced_note = 'test ' * 4 |
| 166 | + list_mock.return_value = [ |
| 167 | + {'notes': note_mock} |
| 168 | + ] |
| 169 | + expected_table = formatting.Table(['notes']) |
| 170 | + expected_table.add_row([expected_reduced_note]) |
| 171 | + expected_output = formatting.format_output(expected_table)+'\n' |
| 172 | + result = self.run_command(['--format', 'table', 'block', 'volume-list', '--columns', 'notes']) |
| 173 | + |
| 174 | + self.assert_no_fail(result) |
| 175 | + self.assertEqual(expected_output, result.output) |
| 176 | + |
146 | 177 | def test_volume_list_order(self): |
147 | 178 | result = self.run_command(['block', 'volume-list', '--order=1234567']) |
148 | 179 |
|
|
0 commit comments