Skip to content

Commit fb14b43

Browse files
Merge pull request #1924 from edsonarios/issue1921
Added double quotes in CSV outputformat
2 parents 6f7d3f1 + 212a942 commit fb14b43

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

SoftLayer/CLI/formatting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def clean_table(data, delimiter):
467467

468468
if str(type(value)) == "<class 'SoftLayer.CLI.formatting.Table'>":
469469
string_io = io.StringIO()
470-
write_csv_format(string_io, value, delimiter)
470+
write_csv_format(string_io, value, delimiter, quoting=csv.QUOTE_MINIMAL)
471471

472472
nested_table_converted = string_io.getvalue()
473473
nested_table_converted = nested_table_converted.replace('\r', '').split('\n')
@@ -488,8 +488,8 @@ def clean_table(data, delimiter):
488488
return data
489489

490490

491-
def write_csv_format(support_output, data, delimiter):
491+
def write_csv_format(support_output, data, delimiter, quoting=csv.QUOTE_NONNUMERIC):
492492
"""Write csv format to supported output"""
493-
writer = csv.writer(support_output, delimiter=delimiter)
493+
writer = csv.writer(support_output, delimiter=delimiter, quoting=quoting)
494494
writer.writerow(data.columns)
495495
writer.writerows(data.rows)

tests/CLI/modules/account_tests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,11 @@ def test_invoice_detail_csv_output_format(self):
7070
result = self.run_command(["--format", "csv", 'account', 'invoice-detail', '1234'])
7171
result_output = result.output.replace('\r', '').split('\n')
7272
self.assert_no_fail(result)
73-
self.assertEqual(result_output[0], 'Item Id,Category,Description,Single,Monthly,Create Date,Location')
74-
self.assertEqual(result_output[1], '724951323,Private (only) Secondary VLAN IP Addresses,'
75-
'64 Portable Private IP Addresses (bleg.beh.com),'
76-
'$0.00,$0.00,2018-04-04,fra02')
73+
self.assertEqual(result_output[0], '"Item Id","Category","Description","Single","Monthly",'
74+
'"Create Date","Location"')
75+
self.assertEqual(result_output[1], '724951323,"Private (only) Secondary VLAN IP Addresses",'
76+
'"64 Portable Private IP Addresses (bleg.beh.com)",'
77+
'"$0.00","$0.00","2018-04-04","fra02"')
7778

7879
# slcli account invoices
7980
def test_invoices(self):

tests/CLI/modules/vs/vs_tests.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,18 @@ def test_vs_detail_csv_output_format_with_nested_tables(self):
335335
result = self.run_command(["--format", "csv", 'vs', 'detail', '100'])
336336
result_output = result.output.replace('\r', '').split('\n')
337337
self.assert_no_fail(result)
338-
self.assertEqual(result_output[0], 'name,value')
339-
self.assertEqual(result_output[1], 'id,100')
340-
self.assertEqual(result_output[16], 'drives,"Type,Name,Drive,Capacity"')
341-
self.assertEqual(result_output[17], 'drives,"System,Disk,0,100 GB"')
342-
self.assertEqual(result_output[18], 'drives,"Swap,Disk,1,2 GB"')
343-
self.assertEqual(result_output[30], 'vlans,"type,number,id"')
344-
self.assertEqual(result_output[31], 'vlans,"PUBLIC,23,1"')
345-
self.assertEqual(result_output[32], 'Bandwidth,"Type,In GB,Out GB,Allotment"')
346-
self.assertEqual(result_output[33], 'Bandwidth,"Public,.448,.52157,250"')
347-
self.assertEqual(result_output[34], 'Bandwidth,"Private,.03842,.01822,N/A"')
348-
self.assertEqual(result_output[35], 'security_groups,"interface,id,name"')
349-
self.assertEqual(result_output[36], 'security_groups,"PRIVATE,128321,allow_all"')
338+
self.assertEqual(result_output[0], '"name","value"')
339+
self.assertEqual(result_output[1], '"id",100')
340+
self.assertEqual(result_output[16], '"drives","Type,Name,Drive,Capacity"')
341+
self.assertEqual(result_output[17], '"drives","System,Disk,0,100 GB"')
342+
self.assertEqual(result_output[18], '"drives","Swap,Disk,1,2 GB"')
343+
self.assertEqual(result_output[30], '"vlans","type,number,id"')
344+
self.assertEqual(result_output[31], '"vlans","PUBLIC,23,1"')
345+
self.assertEqual(result_output[32], '"Bandwidth","Type,In GB,Out GB,Allotment"')
346+
self.assertEqual(result_output[33], '"Bandwidth","Public,.448,.52157,250"')
347+
self.assertEqual(result_output[34], '"Bandwidth","Private,.03842,.01822,N/A"')
348+
self.assertEqual(result_output[35], '"security_groups","interface,id,name"')
349+
self.assertEqual(result_output[36], '"security_groups","PRIVATE,128321,allow_all"')
350350

351351
def test_create_options(self):
352352
result = self.run_command(['vs', 'create-options', '--vsi-type', 'TRANSIENT_CLOUD_SERVER'])

0 commit comments

Comments
 (0)