From 00cc11f4dc2baedd632f039288b501071628e97a Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 18 Aug 2020 09:56:57 -0400 Subject: [PATCH 1/3] fix the ha option firewall add and implement unit test --- SoftLayer/CLI/firewall/add.py | 2 +- .../fixtures/SoftLayer_Product_Package.py | 22 +++++++++----- tests/CLI/modules/firewall_tests.py | 29 +++++++++++++++++++ 3 files changed, 44 insertions(+), 9 deletions(-) diff --git a/SoftLayer/CLI/firewall/add.py b/SoftLayer/CLI/firewall/add.py index 5eba9b778..12c7abef3 100644 --- a/SoftLayer/CLI/firewall/add.py +++ b/SoftLayer/CLI/firewall/add.py @@ -15,7 +15,7 @@ type=click.Choice(['vs', 'vlan', 'server']), help='Firewall type', required=True) -@click.option('--ha', '--high-availability', +@click.option('-ha', '--high-availability', is_flag=True, help='High available firewall option') @environment.pass_env diff --git a/SoftLayer/fixtures/SoftLayer_Product_Package.py b/SoftLayer/fixtures/SoftLayer_Product_Package.py index b131f8916..07aefab69 100644 --- a/SoftLayer/fixtures/SoftLayer_Product_Package.py +++ b/SoftLayer/fixtures/SoftLayer_Product_Package.py @@ -833,6 +833,7 @@ 'itemCategory': {'categoryCode': 'Uplink Port Speeds'}, 'prices': [{'id': 1122, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 26, 'name': 'Uplink Port Speeds', 'categoryCode': 'port_speed'}]}], @@ -845,6 +846,7 @@ 'itemCategory': {'categoryCode': 'Uplink Port Speeds'}, 'prices': [{'id': 4477, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 26, 'name': 'Uplink Port Speeds', 'categoryCode': 'port_speed'}]}], @@ -857,6 +859,7 @@ 'itemCategory': {'categoryCode': 'RAM'}, 'prices': [{'id': 1133, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 3, 'name': 'RAM', 'categoryCode': 'ram'}]}], @@ -870,6 +873,7 @@ 'itemCategory': {'categoryCode': 'Computing Instance'}, 'prices': [{'id': 1007, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 80, 'name': 'Computing Instance', 'categoryCode': 'guest_core'}]}], @@ -884,6 +888,7 @@ 'prices': [{'id': 1144, 'locationGroupId': None, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 80, 'name': 'Computing Instance', 'categoryCode': 'guest_core'}]}], @@ -898,6 +903,7 @@ 'prices': [{'id': 332211, 'locationGroupId': 1, 'hourlyRecurringFee': 0.0, + 'recurringFee': 0.0, 'categories': [{'id': 80, 'name': 'Computing Instance', 'categoryCode': 'guest_core'}]}], @@ -908,7 +914,7 @@ 'capacity': '1', 'description': '1 GB iSCSI Storage', 'itemCategory': {'categoryCode': 'iscsi'}, - 'prices': [{'id': 2222, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 2222, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 1121, @@ -924,7 +930,7 @@ 'capacity': '4', 'description': '4 Portable Public IP Addresses', 'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'}, - 'prices': [{'id': 4444, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 4444, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 8880, @@ -932,7 +938,7 @@ 'capacity': '8', 'description': '8 Portable Public IP Addresses', 'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_pub'}, - 'prices': [{'id': 8888, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 8888, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 44400, @@ -940,7 +946,7 @@ 'capacity': '4', 'description': '4 Portable Private IP Addresses', 'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_priv'}, - 'prices': [{'id': 44441, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 44441, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 88800, @@ -948,7 +954,7 @@ 'capacity': '8', 'description': '8 Portable Private IP Addresses', 'itemCategory': {'categoryCode': 'sov_sec_ip_addresses_priv'}, - 'prices': [{'id': 88881, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 88881, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 10, @@ -956,7 +962,7 @@ 'capacity': '0', 'description': 'Global IPv4', 'itemCategory': {'categoryCode': 'global_ipv4'}, - 'prices': [{'id': 11, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 11, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 66464, @@ -964,7 +970,7 @@ 'capacity': '64', 'description': '/64 Block Portable Public IPv6 Addresses', 'itemCategory': {'categoryCode': 'static_ipv6_addresses'}, - 'prices': [{'id': 664641, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 664641, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }, { 'id': 610, @@ -972,7 +978,7 @@ 'capacity': '0', 'description': 'Global IPv6', 'itemCategory': {'categoryCode': 'global_ipv6'}, - 'prices': [{'id': 611, 'hourlyRecurringFee': 0.0}], + 'prices': [{'id': 611, 'hourlyRecurringFee': 0.0, 'recurringFee': 0.0}], }] getItemPricesISCSI = [ diff --git a/tests/CLI/modules/firewall_tests.py b/tests/CLI/modules/firewall_tests.py index f83022d7e..270619b2f 100644 --- a/tests/CLI/modules/firewall_tests.py +++ b/tests/CLI/modules/firewall_tests.py @@ -5,6 +5,9 @@ :license: MIT, see LICENSE for more details. """ import json +from unittest import mock + +from SoftLayer.CLI import exceptions from SoftLayer import testing @@ -28,3 +31,29 @@ def test_list_firewalls(self): 'firewall id': 'server:1234', 'server/vlan id': 1, 'type': 'Server - standard'}]) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_add_vs(self, confirm_mock): + confirm_mock.return_value = True + result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vlan', '-ha']) + self.assert_no_fail(result) + self.assertIn("Firewall is being created!", result.output) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_add_vlan(self, confirm_mock): + confirm_mock.return_value = True + result = self.run_command(['firewall', 'add', '1000', '--firewall-type=vs']) + self.assert_no_fail(result) + self.assertIn("Firewall is being created!", result.output) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_add_server(self, confirm_mock): + confirm_mock.return_value = True + result = self.run_command(['firewall', 'add', '1000', '--firewall-type=server']) + self.assert_no_fail(result) + self.assertIn("Firewall is being created!", result.output) + + def test_add_server_fail(self): + result = self.run_command(['firewall', 'add', '1000', '--firewall-type=server']) + self.assertEqual(result.exit_code, 2) + self.assertIsInstance(result.exception, exceptions.CLIAbort) From 8a6cf5e8166e08c769adf962c39a55ac0436c3a4 Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 18 Aug 2020 10:19:05 -0400 Subject: [PATCH 2/3] fix tox tool --- tests/CLI/modules/firewall_tests.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/CLI/modules/firewall_tests.py b/tests/CLI/modules/firewall_tests.py index 270619b2f..a90038065 100644 --- a/tests/CLI/modules/firewall_tests.py +++ b/tests/CLI/modules/firewall_tests.py @@ -52,8 +52,3 @@ def test_add_server(self, confirm_mock): result = self.run_command(['firewall', 'add', '1000', '--firewall-type=server']) self.assert_no_fail(result) self.assertIn("Firewall is being created!", result.output) - - def test_add_server_fail(self): - result = self.run_command(['firewall', 'add', '1000', '--firewall-type=server']) - self.assertEqual(result.exit_code, 2) - self.assertIsInstance(result.exception, exceptions.CLIAbort) From fa8c48357225778e4f93a7c1363bb074b03b0d9f Mon Sep 17 00:00:00 2001 From: caberos Date: Tue, 18 Aug 2020 10:26:12 -0400 Subject: [PATCH 3/3] fix tox tool --- tests/CLI/modules/firewall_tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/CLI/modules/firewall_tests.py b/tests/CLI/modules/firewall_tests.py index a90038065..b3ac8c0b2 100644 --- a/tests/CLI/modules/firewall_tests.py +++ b/tests/CLI/modules/firewall_tests.py @@ -7,8 +7,6 @@ import json from unittest import mock -from SoftLayer.CLI import exceptions - from SoftLayer import testing