File: account_tests.py

package info (click to toggle)
python-softlayer 6.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,508 kB
  • sloc: python: 57,195; makefile: 133; xml: 97; sh: 59
file content (206 lines) | stat: -rw-r--r-- 9,126 bytes parent folder | download
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""
    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')
        print(f"RESULT: {result.output}")
        # 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:
            print(f"TESTING THIS: \n{json_text_table}\n")
            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')

    def test_invoice_detail_csv_output_format(self):
        result = self.run_command(["--format", "csv", 'account', 'invoice-detail', '1234'])
        result_output = result.output.replace('\r', '').split('\n')
        self.assert_no_fail(result)
        self.assertEqual(result_output[0], '"Item Id","Category","Description","Single","Monthly",'
                         '"Create Date","Location"')
        self.assertEqual(result_output[1], '724951323,"Private (only) Secondary VLAN IP Addresses",'
                                           '"64 Portable Private IP Addresses (bleg.beh.com)",'
                                           '"$0.00","$0.00","2018-04-04","fra02"')

    # 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')

    def test_account_billing_items_by_category(self):
        result = self.run_command(['account', 'billing-items', '--category', 'server'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

    def test_account_billing_items_by_ordered(self):
        result = self.run_command(['account', 'billing-items', '--ordered', 'Test'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')

    def test_account_billing_items_create(self):
        result = self.run_command(['account', 'billing-items', '--create', '04-21-2023'])
        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_acccount_provisioning_hook(self):
        result = self.run_command(['account', 'hooks'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Account', 'getPostProvisioningHooks')

    def test_created_provisioning_hook(self):
        result = self.run_command(['account', 'hook-create', '--name', 'testslcli', '--uri', 'http://slclitest.com'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

    def test_delete_provisioning_hook(self):
        result = self.run_command(['account', 'hook-delete', '123456'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Provisioning_Hook', 'deleteObject')

    def test_order_upgrade(self):
        result = self.run_command(['account', 'orders', '--upgrades'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Account', 'getUpgradeRequests')

    def test_account_events(self):
        result = self.run_command(['account', 'events', '--date-min', '5/9/2023'])
        self.assert_no_fail(result)
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_account_planned_events(self):
        result = self.run_command(['account', 'events', '--planned'])
        self.assert_no_fail(result)
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_account_unplanned_events(self):
        result = self.run_command(['account', 'events', '--unplanned'])
        self.assert_no_fail(result)
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_account_announcement_events(self):
        result = self.run_command(['account', 'events', '--announcement'])
        self.assert_no_fail(result)
        self.assert_called_with(self.SLNOE, 'getAllObjects')