From ec04e850fb19314f453b4e7da98b4f6793805702 Mon Sep 17 00:00:00 2001 From: Khuong-Nguyen Date: Wed, 3 Oct 2018 15:34:07 -0500 Subject: [PATCH 1/2] Fix unit tests --- SoftLayer/fixtures/SoftLayer_Account.py | 4 +- .../SoftLayer_Virtual_DedicatedHost.py | 38 +++--- tests/CLI/modules/dedicatedhost_tests.py | 119 ++++++++---------- tests/managers/dedicated_host_tests.py | 58 ++++----- 4 files changed, 99 insertions(+), 120 deletions(-) diff --git a/SoftLayer/fixtures/SoftLayer_Account.py b/SoftLayer/fixtures/SoftLayer_Account.py index 586e597a9..f588417ad 100644 --- a/SoftLayer/fixtures/SoftLayer_Account.py +++ b/SoftLayer/fixtures/SoftLayer_Account.py @@ -553,11 +553,11 @@ 'name': 'dal05' }, 'memoryCapacity': 242, - 'name': 'khnguyendh', + 'name': 'test-dedicated', 'diskCapacity': 1200, 'guestCount': 1, 'cpuCount': 56, - 'id': 44701 + 'id': 12345 }] diff --git a/SoftLayer/fixtures/SoftLayer_Virtual_DedicatedHost.py b/SoftLayer/fixtures/SoftLayer_Virtual_DedicatedHost.py index ea1775eb9..94c8e5cc4 100644 --- a/SoftLayer/fixtures/SoftLayer_Virtual_DedicatedHost.py +++ b/SoftLayer/fixtures/SoftLayer_Virtual_DedicatedHost.py @@ -11,57 +11,57 @@ getAvailableRouters = [ - {'hostname': 'bcr01a.dal05', 'id': 51218}, - {'hostname': 'bcr02a.dal05', 'id': 83361}, - {'hostname': 'bcr03a.dal05', 'id': 122762}, - {'hostname': 'bcr04a.dal05', 'id': 147566} + {'hostname': 'bcr01a.dal05', 'id': 12345}, + {'hostname': 'bcr02a.dal05', 'id': 12346}, + {'hostname': 'bcr03a.dal05', 'id': 12347}, + {'hostname': 'bcr04a.dal05', 'id': 12348} ] getObjectById = { 'datacenter': { - 'id': 138124, + 'id': 12345, 'name': 'dal05', 'longName': 'Dallas 5' }, 'memoryCapacity': 242, 'modifyDate': '2017-11-06T11:38:20-06:00', - 'name': 'khnguyendh', + 'name': 'test-dedicated', 'diskCapacity': 1200, 'backendRouter': { - 'domain': 'softlayer.com', + 'domain': 'test.com', 'hostname': 'bcr01a.dal05', - 'id': 51218 + 'id': 12345 }, 'guestCount': 1, 'cpuCount': 56, 'guests': [{ - 'domain': 'Softlayer.com', - 'hostname': 'khnguyenDHI', - 'id': 43546081, - 'uuid': '806a56ec-0383-4c2e-e6a9-7dc89c4b29a2' + 'domain': 'test.com', + 'hostname': 'test-dedicated', + 'id': 12345, + 'uuid': 'F9329795-4220-4B0A-B970-C86B950667FA' }], 'billingItem': { 'nextInvoiceTotalRecurringAmount': 1515.556, 'orderItem': { - 'id': 263060473, + 'id': 12345, 'order': { 'status': 'APPROVED', 'privateCloudOrderFlag': False, 'modifyDate': '2017-11-02T11:42:50-07:00', 'orderQuoteId': '', - 'userRecordId': 6908745, + 'userRecordId': 12345, 'createDate': '2017-11-02T11:40:56-07:00', 'impersonatingUserRecordId': '', 'orderTypeId': 7, 'presaleEventId': '', 'userRecord': { - 'username': '232298_khuong' + 'username': 'test-dedicated' }, - 'id': 20093269, - 'accountId': 232298 + 'id': 12345, + 'accountId': 12345 } }, - 'id': 235379377, + 'id': 12345, 'children': [ { 'nextInvoiceTotalRecurringAmount': 0.0, @@ -73,6 +73,6 @@ } ] }, - 'id': 44701, + 'id': 12345, 'createDate': '2017-11-02T11:40:56-07:00' } diff --git a/tests/CLI/modules/dedicatedhost_tests.py b/tests/CLI/modules/dedicatedhost_tests.py index 59f6cab7c..3cc675749 100644 --- a/tests/CLI/modules/dedicatedhost_tests.py +++ b/tests/CLI/modules/dedicatedhost_tests.py @@ -29,21 +29,17 @@ def test_list_dedicated_hosts(self): 'datacenter': 'dal05', 'diskCapacity': 1200, 'guestCount': 1, - 'id': 44701, + 'id': 12345, 'memoryCapacity': 242, - 'name': 'khnguyendh' + 'name': 'test-dedicated' }] ) - def tear_down(self): - if os.path.exists("test.txt"): - os.remove("test.txt") - def test_details(self): mock = self.set_mock('SoftLayer_Virtual_DedicatedHost', 'getObject') mock.return_value = SoftLayer_Virtual_DedicatedHost.getObjectById - result = self.run_command(['dedicatedhost', 'detail', '44701', '--price', '--guests']) + result = self.run_command(['dedicatedhost', 'detail', '12345', '--price', '--guests']) self.assert_no_fail(result) self.assertEqual(json.loads(result.output), @@ -54,19 +50,19 @@ def test_details(self): 'disk capacity': 1200, 'guest count': 1, 'guests': [{ - 'domain': 'Softlayer.com', - 'hostname': 'khnguyenDHI', - 'id': 43546081, - 'uuid': '806a56ec-0383-4c2e-e6a9-7dc89c4b29a2' + 'domain': 'test.com', + 'hostname': 'test-dedicated', + 'id': 12345, + 'uuid': 'F9329795-4220-4B0A-B970-C86B950667FA' }], - 'id': 44701, + 'id': 12345, 'memory capacity': 242, 'modify date': '2017-11-06T11:38:20-06:00', - 'name': 'khnguyendh', - 'owner': '232298_khuong', + 'name': 'test-dedicated', + 'owner': 'test-dedicated', 'price_rate': 1515.556, 'router hostname': 'bcr01a.dal05', - 'router id': 51218} + 'router id': 12345} ) def test_details_no_owner(self): @@ -85,18 +81,18 @@ def test_details_no_owner(self): 'disk capacity': 1200, 'guest count': 1, 'guests': [{ - 'domain': 'Softlayer.com', - 'hostname': 'khnguyenDHI', - 'id': 43546081, - 'uuid': '806a56ec-0383-4c2e-e6a9-7dc89c4b29a2'}], - 'id': 44701, + 'domain': 'test.com', + 'hostname': 'test-dedicated', + 'id': 12345, + 'uuid': 'F9329795-4220-4B0A-B970-C86B950667FA'}], + 'id': 12345, 'memory capacity': 242, 'modify date': '2017-11-06T11:38:20-06:00', - 'name': 'khnguyendh', + 'name': 'test-dedicated', 'owner': None, 'price_rate': 0, 'router hostname': 'bcr01a.dal05', - 'router id': 51218} + 'router id': 12345} ) def test_create_options(self): @@ -159,29 +155,29 @@ def test_create(self): mock_package_obj.return_value = SoftLayer_Product_Package.getAllObjectsDH result = self.run_command(['dedicatedhost', 'create', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_242_RAM_X_1_4_TB', '--billing=hourly']) self.assert_no_fail(result) args = ({ 'hardware': [{ - 'domain': 'example.com', + 'domain': 'test.com', 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, - 'hostname': 'host' - }], - 'prices': [{ - 'id': 200269 + 'hostname': 'test-dedicated' }], + 'useHourlyPricing': True, 'location': 'DALLAS05', 'packageId': 813, 'complexType': 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', - 'useHourlyPricing': True, + 'prices': [{ + 'id': 200269 + }], 'quantity': 1},) self.assert_called_with('SoftLayer_Product_Order', 'placeOrder', @@ -195,21 +191,21 @@ def test_create_with_gpu(self): mock_package_obj.return_value = SoftLayer_Product_Package.getAllObjectsDHGpu result = self.run_command(['dedicatedhost', 'create', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_484_RAM_X_1_5_TB_X_2_GPU_P100', '--billing=hourly']) self.assert_no_fail(result) args = ({ 'hardware': [{ - 'domain': 'example.com', + 'domain': 'test.com', 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, - 'hostname': 'host' + 'hostname': 'test-dedicated' }], 'prices': [{ 'id': 200269 @@ -233,8 +229,8 @@ def test_create_verify(self): result = self.run_command(['dedicatedhost', 'create', '--verify', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_242_RAM_X_1_4_TB', '--billing=hourly']) @@ -244,12 +240,12 @@ def test_create_verify(self): 'useHourlyPricing': True, 'hardware': [{ - 'hostname': 'host', - 'domain': 'example.com', + 'hostname': 'test-dedicated', + 'domain': 'test.com', 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } } }], @@ -263,8 +259,8 @@ def test_create_verify(self): result = self.run_command(['dh', 'create', '--verify', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_242_RAM_X_1_4_TB', '--billing=monthly']) @@ -273,11 +269,11 @@ def test_create_verify(self): args = ({ 'useHourlyPricing': True, 'hardware': [{ - 'hostname': 'host', - 'domain': 'example.com', + 'hostname': 'test-dedicated', + 'domain': 'test.com', 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } } }], @@ -296,8 +292,8 @@ def test_create_aborted(self): mock_package_obj.return_value = SoftLayer_Product_Package.getAllObjectsDH result = self.run_command(['dh', 'create', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_242_RAM_X_1_4_TB', '--billing=monthly']) @@ -305,23 +301,6 @@ def test_create_aborted(self): self.assertEqual(result.exit_code, 2) self.assertIsInstance(result.exception, exceptions.CLIAbort) - def test_create_export(self): - mock_package_obj = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') - mock_package_obj.return_value = SoftLayer_Product_Package.getAllObjectsDH - mock_package = self.set_mock('SoftLayer_Product_Order', 'verifyOrder') - mock_package.return_value = SoftLayer_Product_Package.verifyOrderDH - - self.run_command(['dedicatedhost', 'create', - '--verify', - '--hostname=host', - '--domain=example.com', - '--datacenter=dal05', - '--flavor=56_CORES_X_242_RAM_X_1_4_TB', - '--billing=hourly', - '--export=test.txt']) - - self.assertEqual(os.path.exists("test.txt"), True) - def test_create_verify_no_price_or_more_than_one(self): mock_package_obj = self.set_mock('SoftLayer_Product_Package', 'getAllObjects') mock_package_obj.return_value = SoftLayer_Product_Package.getAllObjectsDH @@ -332,8 +311,8 @@ def test_create_verify_no_price_or_more_than_one(self): result = self.run_command(['dedicatedhost', 'create', '--verify', - '--hostname=host', - '--domain=example.com', + '--hostname=test-dedicated', + '--domain=test.com', '--datacenter=dal05', '--flavor=56_CORES_X_242_RAM_X_1_4_TB', '--billing=hourly']) @@ -341,13 +320,13 @@ def test_create_verify_no_price_or_more_than_one(self): self.assertIsInstance(result.exception, exceptions.ArgumentError) args = ({ 'hardware': [{ - 'domain': 'example.com', + 'domain': 'test.com', 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, - 'hostname': 'host' + 'hostname': 'test-dedicated' }], 'prices': [{ 'id': 200269 diff --git a/tests/managers/dedicated_host_tests.py b/tests/managers/dedicated_host_tests.py index 2f21edacf..bdfa6d3f6 100644 --- a/tests/managers/dedicated_host_tests.py +++ b/tests/managers/dedicated_host_tests.py @@ -90,7 +90,7 @@ def test_place_order(self): { 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, 'domain': u'test.com', @@ -103,7 +103,7 @@ def test_place_order(self): 'complexType': 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', 'prices': [ { - 'id': 200269 + 'id': 12345 } ], 'quantity': 1 @@ -141,7 +141,7 @@ def test_place_order_with_gpu(self): { 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, 'domain': u'test.com', @@ -154,7 +154,7 @@ def test_place_order_with_gpu(self): 'complexType': 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', 'prices': [ { - 'id': 200269 + 'id': 12345 } ], 'quantity': 1 @@ -192,7 +192,7 @@ def test_verify_order(self): { 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, 'domain': 'test.com', @@ -205,7 +205,7 @@ def test_verify_order(self): 'complexType': 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', 'prices': [ { - 'id': 200269 + 'id': 12345 } ], 'quantity': 1 @@ -259,7 +259,7 @@ def test_generate_create_dict_without_router(self): { 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, 'domain': 'test.com', @@ -272,7 +272,7 @@ def test_generate_create_dict_without_router(self): 'complexType': 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', 'prices': [ { - 'id': 200269 + 'id': 12345 } ], 'quantity': 1 @@ -284,10 +284,10 @@ def test_generate_create_dict_with_router(self): self.dedicated_host._get_package = mock.MagicMock() self.dedicated_host._get_package.return_value = self._get_package() self.dedicated_host._get_default_router = mock.Mock() - self.dedicated_host._get_default_router.return_value = 51218 + self.dedicated_host._get_default_router.return_value = 12345 location = 'dal05' - router = 51218 + router = 12345 hostname = 'test' domain = 'test.com' hourly = True @@ -306,7 +306,7 @@ def test_generate_create_dict_with_router(self): { 'primaryBackendNetworkComponent': { 'router': { - 'id': 51218 + 'id': 12345 } }, 'domain': 'test.com', @@ -320,7 +320,7 @@ def test_generate_create_dict_with_router(self): 'SoftLayer_Container_Product_Order_Virtual_DedicatedHost', 'prices': [ { - 'id': 200269 + 'id': 12345 } ], 'quantity': 1 @@ -421,7 +421,7 @@ def test_get_create_options(self): def test_get_price(self): package = self._get_package() item = package['items'][0] - price_id = 200269 + price_id = 12345 self.assertEqual(self.dedicated_host._get_price(item), price_id) @@ -454,15 +454,15 @@ def test_get_item(self): }], 'capacity': '56', 'description': '56 Cores X 242 RAM X 1.2 TB', - 'id': 10195, + 'id': 12345, 'itemCategory': { 'categoryCode': 'dedicated_virtual_hosts' }, 'keyName': '56_CORES_X_242_RAM_X_1_4_TB', 'prices': [{ 'hourlyRecurringFee': '3.164', - 'id': 200269, - 'itemId': 10195, + 'id': 12345, + 'itemId': 12345, 'recurringFee': '2099', }] } @@ -481,7 +481,7 @@ def test_get_backend_router(self): location = [ { 'isAvailable': 1, - 'locationId': 138124, + 'locationId': 12345, 'packageId': 813 } ] @@ -528,7 +528,7 @@ def test_get_backend_router_no_routers_found(self): def test_get_default_router(self): routers = self._get_routers_sample() - router = 51218 + router = 12345 router_test = self.dedicated_host._get_default_router(routers, 'bcr01a.dal05') @@ -544,19 +544,19 @@ def _get_routers_sample(self): routers = [ { 'hostname': 'bcr01a.dal05', - 'id': 51218 + 'id': 12345 }, { 'hostname': 'bcr02a.dal05', - 'id': 83361 + 'id': 12346 }, { 'hostname': 'bcr03a.dal05', - 'id': 122762 + 'id': 12347 }, { 'hostname': 'bcr04a.dal05', - 'id': 147566 + 'id': 12348 } ] @@ -590,14 +590,14 @@ def _get_package(self): ], "prices": [ { - "itemId": 10195, + "itemId": 12345, "recurringFee": "2099", "hourlyRecurringFee": "3.164", - "id": 200269, + "id": 12345, } ], "keyName": "56_CORES_X_242_RAM_X_1_4_TB", - "id": 10195, + "id": 12345, "itemCategory": { "categoryCode": "dedicated_virtual_hosts" }, @@ -608,12 +608,12 @@ def _get_package(self): "location": { "locationPackageDetails": [ { - "locationId": 265592, + "locationId": 12345, "packageId": 813 } ], "location": { - "id": 265592, + "id": 12345, "name": "ams01", "longName": "Amsterdam 1" } @@ -627,12 +627,12 @@ def _get_package(self): "locationPackageDetails": [ { "isAvailable": 1, - "locationId": 138124, + "locationId": 12345, "packageId": 813 } ], "location": { - "id": 138124, + "id": 12345, "name": "dal05", "longName": "Dallas 5" } From 363266b214f12db21001fad23c4cb03285570da9 Mon Sep 17 00:00:00 2001 From: Khuong-Nguyen Date: Wed, 3 Oct 2018 15:40:40 -0500 Subject: [PATCH 2/2] Removed unused import --- tests/CLI/modules/dedicatedhost_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/CLI/modules/dedicatedhost_tests.py b/tests/CLI/modules/dedicatedhost_tests.py index 3cc675749..82c694ff9 100644 --- a/tests/CLI/modules/dedicatedhost_tests.py +++ b/tests/CLI/modules/dedicatedhost_tests.py @@ -6,7 +6,6 @@ """ import json import mock -import os import SoftLayer from SoftLayer.CLI import exceptions