Skip to content

Commit f0f5a21

Browse files
author
caberos
committed
implement unit test to classes not pass the coverage
1 parent a3ad28b commit f0f5a21

12 files changed

+251
-10
lines changed

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@
397397

398398
getSecurityCertificates = [{'certificate': '1234',
399399
'commonName': 'cert',
400-
'id': 1234}]
400+
'id': 1234,
401+
'validityDays': 0, }]
401402
getExpiredSecurityCertificates = getSecurityCertificates
402403
getValidSecurityCertificates = getSecurityCertificates
403404

@@ -490,6 +491,7 @@
490491
'networkSpace': 'PRIVATE',
491492
'hardwareCount': 0,
492493
'hardware': [],
494+
'vlanNumber': 12,
493495
'networkComponents': [],
494496
'primaryRouter': {
495497
'datacenter': {'name': 'dal00'}
@@ -502,13 +504,26 @@
502504
'totalPrimaryIpAddressCount': 1,
503505
'subnetCount': 0,
504506
'subnets': [],
507+
'firewallInterfaces': [
508+
{
509+
'id': 1,
510+
'name': 'outside'
511+
},
512+
{
513+
'id': 12,
514+
'name': 'inside'
515+
}
516+
]
505517
}, {
506518
'id': 2,
507519
'networkSpace': 'PRIVATE',
508520
'totalPrimaryIpAddressCount': 2,
509521
'dedicatedFirewallFlag': False,
522+
'highAvailabilityFirewallFlag': True,
523+
'networkVlanFirewall': {'id': 7896},
510524
'hardwareCount': 0,
511525
'hardware': [],
526+
'vlanNumber': 13,
512527
'networkComponents': [],
513528
'primaryRouter': {
514529
'datacenter': {'name': 'dal00'}
@@ -523,18 +538,29 @@
523538
'id': 1234,
524539
'networkComponent': {'downlinkComponent': {'hardwareId': 1}},
525540
'status': 'ok'}],
541+
'firewallInterfaces': [],
542+
526543
'subnetCount': 0,
527544
'subnets': [],
528545
}, {
529546
'id': 3,
530547
'networkSpace': 'PRIVATE',
531548
'name': 'dal00',
532549
'hardwareCount': 1,
550+
'dedicatedFirewallFlag': True,
551+
'highAvailabilityFirewallFlag': True,
552+
'networkVlanFirewall': {'id': 23456},
553+
'vlanNumber': 14,
533554
'hardware': [{'id': 1}],
534555
'networkComponents': [{'id': 2}],
535556
'primaryRouter': {
536557
'datacenter': {'name': 'dal00'}
537558
},
559+
'firewallInterfaces': [
560+
{
561+
'id': 31,
562+
'name': 'outside'
563+
}],
538564
'totalPrimaryIpAddressCount': 3,
539565
'subnetCount': 0,
540566
'subnets': [],
@@ -662,7 +688,6 @@
662688
'id': 12345
663689
}]
664690

665-
666691
getUsers = [
667692
{'displayName': 'ChristopherG',
668693
'hardwareCount': 138,
@@ -742,7 +767,6 @@
742767
}
743768
]
744769

745-
746770
getPlacementGroups = [{
747771
"createDate": "2019-01-18T16:08:44-06:00",
748772
"id": 12345,
@@ -893,7 +917,6 @@
893917
}
894918
]
895919

