Repository: softlayer/softlayer-python
Pull request #1918 (2023-04-19 19:05:44)

New command: slcli order quote-delete
[#issue1915](https://github.com/softlayer/softlayer-python/issues/1915)

![image](https://user-images.githubusercontent.com/22535437/233175258-8846b6f5-41e7-4f2c-b2d2-edef05ab5c85.png)



Patch:
diff --git a/SoftLayer/CLI/order/quote_delete.py b/SoftLayer/CLI/order/quote_delete.py
new file mode 100644
index 00000000..2b00ad3a
--- /dev/null
+++ b/SoftLayer/CLI/order/quote_delete.py
@@ -0,0 +1,20 @@
+"""Delete the quote of an order"""
+# :license: MIT, see LICENSE for more details.
+import click
+
+from SoftLayer.CLI.command import SLCommand as SLCommand
+from SoftLayer.CLI import environment
+from SoftLayer.managers import ordering
+
+
+@click.command(cls=SLCommand)
+@click.argument('identifier')
+@environment.pass_env
+def cli(env, identifier):
+    """Delete the quote of an order"""
+
+    manager = ordering.OrderingManager(env.client)
+    result = manager.delete_quote(identifier)
+
+    if result:
+        env.fout(f"Quote id: {identifier} was deleted.")
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 9550b927..8527c5ce 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -275,6 +275,7 @@
     ('order:place-quote', 'SoftLayer.CLI.order.place_quote:cli'),
     ('order:quote-list', 'SoftLayer.CLI.order.quote_list:cli'),
     ('order:quote-detail', 'SoftLayer.CLI.order.quote_detail:cli'),
+    ('order:quote-delete', 'SoftLayer.CLI.order.quote_delete:cli'),
     ('order:quote-save', 'SoftLayer.CLI.order.quote_save:cli'),
     ('order:quote', 'SoftLayer.CLI.order.quote:cli'),
     ('order:lookup', 'SoftLayer.CLI.order.lookup:cli'),
diff --git a/SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py b/SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py
index 9e7340e6..ee17078d 100644
--- a/SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py
+++ b/SoftLayer/fixtures/SoftLayer_Billing_Order_Quote.py
@@ -104,3 +104,4 @@
 }
 
 saveQuote = getObject
+deleteQuote = getObject
diff --git a/SoftLayer/managers/ordering.py b/SoftLayer/managers/ordering.py
index cb5bd428..778d7bab 100644
--- a/SoftLayer/managers/ordering.py
+++ b/SoftLayer/managers/ordering.py
@@ -737,3 +737,11 @@ def get_regions(self, package_id, location=None):
         if location:
             _filter = {"regions": {"location": {"location": {"name": {"operation": location}}}}}
         return self.client.call('SoftLayer_Product_Package', 'getRegions', id=package_id, filter=_filter)
+
+    def delete_quote(self, quote_id):
+        """Delete the quote of an order.
+
+        :param quote_id: ID number of target quote
+        """
+
+        return self.client['SoftLayer_Billing_Order_Quote'].deleteQuote(id=quote_id)
diff --git a/docs/cli/ordering.rst b/docs/cli/ordering.rst
index 740438a6..93d578cf 100644
--- a/docs/cli/ordering.rst
+++ b/docs/cli/ordering.rst
@@ -139,6 +139,10 @@ Quotes
     :prog: order place-quote
     :show-nested:
 
+.. click:: SoftLayer.CLI.order.quote_delete:cli
+    :prog: order quote-delete
+    :show-nested:
+
 Lookup
 ======
 .. click:: SoftLayer.CLI.order.lookup:cli


Test patch:
diff --git a/tests/CLI/modules/order_tests.py b/tests/CLI/modules/order_tests.py
index 88c5d869..c175e1b8 100644
--- a/tests/CLI/modules/order_tests.py
+++ b/tests/CLI/modules/order_tests.py
@@ -442,6 +442,11 @@ def test_order_lookup(self):
         self.assertIn('Ordered By', result.output)
         self.assertIn('Initial Invoice', result.output)
 
+    def test_quote_delete(self):
+        result = self.run_command(['order', 'quote-delete', '12345'])
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote', identifier='12345')
+
 
 def _get_all_packages():
     package_type = {'keyName': 'BARE_METAL_CPU'}
diff --git a/tests/CLI/modules/sshkey_tests.py b/tests/CLI/modules/sshkey_tests.py
index 61260a2f..c4646f7b 100644
--- a/tests/CLI/modules/sshkey_tests.py
+++ b/tests/CLI/modules/sshkey_tests.py
@@ -118,7 +118,7 @@ def test_print_key(self):
                          {'id': 1234, 'label': 'label', 'notes': 'notes'})
 
     def test_print_key_file(self):
