Skip to content

Commit 4815cdb

Browse files
#1026 unit tests
1 parent 53492ee commit 4815cdb

File tree

9 files changed

+186
-26
lines changed

9 files changed

+186
-26
lines changed

SoftLayer/CLI/columns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def mask(self):
5757
def get_formatter(columns):
5858
"""This function returns a callback to use with click options.
5959
60-
The retuend function parses a comma-separated value and returns a new
60+
The returend function parses a comma-separated value and returns a new
6161
ColumnFormatter.
6262
6363
:param columns: a list of Column instances

SoftLayer/CLI/virt/capacity/create.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
def cli(env, name, datacenter, backend_router_id, capacity, quantity, test=False):
3333
"""Create a Reserved Capacity instance. *WARNING*: Reserved Capacity is on a yearly contract and not cancelable until the contract is expired."""
3434
manager = CapacityManager(env.client)
35+
3536
result = manager.create(
3637
name=name,
3738
datacenter=datacenter,
@@ -40,12 +41,11 @@ def cli(env, name, datacenter, backend_router_id, capacity, quantity, test=False
4041
quantity=quantity,
4142
test=test)
4243

43-
pp(result)
4444
if test:
45-
table = formating.Table(['Name', 'Value'], "Test Order")
45+
table = formatting.Table(['Name', 'Value'], "Test Order")
4646
container = result['orderContainers'][0]
4747
table.add_row(['Name', container['name']])
48-
table.add_row(['Location'], container['locationObject']['longName'])
48+
table.add_row(['Location', container['locationObject']['longName']])
4949
for price in container['prices']:
5050
table.add_row([price['item']['keyName'], price['item']['description']])
5151
table.add_row(['Total', result['postTaxRecurring']])

SoftLayer/CLI/virt/capacity/detail.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,11 @@
1010
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
1111

1212
COLUMNS = [
13-
column_helper.Column('guid', ('globalIdentifier',)),
13+
column_helper.Column('Id', ('id',)),
14+
column_helper.Column('hostname', ('hostname',)),
15+
column_helper.Column('domain', ('domain',)),
1416
column_helper.Column('primary_ip', ('primaryIpAddress',)),
1517
column_helper.Column('backend_ip', ('primaryBackendIpAddress',)),
16-
column_helper.Column('datacenter', ('datacenter', 'name')),
17-
column_helper.Column('action', lambda guest: formatting.active_txn(guest),
18-
mask='''
19-
activeTransaction[
20-
id,transactionStatus[name,friendlyName]
21-
]'''),
22-
column_helper.Column('power_state', ('powerState', 'name')),
23-
column_helper.Column(
24-
'created_by',
25-
('billingItem', 'orderItem', 'order', 'userRecord', 'username')),
26-
column_helper.Column(
27-
'tags',
28-
lambda server: formatting.tags(server.get('tagReferences')),
29-
mask="tagReferences.tag.name"),
3018
]
3119

3220
DEFAULT_COLUMNS = [
@@ -48,6 +36,7 @@
4836
@environment.pass_env
4937
def cli(env, identifier, columns):
5038
"""Reserved Capacity Group details. Will show which guests are assigned to a reservation."""
39+
5140
manager = CapacityManager(env.client)
5241
mask = """mask[instances[id,createDate,guestId,billingItem[id, recurringFee, category[name]],
5342
guest[modifyDate,id, primaryBackendIpAddress, primaryIpAddress,domain, hostname]]]"""
@@ -60,6 +49,7 @@ def cli(env, identifier, columns):
6049
table = formatting.Table(columns.columns,
6150
title = "%s - %s" % (result.get('name'), flavor)
6251
)
52+
# RCI = Reserved Capacity Instance
6353
for rci in result['instances']:
6454
guest = rci.get('guest', None)
6555
guest_string = "---"

SoftLayer/CLI/virt/capacity/list.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager
1010

1111

12-
from pprint import pprint as pp
13-
1412
@click.command()
1513
@environment.pass_env
1614
def cli(env):
@@ -28,14 +26,9 @@ def cli(env):
2826
try:
2927
flavor = rc['instances'][0]['billingItem']['description']
3028
cost = float(rc['instances'][0]['billingItem']['hourlyRecurringFee'])
31-
# instance_count = int(rc.get('instanceCount',0))
32-
# cost_string = "%s * %s = %s" % (cost, instance_count, cost * instance_count)
3329
except KeyError:
3430
flavor = "Unknown Billing Item"
35-
# cost_string = "-"
3631
location = rc['backendRouter']['hostname']
3732
capacity = "%s%s" % (occupied_string, available_string)
3833
table.add_row([rc['id'], rc['name'], capacity, flavor, location, rc['createDate']])
3934
env.fout(table)
40-
print("")
41-
# pp(result)

SoftLayer/fixtures/SoftLayer_Product_Order.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,69 @@
1515
}]}
1616
placeOrder = verifyOrder
1717

18+
#Reserved Capacity Stuff
19+
20+
rsc_verifyOrder = {
21+
'orderContainers': [
22+
{
23+
'locationObject': {
24+
'id': 1854895,
25+
'longName': 'Dallas 13',
26+
'name': 'dal13'
27+
},
28+
'name': 'test-capacity',
29+
'postTaxRecurring': '0.32',
30+
'prices': [
31+
{
32+
'item': {
33+
'id': 1,
34+
'description': 'B1.1x2 (1 Year ''Term)',
35+
'keyName': 'B1_1X2_1_YEAR_TERM',
36+
}
37+
}
38+
]
39+
}
40+
],
41+
'postTaxRecurring': '0.32',
42+
}
43+
44+
rsc_placeOrder = {
45+
'orderDate': '2013-08-01 15:23:45',
46+
'orderId': 1234,
47+
'orderDetails': {
48+
'postTaxRecurring': '0.32',
49+
},
50+
'placedOrder': {
51+
'status': 'Great, thanks for asking',
52+
'locationObject': {
53+
'id': 1854895,
54+
'longName': 'Dallas 13',
55+
'name': 'dal13'
56+
},
57+
'name': 'test-capacity',
58+
'items': [
59+
{
60+
'description': 'B1.1x2 (1 Year ''Term)',
61+
'keyName': 'B1_1X2_1_YEAR_TERM',
62+
'categoryCode': 'guest_core',
63+
64+
}
65+
]
66+
}
67+
}
68+
69+
rsi_placeOrder = {
70+
'orderId': 1234,
71+
'orderDetails': {
72+
'prices': [
73+
{
74+
'id': 4,
75+
'item': {
76+
'id': 1,
77+
'description': 'B1.1x2 (1 Year ''Term)',
78+
'keyName': 'B1_1X2_1_YEAR_TERM',
79+
}
80+
}
81+
]
82+
}
83+
}

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@
15481548
{
15491549
'id': 12273,
15501550
'keyName': 'B1_1X2_1_YEAR_TERM',
1551+
'description': 'B1 1x2 1 year term',
1552+
'capacity': 12,
15511553
'itemCategory': {
15521554
'categoryCode': 'reserved_capacity',
15531555
'id': 2060,

SoftLayer/fixtures/SoftLayer_Security_Ssh_Key.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
'notes': 'notes',
77
'key': 'ssh-rsa AAAAB3N...pa67 user@example.com'}
88
createObject = getObject
9+
getAllObjects = [getObject]

SoftLayer/fixtures/SoftLayer_Virtual_ReservedCapacityGroup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,31 @@
5555
}
5656
]
5757
}
58+
59+
60+
getObject_pending = {
61+
'accountId': 1234,
62+
'backendRouterId': 1411193,
63+
'backendRouter': {
64+
'fullyQualifiedDomainName': 'bcr02a.dal13.softlayer.com',
65+
'hostname': 'bcr02a.dal13',
66+
'id': 1411193,
67+
'datacenter': {
68+
'id': 1854895,
69+
'longName': 'Dallas 13',
70+
'name': 'dal13',
71+
72+
}
73+
},
74+
'createDate': '2018-09-24T16:33:09-06:00',
75+
'id': 3103,
76+
'modifyDate': '',
77+
'name': 'test-capacity',
78+
'instances': [
79+
{
80+
'createDate': '2018-09-24T16:33:09-06:00',
81+
'guestId': 62159257,
82+
'id': 3501,
83+
}
84+
]
85+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
"""
2+
SoftLayer.tests.CLI.modules.vs_capacity_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
import json
8+
9+
import mock
10+
11+
from SoftLayer.CLI import exceptions
12+
from SoftLayer.fixtures import SoftLayer_Product_Package
13+
from SoftLayer.fixtures import SoftLayer_Product_Order
14+
from SoftLayer import SoftLayerAPIError
15+
from SoftLayer import testing
16+
17+
18+
from pprint import pprint as pp
19+
class VSCapacityTests(testing.TestCase):
20+
21+
def test_list(self):
22+
result = self.run_command(['vs', 'capacity', 'list'])
23+
self.assert_no_fail(result)
24+
25+
def test_detail(self):
26+
result = self.run_command(['vs', 'capacity', 'detail', '1234'])
27+
self.assert_no_fail(result)
28+
29+
def test_detail_pending(self):
30+
# Instances don't have a billing item if they haven't been approved yet.
31+
capacity_mock = self.set_mock('SoftLayer_Virtual_ReservedCapacityGroup', 'getObject')
32+
get_object = {
33+
'name': 'test-capacity',
34+
'instances': [
35+
{
36+
'createDate': '2018-09-24T16:33:09-06:00',
37+
'guestId': 62159257,
38+
'id': 3501,
39+
}
40+
]
41+
}
42+
capacity_mock.return_value = get_object
43+
result = self.run_command(['vs', 'capacity', 'detail', '1234'])
44+
self.assert_no_fail(result)
45+
46+
def test_create_test(self):
47+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
48+
item_mock.return_value = SoftLayer_Product_Package.getItems_RESERVED_CAPACITY
49+
order_mock = self.set_mock('SoftLayer_Product_Order', 'verifyOrder')
50+
order_mock.return_value = SoftLayer_Product_Order.rsc_verifyOrder
51+
result = self.run_command(['vs', 'capacity', 'create', '--name=TEST', '--datacenter=dal13',
52+
'--backend_router_id=1234', '--capacity=B1_1X2_1_YEAR_TERM', '--quantity=10', '--test'])
53+
self.assert_no_fail(result)
54+
55+
def test_create(self):
56+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
57+
item_mock.return_value = SoftLayer_Product_Package.getItems_RESERVED_CAPACITY
58+
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
59+
order_mock.return_value = SoftLayer_Product_Order.rsc_placeOrder
60+
result = self.run_command(['vs', 'capacity', 'create', '--name=TEST', '--datacenter=dal13',
61+
'--backend_router_id=1234', '--capacity=B1_1X2_1_YEAR_TERM', '--quantity=10'])
62+
self.assert_no_fail(result)
63+
64+
def test_create_options(self):
65+
item_mock = self.set_mock('SoftLayer_Product_Package', 'getItems')
66+
item_mock.return_value = SoftLayer_Product_Package.getItems_RESERVED_CAPACITY
67+
result = self.run_command(['vs', 'capacity', 'create-options'])
68+
self.assert_no_fail(result)
69+
70+
def test_create_guest_test(self):
71+
result = self.run_command(['vs', 'capacity', 'create-guest', '--capacity-id=3103', '--primary-disk=25',
72+
'-H ABCDEFG', '-D test_list.com', '-o UBUNTU_LATEST_64', '-kTest 1', '--test'])
73+
self.assert_no_fail(result)
74+
75+
def test_create_guest(self):
76+
order_mock = self.set_mock('SoftLayer_Product_Order', 'placeOrder')
77+
order_mock.return_value = SoftLayer_Product_Order.rsi_placeOrder
78+
result = self.run_command(['vs', 'capacity', 'create-guest', '--capacity-id=3103', '--primary-disk=25',
79+
'-H ABCDEFG', '-D test_list.com', '-o UBUNTU_LATEST_64', '-kTest 1'])
80+
self.assert_no_fail(result)

0 commit comments

Comments
 (0)