-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathaccount_tests.py
144 lines (120 loc) · 5.92 KB
/
account_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
SoftLayer.tests.CLI.modules.account_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tests for the user cli command
"""
import json
from SoftLayer.fixtures import SoftLayer_Account as SoftLayer_Account
from SoftLayer import testing
class AccountCLITests(testing.TestCase):
def set_up(self):
self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
# slcli account event-detail
def test_event_detail(self):
result = self.run_command(['account', 'event-detail', '1234'])
self.assert_no_fail(result)
self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
def test_event_details_ack(self):
result = self.run_command(['account', 'event-detail', '1234', '--ack'])
self.assert_no_fail(result)
self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier='1234')
# slcli account events
def test_events(self):
result = self.run_command(['account', 'events'])
self.assert_no_fail(result)
self.assert_called_with(self.SLNOE, 'getAllObjects')
def test_event_ack_all(self):
result = self.run_command(['account', 'events', '--ack-all'])
self.assert_no_fail(result)
self.assert_called_with(self.SLNOE, 'getAllObjects')
self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier=1234)
def test_event_jsonraw_output(self):
# https://github.com/softlayer/softlayer-python/issues/1545
command = '--format jsonraw account events'
command_params = command.split()
result = self.run_command(command_params)
json_text_tables = result.stdout.split('\n')
# removing an extra item due to an additional Newline at the end of the output
json_text_tables.pop()
# each item in the json_text_tables should be a list
for json_text_table in json_text_tables:
json_table = json.loads(json_text_table)
self.assertIsInstance(json_table, list)
# slcli account invoice-detail
def test_invoice_detail(self):
result = self.run_command(['account', 'invoice-detail', '1234'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
def test_invoice_detail_details(self):
result = self.run_command(['account', 'invoice-detail', '1234', '--details'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
# slcli account invoices
def test_invoices(self):
result = self.run_command(['account', 'invoices'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
def test_invoices_limited(self):
result = self.run_command(['account', 'invoices', '--limit=10'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=10)
def test_invoices_closed(self):
_filter = {
'invoices': {
'createDate': {
'operation': 'orderBy',
'options': [{
'name': 'sort',
'value': ['DESC']
}]
}
}
}
result = self.run_command(['account', 'invoices', '--closed'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50, filter=_filter)
def test_invoices_all(self):
result = self.run_command(['account', 'invoices', '--all'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
def test_single_invoice(self):
amock = self.set_mock('SoftLayer_Account', 'getInvoices')
amock.return_value = SoftLayer_Account.getInvoices[0]
result = self.run_command(['account', 'invoices', '--limit=1'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=1)
# slcli account summary
def test_account_summary(self):
result = self.run_command(['account', 'summary'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getObject')
# slcli account billing-items
def test_account_billing_items(self):
result = self.run_command(['account', 'billing-items'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')
# slcli account item-detail
def test_account_get_billing_item_detail(self):
result = self.run_command(['account', 'item-detail', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier='12345')
# slcli account cancel-item
def test_account_cancel_item(self):
result = self.run_command(['account', 'cancel-item', '12345'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')
def test_acccount_order(self):
result = self.run_command(['account', 'orders'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Billing_Order', 'getAllObjects')
def test_acccount_licenses(self):
result = self.run_command(['account', 'licenses'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')
def test_bandwidth_pools(self):
result = self.run_command(['account', 'bandwidth-pools'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments')
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject')