Skip to content

Commit a7c8db4

Browse files
unit tests for slcli portion
1 parent f634e8a commit a7c8db4

7 files changed

Lines changed: 132 additions & 8 deletions

File tree

SoftLayer/CLI/account/invoices.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55

66
import SoftLayer
77
from SoftLayer.CLI import environment
8-
from SoftLayer.CLI import exceptions
98
from SoftLayer.CLI import formatting
109
from SoftLayer.managers.account import AccountManager as AccountManager
1110
from SoftLayer import utils
12-
from pprint import pprint as pp
13-
1411

1512
@click.command()
1613
@click.option('--limit', default=50, show_default=True,
17-
help="How many invoices to get back. ALL for EVERY invoice on your account")
14+
help="How many invoices to get back.")
1815
@click.option('--closed', is_flag=True, default=False, show_default=True,
1916
help="Include invoices with a CLOSED status.")
2017
@click.option('--all', 'get_all', is_flag=True, default=False, show_default=True,

SoftLayer/CLI/account/summary.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,4 @@ def get_snapshot_table(account):
4040
table.add_row(['Network Vlans', account.get('networkVlanCount', '-')])
4141
table.add_row(['Subnets', account.get('subnetCount', '-')])
4242
table.add_row(['Users', account.get('userCount', '-')])
43-
# table.add_row(['', account.get('', '-')])
4443
return table

SoftLayer/fixtures/SoftLayer_Account.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,3 +662,27 @@
662662
"name": "SPREAD"
663663
}
664664
}]
665+
666+
getInvoices = [
667+
{
668+
'id': 33816665,
669+
'modifyDate': '2019-03-04T00:17:42-06:00',
670+
'createDate': '2019-03-04T00:17:42-06:00',
671+
'startingBalance': '129251.73',
672+
'statusCode': 'OPEN',
673+
'typeCode': 'RECURRING',
674+
'itemCount': 3317,
675+
'invoiceTotalAmount': '6230.66'
676+
},
677+
{
678+
'id': 12345667,
679+
'modifyDate': '2019-03-05T00:17:42-06:00',
680+
'createDate': '2019-03-04T00:17:42-06:00',
681+
'startingBalance': '129251.73',
682+
'statusCode': 'OPEN',
683+
'typeCode': 'RECURRING',
684+
'itemCount': 12,
685+
'invoiceTotalAmount': '6230.66',
686+
'endingBalance': '12345.55'
687+
}
688+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
getInvoiceTopLevelItems = [
2+
{
3+
'categoryCode': 'sov_sec_ip_addresses_priv',
4+
'createDate': '2018-04-04T23:15:20-06:00',
5+
'description': '64 Portable Private IP Addresses',
6+
'id': 724951323,
7+
'oneTimeAfterTaxAmount': '0',
8+
'recurringAfterTaxAmount': '0',
9+
'category': {'name': 'Private (only) Secondary VLAN IP Addresses'},
10+
'children': [
11+
{
12+
'id': 12345,
13+
'category': {'name': 'Fake Child Category'},
14+
'description': 'Blah',
15+
'oneTimeAfterTaxAmount': 55.50,
16+
'recurringAfterTaxAmount': 0.10
17+
}
18+
],
19+
'location': {'name': 'fra02'}
20+
}
21+
]

SoftLayer/fixtures/SoftLayer_Notification_Occurrence_Event.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
getObject = {
22
'endDate': '2019-03-18T17:00:00-06:00',
3-
'id': 174093,
3+
'id': 1234,
44
'lastImpactedUserCount': 417756,
55
'modifyDate': '2019-03-12T15:32:48-06:00',
66
'recoveryTime': None,
@@ -20,3 +20,7 @@
2020
}
2121
]
2222
}
23+
24+
getAllObjects = [getObject]
25+
26+
acknowledgeNotification = True

SoftLayer/managers/account.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ def get_billing_items(self, identifier):
103103
location[name],
104104
children[id, category[name], description, oneTimeAfterTaxAmount, recurringAfterTaxAmount]
105105
]"""
106-
return self.client.call('Billing_Invoice', 'getInvoiceTopLevelItems', id=identifier, mask=mask, iter=True, limit=100)
106+
return self.client.call(
107+
'Billing_Invoice',
108+
'getInvoiceTopLevelItems',
109+
id=identifier,
110+
mask=mask,
111+
iter=True,
112+
limit=100
113+
)
107114

108115
def get_child_items(self, identifier):
109116
mask = "mask[id, description, oneTimeAfterTaxAmount, recurringAfterTaxAmount, category[name], location[name]]"

tests/CLI/modules/account_tests.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,79 @@
1515

1616
class AccountCLITests(testing.TestCase):
1717

18+
def set_up(self):
19+
self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
20+
21+
#### slcli account event-detail ####
1822
def test_event_detail(self):
1923
result = self.run_command(['account', 'event-detail', '1234'])
2024
self.assert_no_fail(result)
21-
self.assert_called_with('SoftLayer_Notification_Occurrence_Event', 'getObject', identifier='1234')
25+
self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
26+
27+
def test_event_details_ack(self):
28+
result = self.run_command(['account', 'event-detail', '1234', '--ack'])
29+
self.assert_no_fail(result)
30+
self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
31+
self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier='1234')
32+
33+
#### slcli account events ####
34+
def test_events(self):
35+
result = self.run_command(['account', 'events'])
36+
self.assert_no_fail(result)
37+
self.assert_called_with(self.SLNOE, 'getAllObjects')
38+
39+
def test_event_ack_all(self):
40+
result = self.run_command(['account', 'events', '--ack-all'])
41+
self.assert_called_with(self.SLNOE, 'getAllObjects')
42+
self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier=1234)
43+
44+
45+
#### slcli account invoice-detail ####
46+
def test_invoice_detail(self):
47+
result = self.run_command(['account', 'invoice-detail', '1234'])
48+
self.assert_no_fail(result)
49+
self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
50+
51+
def test_invoice_detail(self):
52+
result = self.run_command(['account', 'invoice-detail', '1234', '--details'])
53+
self.assert_no_fail(result)
54+
self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
55+
56+
#### slcli account invoices ####
57+
def test_invoices(self):
58+
result = self.run_command(['account', 'invoices'])
59+
self.assert_no_fail(result)
60+
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
61+
62+
def test_invoices_limited(self):
63+
result = self.run_command(['account', 'invoices', '--limit=10'])
64+
self.assert_no_fail(result)
65+
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=10)
66+
67+
def test_invoices_closed(self):
68+
_filter = {
69+
'invoices': {
70+
'createDate' : {
71+
'operation': 'orderBy',
72+
'options': [{
73+
'name': 'sort',
74+
'value': ['DESC']
75+
}]
76+
}
77+
}
78+
}
79+
result = self.run_command(['account', 'invoices', '--closed'])
80+
self.assert_no_fail(result)
81+
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50, filter=_filter)
82+
83+
def test_invoices_all(self):
84+
result = self.run_command(['account', 'invoices', '--all'])
85+
self.assert_no_fail(result)
86+
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
87+
88+
#### slcli account summary ####
89+
result = self.run_command(['account', 'summary'])
90+
self.assert_no_fail(result)
91+
self.assert_called_with('SoftLayer_Account', 'getObject')
92+
93+

0 commit comments

Comments
 (0)