-        if(sys.platform.startswith("win")):
+        if (sys.platform.startswith("win")):
             self.skipTest("Test doesn't work in Windows")
         with tempfile.NamedTemporaryFile() as sshkey_file:
             service = self.client['Security_Ssh_Key']
diff --git a/tests/CLI/modules/vs/vs_create_tests.py b/tests/CLI/modules/vs/vs_create_tests.py
index 468bc533..e2e43904 100644
--- a/tests/CLI/modules/vs/vs_create_tests.py
+++ b/tests/CLI/modules/vs/vs_create_tests.py
@@ -69,28 +69,28 @@ def test_create_vlan_subnet(self, confirm_mock):
         self.assertIn('"guid": "1a2b3c-1701"', result.output)
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
         args = ({
-            'startCpus': 2,
-            'maxMemory': 1024,
-            'hostname': 'host',
-            'domain': 'example.com',
-            'localDiskFlag': True,
-            'hourlyBillingFlag': True,
-            'supplementalCreateObjectOptions': {'bootMode': None},
-            'operatingSystemReferenceCode': 'UBUNTU_LATEST',
-            'datacenter': {'name': 'dal05'},
-            'primaryBackendNetworkComponent': {
-                'networkVlan': {
-                    'id': 577940,
-                    'primarySubnet': {'id': 478700}
-                }
-            },
-            'primaryNetworkComponent': {
-                'networkVlan': {
-                    'id': 1639255,
-                    'primarySubnet': {'id': 297614}
-                }
-            }
-        },)
+                    'startCpus': 2,
+                    'maxMemory': 1024,
+                    'hostname': 'host',
+                    'domain': 'example.com',
+                    'localDiskFlag': True,
+                    'hourlyBillingFlag': True,
+                    'supplementalCreateObjectOptions': {'bootMode': None},
+                    'operatingSystemReferenceCode': 'UBUNTU_LATEST',
+                    'datacenter': {'name': 'dal05'},
+                    'primaryBackendNetworkComponent': {
+                        'networkVlan': {
+                            'id': 577940,
+                            'primarySubnet': {'id': 478700}
+                        }
+                    },
+                    'primaryNetworkComponent': {
+                        'networkVlan': {
+                            'id': 1639255,
+                            'primarySubnet': {'id': 297614}
+                        }
+                    }
+                },)
 
         self.assert_called_with('SoftLayer_Virtual_Guest', 'generateOrderTemplate', args=args)
 
@@ -114,26 +114,26 @@ def test_create_by_router(self, confirm_mock):
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
         args = ({
-            'startCpus': 2,
-            'maxMemory': 1024,
-            'hostname': 'host',
-            'domain': 'example.com',
-            'localDiskFlag': True,
-            'hourlyBillingFlag': True,
-            'supplementalCreateObjectOptions': {'bootMode': None},
-            'operatingSystemReferenceCode': 'UBUNTU_LATEST',
-            'datacenter': {'name': 'dal05'},
-            'primaryBackendNetworkComponent': {
+                    'startCpus': 2,
+                    'maxMemory': 1024,
+                    'hostname': 'host',
+                    'domain': 'example.com',
+                    'localDiskFlag': True,
+                    'hourlyBillingFlag': True,
+                    'supplementalCreateObjectOptions': {'bootMode': None},
+                    'operatingSystemReferenceCode': 'UBUNTU_LATEST',
+                    'datacenter': {'name': 'dal05'},
+                    'primaryBackendNetworkComponent': {
                         'router': {
                             'id': 577940
                         }
-            },
-            'primaryNetworkComponent': {
-                'router': {
-                    'id': 1639255
-                }
-            }
-        },)
+                    },
+                    'primaryNetworkComponent': {
+                        'router': {
+                            'id': 1639255
+                        }
+                    }
+                },)
 
         self.assert_called_with('SoftLayer_Virtual_Guest', 'generateOrderTemplate', args=args)
 
