Repository: softlayer/softlayer-python
Pull request #1924 (2023-04-24 15:01:37)

Added double quotes in CSV outputformat 
Issue: #1921
```
softlayer-python/ (issue1916) $ slcli --format=csv account billing-items
"Id","Create Date","Cost","Category Code","Ordered By","Description","Notes"
19388750,"2014-02-22",0.0,"guest_storage","IBM","Image Template Storage","None"
```
The problem with the "Tests / analysis" was solved in the PR #1917


Patch:
diff --git a/SoftLayer/CLI/formatting.py b/SoftLayer/CLI/formatting.py
index f85de2a9..e23eb527 100644
--- a/SoftLayer/CLI/formatting.py
+++ b/SoftLayer/CLI/formatting.py
@@ -467,7 +467,7 @@ def clean_table(data, delimiter):
 
             if str(type(value)) == "<class 'SoftLayer.CLI.formatting.Table'>":
                 string_io = io.StringIO()
-                write_csv_format(string_io, value, delimiter)
+                write_csv_format(string_io, value, delimiter, quoting=csv.QUOTE_MINIMAL)
 
                 nested_table_converted = string_io.getvalue()
                 nested_table_converted = nested_table_converted.replace('\r', '').split('\n')
@@ -488,8 +488,8 @@ def clean_table(data, delimiter):
     return data
 
 
-def write_csv_format(support_output, data, delimiter):
+def write_csv_format(support_output, data, delimiter, quoting=csv.QUOTE_NONNUMERIC):
     """Write csv format to supported output"""
-    writer = csv.writer(support_output, delimiter=delimiter)
+    writer = csv.writer(support_output, delimiter=delimiter, quoting=quoting)
     writer.writerow(data.columns)
     writer.writerows(data.rows)


Test patch:
diff --git a/tests/CLI/modules/account_tests.py b/tests/CLI/modules/account_tests.py
index a158713f..d45c70aa 100644
--- a/tests/CLI/modules/account_tests.py
+++ b/tests/CLI/modules/account_tests.py
@@ -70,10 +70,11 @@ def test_invoice_detail_csv_output_format(self):
         result = self.run_command(["--format", "csv", 'account', 'invoice-detail', '1234'])
         result_output = result.output.replace('\r', '').split('\n')
         self.assert_no_fail(result)
-        self.assertEqual(result_output[0], 'Item Id,Category,Description,Single,Monthly,Create Date,Location')
-        self.assertEqual(result_output[1], '724951323,Private (only) Secondary VLAN IP Addresses,'
-                                           '64 Portable Private IP Addresses (bleg.beh.com),'
-                                           '$0.00,$0.00,2018-04-04,fra02')
+        self.assertEqual(result_output[0], '"Item Id","Category","Description","Single","Monthly",'
+                         '"Create Date","Location"')
+        self.assertEqual(result_output[1], '724951323,"Private (only) Secondary VLAN IP Addresses",'
+                                           '"64 Portable Private IP Addresses (bleg.beh.com)",'
+                                           '"$0.00","$0.00","2018-04-04","fra02"')
 
     # slcli account invoices
     def test_invoices(self):
diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py
index fc0807fd..78dc9c50 100644
--- a/tests/CLI/modules/vs/vs_tests.py
+++ b/tests/CLI/modules/vs/vs_tests.py
@@ -335,18 +335,18 @@ def test_vs_detail_csv_output_format_with_nested_tables(self):
         result = self.run_command(["--format", "csv", 'vs', 'detail', '100'])
         result_output = result.output.replace('\r', '').split('\n')
         self.assert_no_fail(result)
-        self.assertEqual(result_output[0], 'name,value')
-        self.assertEqual(result_output[1], 'id,100')
-        self.assertEqual(result_output[16], 'drives,"Type,Name,Drive,Capacity"')
-        self.assertEqual(result_output[17], 'drives,"System,Disk,0,100 GB"')
-        self.assertEqual(result_output[18], 'drives,"Swap,Disk,1,2 GB"')
-        self.assertEqual(result_output[30], 'vlans,"type,number,id"')
-        self.assertEqual(result_output[31], 'vlans,"PUBLIC,23,1"')
-        self.assertEqual(result_output[32], 'Bandwidth,"Type,In GB,Out GB,Allotment"')
-        self.assertEqual(result_output[33], 'Bandwidth,"Public,.448,.52157,250"')
-        self.assertEqual(result_output[34], 'Bandwidth,"Private,.03842,.01822,N/A"')
-        self.assertEqual(result_output[35], 'security_groups,"interface,id,name"')
-        self.assertEqual(result_output[36], 'security_groups,"PRIVATE,128321,allow_all"')
+        self.assertEqual(result_output[0], '"name","value"')
+        self.assertEqual(result_output[1], '"id",100')
+        self.assertEqual(result_output[16], '"drives","Type,Name,Drive,Capacity"')
+        self.assertEqual(result_output[17], '"drives","System,Disk,0,100 GB"')
+        self.assertEqual(result_output[18], '"drives","Swap,Disk,1,2 GB"')
+        self.assertEqual(result_output[30], '"vlans","type,number,id"')
+        self.assertEqual(result_output[31], '"vlans","PUBLIC,23,1"')
+        self.assertEqual(result_output[32], '"Bandwidth","Type,In GB,Out GB,Allotment"')
+        self.assertEqual(result_output[33], '"Bandwidth","Public,.448,.52157,250"')
+        self.assertEqual(result_output[34], '"Bandwidth","Private,.03842,.01822,N/A"')
+        self.assertEqual(result_output[35], '"security_groups","interface,id,name"')
+        self.assertEqual(result_output[36], '"security_groups","PRIVATE,128321,allow_all"')
 
     def test_create_options(self):
         result = self.run_command(['vs', 'create-options', '--vsi-type', 'TRANSIENT_CLOUD_SERVER'])