Skip to content

Commit c212461

Browse files
committed
adding basic tests
1 parent 530eb45 commit c212461

6 files changed

Lines changed: 94 additions & 5 deletions

File tree

SoftLayer/CLI/billing/info.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def cli(env):
1616
billing = SoftLayer.BillingManager(env.client)
1717
table = formatting.Table(['Name', 'Value'])
1818
info = billing.get_info()
19+
table.add_row(['accountId', info['accountId']])
1920
table.add_row(['id', info['id']])
2021
table.add_row(['paymentTerms', info['paymentTerms']])
2122
table.add_row(['modifyDate', info['modifyDate']])

SoftLayer/CLI/billing/summary.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ def cli(env):
1515
"""List billing summary."""
1616
billing = SoftLayer.BillingManager(env.client)
1717
table = formatting.Table(['Name', 'Value'])
18-
balance = billing.get_balance()
19-
next_balance = billing.get_next_balance()
20-
last_bill_date = billing.get_latest_bill_date()
18+
result = billing.get_summary()
19+
balance = result['balance']
20+
next_balance = result['nextbalance']
21+
last_bill_date = result['lastbilldate']
2122
table.add_row(['Current Balance', balance])
2223
table.add_row(['Estimated Next Balance', next_balance])
2324
table.add_row(['Last Billing Date', last_bill_date])

SoftLayer/managers/billing.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def get_latest_bill_date(self):
6262
result = self.account.getLatestBillDate()
6363
return result
6464

65+
def get_summary(self):
66+
"""get summary
67+
68+
:return: billing account info
69+
"""
70+
result = {
71+
'lastbilldate': self.get_latest_bill_date(),
72+
'balance': self.get_balance(),
73+
'nextbalance': self.get_next_balance()
74+
}
75+
return result
76+
6577
def get_next_bill_items(self):
6678
"""get next bill items
6779
@@ -163,8 +175,8 @@ def list_resources(self, from_date=None, to_date=None, **kwargs):
163175
'operation':
164176
item['billingItem']['id']}}}}})
165177
if virtual_guest:
166-
cost = virtual_guest[0]['billingItem']['currentHourly' \
167-
'Charge']
178+
guest = virtual_guest[0]
179+
cost = guest['billingItem']['currentHourlyCharge']
168180

169181
else:
170182
create_date = datetime.datetime.strptime(

SoftLayer/testing/fixtures/SoftLayer_Account.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,35 @@
459459
'name': 'TestQuote1234',
460460
'quoteKey': '1234test4321',
461461
}]
462+
463+
464+
getOrders = [{
465+
'id': 1234,
466+
'resourceType': '1 x 2.0 GHz Core',
467+
'hostName': 'test',
468+
'createDate': '2014-05-01T14:03:04-07:00',
469+
'cost': 0.0
470+
}]
471+
472+
getBillingInfo = [{
473+
'id': 1234,
474+
'accountId': 123,
475+
'resourceType': '1 x 2.0 GHz Core',
476+
'hostName': 'test',
477+
'modifyDate': '2014-05-01T14:03:04-07:00',
478+
'createDate': '2014-05-01T14:03:04-07:00',
479+
'anniversaryDayOfMonth': 2,
480+
'percentDiscountOnetime': 2,
481+
'sparePoolAmount': 0,
482+
'currency': {
483+
'KeyName': 'usd',
484+
'id': 1,
485+
'name': 'dollars'
486+
}
487+
}]
488+
489+
getLatestBillDate = '2014-05-01T14:03:04-07:00'
490+
491+
getBalance = 40
492+
493+
getNextInvoiceTotalAmount = 2
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
getItems = [{
2+
'description': '1 x 2.0 GHz Core',
3+
'billingItem': {
4+
'setupFee': '0',
5+
'createDate': '2014-11-12T14:54:05-06:00',
6+
'oneTimeFee': '0', 'cancellationDate': '',
7+
'id': 1234,
8+
'hostName': 'testhost',
9+
'laborFee': '0'
10+
}
11+
}]
12+
13+
getOrderTotalOneTime = 0.0
14+
getOrderTotalRecurring = 0.0
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
SoftLayer.tests.managers.ticket_tests
3+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4+
5+
:license: MIT, see LICENSE for more details.
6+
"""
7+
import SoftLayer
8+
from SoftLayer import testing
9+
10+
11+
class BillingTests(testing.TestCase):
12+
13+
def set_up(self):
14+
self.billing = SoftLayer.BillingManager(self.client)
15+
16+
def test_list_billing_items(self):
17+
self.billing.list_resources()
18+
self.assert_called_with('SoftLayer_Account', 'getOrders')
19+
20+
def test_billing_info(self):
21+
self.billing.get_info()
22+
self.assert_called_with('SoftLayer_Account', 'getBillingInfo')
23+
24+
def test_billing_summary(self):
25+
self.billing.get_summary()
26+
self.assert_called_with('SoftLayer_Account',
27+
'getNextInvoiceTotalAmount')
28+
self.assert_called_with('SoftLayer_Account', 'getLatestBillDate')
29+
self.assert_called_with('SoftLayer_Account', 'getBalance')

0 commit comments

Comments
 (0)