Skip to content

Commit 3449733

Browse files
author
Brian Flores
committed
updaded --price option and unit tests
1 parent e6a4b9e commit 3449733

File tree

4 files changed

+79
-7
lines changed

4 files changed

+79
-7
lines changed

SoftLayer/CLI/virt/detail.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,10 @@ def cli(env, identifier, passwords=False, price=False):
9797
total_price = utils.lookup(result,
9898
'billingItem',
9999
'nextInvoiceTotalRecurringAmount') or 0
100-
total_price += sum(p['nextInvoiceTotalRecurringAmount']
101-
for p
102-
in utils.lookup(result,
103-
'billingItem',
104-
'children') or [])
105-
table.add_row(['price_rate', total_price])
100+
if total_price != 0:
101+
price_data = _get_price_data(utils.lookup(result, 'billingItem'), total_price)
102+
table.add_row(['Prices', price_data['priceTable']])
103+
table.add_row(['Price rate', price_data['totalPrice']])
106104

107105
if passwords:
108106
pass_table = formatting.Table(['software', 'username', 'password'])
@@ -156,6 +154,22 @@ def _bw_table(bw_data):
156154
return table
157155

158156

157+
def _get_price_data(billing_item, total_price):
158+
"""Returns an item table and price rate value in an object"""
159+
price_table = formatting.Table(['Item', 'CategoryCode', 'Recurring Price'])
160+
price_table.add_row(['Total', '-', total_price])
161+
items = billing_item['nextInvoiceChildren']
162+
for item in items:
163+
if item.get('recurringFee') is not None:
164+
total_price += float(item['recurringFee'])
165+
price_table.add_row([item['description'], item['categoryCode'], item['recurringFee']])
166+
response = {
167+
"priceTable": price_table,
168+
"totalPrice": total_price,
169+
}
170+
return response
171+
172+
159173
def _cli_helper_dedicated_host(env, result, table):
160174
"""Get details on dedicated host for a virtual server."""
161175

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,60 @@
3434
'nextInvoiceTotalRecurringAmount': 1
3535
}
3636
],
37+
"nextInvoiceChildren": [
38+
{
39+
"allowCancellationFlag": 1,
40+
"associatedBillingItemId": "738974962",
41+
"cancellationDate": "2022-11-03T23:00:01-06:00",
42+
"categoryCode": "os_usage",
43+
"createDate": "2022-10-04T17:00:08-06:00",
44+
"cycleStartDate": "2022-10-04T17:00:08-06:00",
45+
"description": "CentOS 8.x Usage is 743.9997 hours Used",
46+
"id": 999303609,
47+
"laborFee": "0",
48+
"laborFeeTaxRate": "0",
49+
"lastBillDate": None,
50+
"modifyDate": None,
51+
"nextBillDate": "2022-11-03T23:00:00-06:00",
52+
"oneTimeFee": "0",
53+
"oneTimeFeeTaxRate": "0",
54+
"orderItemId": None,
55+
"parentId": None,
56+
"recurringFee": "0",
57+
"recurringFeeTaxRate": "0",
58+
"recurringMonths": 1,
59+
"serviceProviderId": 1,
60+
"setupFee": "0",
61+
"setupFeeTaxRate": "0",
62+
"associatedBillingItem": None
63+
},
64+
{
65+
"allowCancellationFlag": 1,
66+
"associatedBillingItemId": "738974962",
67+
"cancellationDate": "2022-11-03T23:00:01-06:00",
68+
"categoryCode": "guest_core_usage",
69+
"createDate": "2022-10-04T17:00:09-06:00",
70+
"cycleStartDate": "2022-10-04T17:00:09-06:00",
71+
"description": "CPU Cores: a suspendable product.",
72+
"id": 999303621,
73+
"laborFee": "0",
74+
"laborFeeTaxRate": "0",
75+
"lastBillDate": None,
76+
"modifyDate": None,
77+
"nextBillDate": "2022-11-03T23:00:00-06:00",
78+
"oneTimeFee": "0",
79+
"oneTimeFeeTaxRate": "0",
80+
"orderItemId": None,
81+
"parentId": None,
82+
"recurringFee": "59.52",
83+
"recurringFeeTaxRate": "0",
84+
"recurringMonths": 1,
85+
"serviceProviderId": 1,
86+
"setupFee": "0",
87+
"setupFeeTaxRate": "0",
88+
"associatedBillingItem": None
89+
},
90+
],
3791
'package': {
3892
"id": 835,
3993
"keyName": "PUBLIC_CLOUD_SERVER"

SoftLayer/managers/vs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ def get_instance(self, instance_id, **kwargs):
246246
'''billingItem[id,nextInvoiceTotalRecurringAmount,
247247
package[id,keyName],
248248
children[description,categoryCode,nextInvoiceTotalRecurringAmount],
249+
nextInvoiceChildren[description,
250+
categoryCode,
251+
recurringFee,
252+
nextInvoiceTotalRecurringAmount],
249253
orderItem[id,
250254
order.userRecord[username],
251255
preset.keyName]],'''

tests/CLI/modules/vs/vs_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_detail_vs(self):
167167
self.assert_no_fail(result)
168168
output = json.loads(result.output)
169169
self.assertEqual(output['notes'], 'notes')
170-
self.assertEqual(output['price_rate'], 6.54)
170+
self.assertEqual(output['Price rate'], 61.06)
171171
self.assertEqual(output['users'][0]['username'], 'user')
172172
self.assertEqual(output['vlans'][0]['number'], 23)
173173
self.assertEqual(output['owner'], 'chechu')

0 commit comments

Comments
 (0)