896-
897920
getPortableStorageVolumes = [
898921
{
899922
"capacity": 200,

SoftLayer/fixtures/SoftLayer_Network_Subnet.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@
4343

4444
editNote = True
4545
setTags = True
46+
cancel = True

SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66
'isNetwork': False,
77
'isReserved': False,
88
'subnetId': 5678,
9+
"hardware": {
10+
"id": 12856,
11+
"fullyQualifiedDomainName": "unit.test.com"
12+
},
13+
"subnet": {
14+
"broadcastAddress": "10.0.1.91",
15+
"cidr": 26,
16+
"gateway": "10.47.16.129",
17+
"id": 258369,
18+
"isCustomerOwned": False,
19+
"isCustomerRoutable": False,
20+
"modifyDate": "2019-04-02T13:45:52-06:00",
21+
"netmask": "255.255.255.192",
22+
"networkIdentifier": "10.0.1.38",
23+
"networkVlanId": 1236987,
24+
"sortOrder": "0",
25+
"subnetType": "PRIMARY",
26+
"totalIpAddresses": "64",
27+
"usableIpAddressCount": "61",
28+
"version": 4
29+
}
930
}
1031

1132
editObject = True

SoftLayer/fixtures/SoftLayer_Network_Vlan.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010

1111
editObject = True
1212
setTags = True
13+
getList = [getObject]

SoftLayer/fixtures/SoftLayer_Network_Vlan_Firewall.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,45 @@
4141
]
4242
}
4343
]
44-
}
44+
},
45+
"rules": [
46+
{'destinationIpAddress': 'any on server',
47+
'protocol': 'tcp',
48+
'orderValue': 1,
49+
'destinationIpSubnetMask': '255.255.255.255',
50+
'destinationPortRangeStart': 80,
51+
'sourceIpSubnetMask': '0.0.0.0',
52+
'destinationPortRangeEnd': 80,
53+
'version': 4,
54+
'action': 'permit',
55+
'sourceIpAddress': '0.0.0.0'
56+
},
57+
{
58+
'destinationIpAddress': 'any on server',
59+
'protocol': 'tcp',
60+
'orderValue': 2,
61+
'destinationIpSubnetMask': '255.255.255.255',
62+
'destinationPortRangeStart': 1,
63+
'sourceIpSubnetMask': '255.255.255.255',
64+
'destinationPortRangeEnd': 65535,
65+
'version': 4,
66+
'action': 'permit',
67+
'sourceIpAddress': '193.212.1.10'
68+
},
69+
{
70+
'destinationIpAddress': 'any on server',
71+
'protocol': 'tcp',
72+
'orderValue': 3,
73+
'destinationIpSubnetMask': '255.255.255.255',
74+
'destinationPortRangeStart': 80,
75+
'sourceIpSubnetMask': '0.0.0.0',
76+
'destinationPortRangeEnd': 800,
77+
'version': 4,
78+
'action': 'permit',
79+
'sourceIpAddress': '0.0.0.0'
80+
}
81+
]
82+
4583
}
4684

4785
getRules = [
@@ -59,7 +97,7 @@
5997
},
6098
{
6199
'destinationIpAddress': 'any on server',
62-
'protocol': 'tcp',
100+
'protocol': 'tmp',
63101
'orderValue': 2,
64102
'destinationIpSubnetMask': '255.255.255.255',
65103
'destinationPortRangeStart': 1,
@@ -82,3 +120,4 @@
82120
'sourceIpAddress': '0.0.0.0'
83121
}
84122
]
123+
edit = True
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1-
getObject = {}
1+
getObject = {
2+
"certificate": "-----BEGIN CERTIFICATE----- \nMIIEJTCCAw2gAwIBAgIDCbQ0MA0GCSqGSIb3DQEBCwUAMEcxCzAJBgNVBAYTAlVT"
3+
" -----END CERTIFICATE-----",
4+
"certificateSigningRequest": "-----BEGIN CERTIFICATE REQUEST-----\n"
5+
"MIIC1jCCAb4CAQAwgZAxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVUZXhhczEQMA4G\n"
6+
"-----END CERTIFICATE REQUEST-----",
7+
"commonName": "techbabble.xyz",
8+
"createDate": "2016-01-20T10:56:44-06:00",
9+
"id": 123456,
10+
"intermediateCertificate": "",
11+
"keySize": 258369,
12+
"modifyDate": "2019-06-05T14:10:40-06:00",
13+
"organizationName": "Unspecified",
14+
"privateKey": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEA3SwTZ7sh7we5zIbmtSbxGJxf67Ayf07eutrK8OAjWXtwQSdE\n"
15+
"-----END RSA PRIVATE KEY-----",
16+
"validityBegin": "2016-01-19T17:59:37-06:00",
17+
"validityDays": 0,
18+
"validityEnd": "2017-01-20T13:48:41-06:00"
19+
}
220
createObject = {}
321
editObject = True
422
deleteObject = True

tests/CLI/modules/firewall_tests.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ def test_list_firewalls(self):
1717

