Skip to content

Commit c1de463

Browse files
committed
#1481 add tests to block and file cli to shows the whole notes in a format json output
1 parent 66a3cde commit c1de463

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

tests/CLI/environment_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ def test_print_unicode(self, echo):
8181
]
8282
self.env.fout(output)
8383
self.assertEqual(2, echo.call_count)
84+
85+
def test_format_output_is_json(self):
86+
self.env.format = 'jsonraw'
87+
self.assertTrue(self.env.format_output_is_json())

tests/CLI/modules/block_tests.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
:license: MIT, see LICENSE for more details.
66
"""
77
from SoftLayer.CLI import exceptions
8+
from SoftLayer.CLI import formatting
89
from SoftLayer import SoftLayerAPIError
910
from SoftLayer import testing
1011

11-
1212
import json
1313
from unittest import mock as mock
1414

@@ -135,14 +135,45 @@ def test_volume_list(self):
135135
'IOPs': None,
136136
'ip_addr': '10.1.2.3',
137137
'lunId': None,
138-
'notes': "{'status': 'availabl",
138+
'notes': "{'status': 'available'}",
139139
'rep_partner_count': None,
140140
'storage_type': 'ENDURANCE',
141141
'username': 'username',
142142
'active_transactions': None
143143
}],
144144
json.loads(result.output))
145145

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+
146177
def test_volume_list_order(self):
147178
result = self.run_command(['block', 'volume-list', '--order=1234567'])
148179

tests/CLI/modules/file_tests.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:license: MIT, see LICENSE for more details.
66
"""
77
from SoftLayer.CLI import exceptions
8+
from SoftLayer.CLI import formatting
89
from SoftLayer import SoftLayerError
910
from SoftLayer import testing
1011

@@ -63,6 +64,37 @@ def test_volume_list_order(self):
6364
json_result = json.loads(result.output)
6465
self.assertEqual(json_result[0]['id'], 1)
6566

67+
@mock.patch('SoftLayer.FileStorageManager.list_file_volumes')
68+
def test_volume_list_notes_format_output_json(self, list_mock):
69+
note_mock = 'test ' * 5
70+
list_mock.return_value = [
71+
{'notes': note_mock}
72+
]
73+
74+
result = self.run_command(['--format', 'json', 'file', 'volume-list', '--columns', 'notes'])
75+
76+
self.assert_no_fail(result)
77+
self.assertEqual(
78+
[{
79+
'notes': note_mock,
80+
}],
81+
json.loads(result.output))
82+
83+
@mock.patch('SoftLayer.FileStorageManager.list_file_volumes')
84+
def test_volume_list_reduced_notes_format_output_table(self, list_mock):
85+
note_mock = 'test ' * 10
86+
expected_reduced_note = 'test ' * 4
87+
list_mock.return_value = [
88+
{'notes': note_mock}
89+
]
90+
expected_table = formatting.Table(['notes'])
91+
expected_table.add_row([expected_reduced_note])
92+
expected_output = formatting.format_output(expected_table) + '\n'
93+
result = self.run_command(['--format', 'table', 'file', 'volume-list', '--columns', 'notes'])
94+
95+
self.assert_no_fail(result)
96+
self.assertEqual(expected_output, result.output)
97+
6698
@mock.patch('SoftLayer.FileStorageManager.list_file_volumes')
6799
def test_volume_count(self, list_mock):
68100
list_mock.return_value = [

0 commit comments

Comments
 (0)