Skip to content

Commit c1e5501

Browse files
Merge pull request #1331 from caberos/issue1324
implement unit test to classes not pass the coverage
2 parents c59be99 + 4450dbc commit c1e5501

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
@@ -394,7 +394,8 @@
394394

395395
getSecurityCertificates = [{'certificate': '1234',
396396
'commonName': 'cert',
397-
'id': 1234}]
397+
'id': 1234,
398+
'validityDays': 0, }]
398399
getExpiredSecurityCertificates = getSecurityCertificates
399400
getValidSecurityCertificates = getSecurityCertificates
400401

@@ -487,6 +488,7 @@
487488
'networkSpace': 'PRIVATE',
488489
'hardwareCount': 0,
489490
'hardware': [],
491+
'vlanNumber': 12,
490492
'networkComponents': [],
491493
'primaryRouter': {
492494
'datacenter': {'name': 'dal00'}
@@ -499,13 +501,26 @@
499501
'totalPrimaryIpAddressCount': 1,
500502
'subnetCount': 0,
501503
'subnets': [],
504+
'firewallInterfaces': [
505+
{
506+
'id': 1,
507+
'name': 'outside'
508+
},
509+
{
510+
'id': 12,
511+
'name': 'inside'
512+
}
513+
]
502514
}, {
503515
'id': 2,
504516
'networkSpace': 'PRIVATE',
505517
'totalPrimaryIpAddressCount': 2,
506518
'dedicatedFirewallFlag': False,
519+
'highAvailabilityFirewallFlag': True,
520+
'networkVlanFirewall': {'id': 7896},
507521
'hardwareCount': 0,
508522
'hardware': [],
523+
'vlanNumber': 13,
509524
'networkComponents': [],
510525
'primaryRouter': {
511526
'datacenter': {'name': 'dal00'}
@@ -520,18 +535,29 @@
520535
'id': 1234,
521536
'networkComponent': {'downlinkComponent': {'hardwareId': 1}},
522537
'status': 'ok'}],
538+
'firewallInterfaces': [],
539+
523540
'subnetCount': 0,
524541
'subnets': [],
525542
}, {
526543
'id': 3,
527544
'networkSpace': 'PRIVATE',
528545
'name': 'dal00',
529546
'hardwareCount': 1,
547+
'dedicatedFirewallFlag': True,
548+
'highAvailabilityFirewallFlag': True,
549+
'networkVlanFirewall': {'id': 23456},
550+
'vlanNumber': 14,
530551
'hardware': [{'id': 1}],
531552
'networkComponents': [{'id': 2}],
532553
'primaryRouter': {
533554
'datacenter': {'name': 'dal00'}
534555
},
556+
'firewallInterfaces': [
557+
{
558+
'id': 31,
559+
'name': 'outside'
560+
}],
535561
'totalPrimaryIpAddressCount': 3,
536562
'subnetCount': 0,
537563
'subnets': [],
@@ -659,7 +685,6 @@
659685
'id': 12345
660686
}]
661687

662-
663688
getUsers = [
664689
{'displayName': 'ChristopherG',
665690
'hardwareCount': 138,
@@ -739,7 +764,6 @@
739764
}
740765
]
741766

742-
743767
getPlacementGroups = [{
744768
"createDate": "2019-01-18T16:08:44-06:00",
745769
"id": 12345,
@@ -890,7 +914,6 @@
890914
}
891915
]
892916

893-
894917
getPortableStorageVolumes = [
895918
{
896919
"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+
"MIIC1jCCAb4CAQAwgZAxCzAJBgNVBAYTAlVTMQ4wDAYDVQQIDAVUZXhh123456QMA4G\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-----\nMIIEpAIBAAKCAQEA3SwTZ7sh7we5zIbmtSbxGJxff07eutrK12345678WXtwQSdE\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)