1818
self.assert_no_fail(result)
1919
self.assertEqual(json.loads(result.output),
20-
[{'type': 'VLAN - dedicated',
20+
[{'features': ['HA'],
21+
'firewall id': 'vlan:1234',
2122
'server/vlan id': 1,
22-
'features': ['HA'],
23-
'firewall id': 'vlan:1234'},
23+
'type': 'VLAN - dedicated'},
24+
{'features': ['HA'],
25+
'firewall id': 'vlan:23456',
26+
'server/vlan id': 3,
27+
'type': 'VLAN - dedicated'},
2428
{'features': '-',
2529
'firewall id': 'vs:1234',
2630
'server/vlan id': 1,
@@ -50,3 +54,42 @@ def test_add_server(self, confirm_mock):
5054
result = self.run_command(['firewall', 'add', '1000', '--firewall-type=server'])
5155
self.assert_no_fail(result)
5256
self.assertIn("Firewall is being created!", result.output)
57+
58+
def test_detail(self):
59+
result = self.run_command(['firewall', 'detail', 'vlan:1234'])
60+
self.assert_no_fail(result)
61+
self.assertEqual(json.loads(result.output),
62+
[{'#': 1,
63+
'action': 'permit',
64+
'dest': 'any on server:80-80',
65+
'dest_mask': '255.255.255.255',
66+
'protocol': 'tcp',
67+
'src_ip': '0.0.0.0',
68+
'src_mask': '0.0.0.0'},
69+
{'#': 2,
70+
'action': 'permit',
71+
'dest': 'any on server:1-65535',
72+
'dest_mask': '255.255.255.255',
73+
'protocol': 'tmp',
74+
'src_ip': '193.212.1.10',
75+
'src_mask': '255.255.255.255'},
76+
{'#': 3,
77+
'action': 'permit',
78+
'dest': 'any on server:80-800',
79+
'dest_mask': '255.255.255.255',
80+
'protocol': 'tcp',
81+
'src_ip': '0.0.0.0',
82+
'src_mask': '0.0.0.0'}])
83+
84+
@mock.patch('SoftLayer.CLI.formatting.confirm')
85+
def test_cancel_firewall(self, confirm_mock):
86+
confirm_mock.return_value = True
87+
result = self.run_command(['firewall', 'cancel', 'vlan:1234'])
88+
self.assert_no_fail(result)
89+
self.assertIn("Firewall with id vlan:1234 is being cancelled!", result.output)
90+
91+
@mock.patch('SoftLayer.CLI.formatting.confirm')
92+
def test_edit(self, confirm_mock):
93+
confirm_mock.return_value = True
94+
result = self.run_command(['firewall', 'edit', 'vlan:1234'])
95+
print(result.output)

tests/CLI/modules/globalip_tests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,22 @@ def test_ip_list(self):
6666
'id': '201',
6767
'ip': '127.0.0.1',
6868
'target': '127.0.0.1 (example.com)'}])
69+
70+
@mock.patch('SoftLayer.CLI.formatting.confirm')
71+
def test_create(self, confirm_mock):
72+
confirm_mock.return_value = True
73+
result = self.run_command(['globalip', 'create', '-v6'])
74+
self.assert_no_fail(result)
75+
self.assertEqual(json.loads(result.output), [{
76+
"item": "this is a thing",
77+
"cost": "2.00"
78+
},
79+
{
80+
"item": "Total monthly cost",
81+
"cost": "2.00"
82+
}])
83+
84+
def test_ip_unassign(self):
85+
result = self.run_command(['globalip', 'unassign', '1'])
86+
self.assert_no_fail(result)
87+
self.assertEqual(result.output, "")

tests/CLI/modules/ssl_tests.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""
2+
SoftLayer.tests.CLI.modules.ssl_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
from SoftLayer import testing
8+
9+
import json
10+
import mock
11+
12+
13+
class SslTests(testing.TestCase):
14+
def test_list(self):
15+
result = self.run_command(['ssl', 'list', '--status', 'all'])
16+
self.assert_no_fail(result)
17+
self.assertEqual(json.loads(result.output), [
18+
{
19+
"id": 1234,
20+
"common_name": "cert",
21+
"days_until_expire": 0,
22+
"notes": None
23+
}
24+
])
25+
26+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
27+
def test_remove(self, confirm_mock):
28+
confirm_mock.return_value = True
29+
result = self.run_command(['ssl', 'remove', '123456'])
30+
self.assert_no_fail(result)
31+
self.assertEqual(result.exit_code, 0)
32+
33+
def test_download(self):
34+
result = self.run_command(['ssl', 'download', '123456'])
35+
self.assert_no_fail(result)
36+
self.assertEqual(result.exit_code, 0)

tests/CLI/modules/subnet_tests.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,30 @@ def test_editrou_Id(self):
157157
result = self.run_command(['subnet', 'edit-ip', '123456', '--note=test'])
158158
self.assert_no_fail(result)
159159
self.assertTrue(result)
160+
161+
def test_lookup(self):
162+
result = self.run_command(['subnet', 'lookup', '1.2.3.10'])
163+
self.assert_no_fail(result)
164+
self.assertEqual(json.loads(result.output), {'device': {
165+
'id': 12856,
166+
'name': 'unit.test.com',
167+
'type': 'server'},
168+
"id": 12345,
169+
"ip": "10.0.1.37",
170+
"subnet": {
171+
"id": 258369,
172+
"identifier": "10.0.1.38/26",
173+
"netmask": "255.255.255.192",
174+
"gateway": "10.47.16.129",
175+
"type": "PRIMARY"
176+
}})
177+
178+
@mock.patch('SoftLayer.CLI.formatting.no_going_back')
179+
def test_cancel(self, confirm_mock):
180+
confirm_mock.return_value = True
181+
result = self.run_command(['subnet', 'cancel', '1234'])
182+
self.assert_no_fail(result)
183+
184+
def test_cancel_fail(self):
185+
result = self.run_command(['subnet', 'cancel', '1234'])
186+
self.assertEqual(result.exit_code, 2)

0 commit comments

Comments
 (0)