@@ -216,17 +216,17 @@ def test_create_with_integer_image_guid(self, confirm_mock):
         self.assert_no_fail(result)
         self.assertIn('"guid": "1a2b3c-1701"', result.output)
         args = ({
-            'startCpus': 2,
-            'maxMemory': 1024,
-            'hostname': 'host',
-            'domain': 'example.com',
-            'localDiskFlag': True,
-            'hourlyBillingFlag': True,
-            'supplementalCreateObjectOptions': {'bootMode': None},
-            'blockDeviceTemplateGroup': {'globalIdentifier': 'aaaa1111bbbb2222'},
-            'datacenter': {'name': 'dal05'},
-            'networkComponents': [{'maxSpeed': 100}]
-        },)
+                    'startCpus': 2,
+                    'maxMemory': 1024,
+                    'hostname': 'host',
+                    'domain': 'example.com',
+                    'localDiskFlag': True,
+                    'hourlyBillingFlag': True,
+                    'supplementalCreateObjectOptions': {'bootMode': None},
+                    'blockDeviceTemplateGroup': {'globalIdentifier': 'aaaa1111bbbb2222'},
+                    'datacenter': {'name': 'dal05'},
+                    'networkComponents': [{'maxSpeed': 100}]
+                },)
 
         self.assert_called_with('SoftLayer_Virtual_Guest', 'generateOrderTemplate', args=args)
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
@@ -345,18 +345,18 @@ def test_create_with_host_id(self, confirm_mock):
 
         self.assert_called_with('SoftLayer_Product_Order', 'placeOrder')
         template_args = ({
-            'startCpus': 2,
-            'maxMemory': 1024,
-            'hostname': 'host',
-            'domain': 'example.com',
-            'localDiskFlag': True,
-            'hourlyBillingFlag': True,
-            'supplementalCreateObjectOptions': {'bootMode': None},
-            'dedicatedHost': {'id': 123},
-            'operatingSystemReferenceCode': 'UBUNTU_LATEST',
-            'datacenter': {'name': 'dal05'},
-            'networkComponents': [{'maxSpeed': 100}]
-        },)
+                             'startCpus': 2,
+                             'maxMemory': 1024,
+                             'hostname': 'host',
+                             'domain': 'example.com',
+                             'localDiskFlag': True,
+                             'hourlyBillingFlag': True,
+                             'supplementalCreateObjectOptions': {'bootMode': None},
+                             'dedicatedHost': {'id': 123},
+                             'operatingSystemReferenceCode': 'UBUNTU_LATEST',
+                             'datacenter': {'name': 'dal05'},
+                             'networkComponents': [{'maxSpeed': 100}]
+                         },)
 
         self.assert_called_with('SoftLayer_Virtual_Guest', 'generateOrderTemplate', args=template_args)
 
@@ -633,22 +633,21 @@ def test_create_with_ipv6(self, confirm_mock):
         self.assertEqual(result.exit_code, 0)
         self.assert_called_with('SoftLayer_Product_Order', 'verifyOrder')
         args = ({
-            'startCpus': None,
-            'maxMemory': None,
-            'hostname': 'TEST',
-            'domain': 'TESTING',
-            'localDiskFlag': None,
-            'hourlyBillingFlag': True,
-            'supplementalCreateObjectOptions': {
-                'bootMode': None,
-                'flavorKeyName': 'B1_2X8X25'
-            },
-            'operatingSystemReferenceCode': 'UBUNTU_LATEST',
-            'datacenter': {
-                'name': 'TEST00'
-            }
-        },
-        )
+                    'startCpus': None,
+                    'maxMemory': None,
+                    'hostname': 'TEST',
+                    'domain': 'TESTING',
+                    'localDiskFlag': None,
+                    'hourlyBillingFlag': True,
+                    'supplementalCreateObjectOptions': {
+                        'bootMode': None,
+                        'flavorKeyName': 'B1_2X8X25'
+                    },
+                    'operatingSystemReferenceCode': 'UBUNTU_LATEST',
+                    'datacenter': {
+                        'name': 'TEST00'
+                    }
+                },)
         self.assert_called_with('SoftLayer_Virtual_Guest', 'generateOrderTemplate', args=args)
         self.assertEqual([], self.calls('SoftLayer_Virtual_Guest', 'setTags'))
 
@@ -693,7 +692,7 @@ def test_create_vs_no_confirm(self, confirm_mock):
         self.assertEqual(result.exit_code, 2)
 
     def test_create_vs_export(self):
-        if(sys.platform.startswith("win")):
+        if (sys.platform.startswith("win")):
             self.skipTest("Test doesn't work in Windows")
         with tempfile.NamedTemporaryFile() as config_file:
             result = self.run_command(['vs', 'create', '--hostname', 'TEST', '--export', config_file.name,
diff --git a/tests/managers/ordering_tests.py b/tests/managers/ordering_tests.py
index 063dbcdd..e38b137f 100644
--- a/tests/managers/ordering_tests.py
+++ b/tests/managers/ordering_tests.py
@@ -901,3 +901,7 @@ def test_get_items(self):
     def test_get_regions(self):
         self.ordering.get_regions(123)
         self.assert_called_with('SoftLayer_Product_Package', 'getRegions')
+
+    def test_delete_quote(self):
+        self.ordering.delete_quote(123)
+        self.assert_called_with('SoftLayer_Billing_Order_Quote', 'deleteQuote')