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 (196 lines) | stat: -rw-r--r-- 7,771 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
"""
    SoftLayer.tests.managers.account_tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

"""
from unittest import mock as mock

from SoftLayer.managers.account import AccountManager as AccountManager
from SoftLayer import SoftLayerAPIError
from SoftLayer import testing


class AccountManagerTests(testing.TestCase):

    def set_up(self):
        self.manager = AccountManager(self.client)
        self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'

    def test_get_summary(self):
        self.manager.get_summary()
        self.assert_called_with('SoftLayer_Account', 'getObject')

    def test_get_planned_upcoming_events(self):
        self.manager.get_upcoming_events("PLANNED")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_get_unplanned_upcoming_events(self):
        self.manager.get_upcoming_events("UNPLANNED_INCIDENT")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_get_announcement_upcoming_events(self):
        self.manager.get_upcoming_events("ANNOUNCEMENT")
        self.assert_called_with(self.SLNOE, 'getAllObjects')

    def test_add_planned_event_filter(self):
        event_type = 'PLANNED'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_add_unplanned_event_filter(self):
        event_type = 'UNPLANNED_INCIDENT'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_add_announcement_event_filter(self):
        event_type = 'ANNOUNCEMENT'
        _filter = {
            'notificationOccurrenceEventType': {
                'keyName': {
                    'operation': event_type
                }
            }
        }
        self.manager.add_event_filter(_filter, event_type)

    def test_ack_event(self):
        self.manager.ack_event(12345)
        self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier=12345)

    def test_get_event(self):
        self.manager.get_event(12345)
        self.assert_called_with(self.SLNOE, 'getObject', identifier=12345)

    def test_get_invoices(self):
        self.manager.get_invoices()
        self.assert_called_with('SoftLayer_Account', 'getInvoices')

    def test_get_invoices_closed(self):
        self.manager.get_invoices(closed=True)
        _filter = {
            'invoices': {
                'createDate': {
                    'operation': 'orderBy',
                    'options': [{
                        'name': 'sort',
                        'value': ['DESC']
                    }]
                }
            }
        }
        self.assert_called_with('SoftLayer_Account', 'getInvoices', filter=_filter)

    def test_get_billing_items(self):
        self.manager.get_billing_items(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems')

    def test_get_account_billing_items(self):
        self.manager.get_account_billing_items()
        object_filter = {
            "allTopLevelBillingItems": {
                "cancellationDate": {
                    "operation": "is null"
                },
                "id": {
                    "operation": "orderBy",
                    "options": [
                        {
                            "name": "sort",
                            "value": ["ASC"]
                        }
                    ]
                }
            }
        }

        self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems',
                                offset=0, limit=100, filter=object_filter)
        self.manager.get_account_billing_items(mask="id")
        self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems', mask="mask[id]")

    def test_get_billing_item(self):
        self.manager.get_billing_item(12345)
        self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier=12345)
        self.manager.get_billing_item(12345, mask="id")
        self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier=12345, mask="mask[id]")

    def test_cancel_item(self):
        self.manager.cancel_item(12345)
        reason = "No longer needed"
        note = "Cancelled by testAccount with the SLCLI"
        self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
                                args=(False, True, reason, note), identifier=12345)
        reason = "TEST"
        note = "note test"
        self.manager.cancel_item(12345, reason, note)
        self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem',
                                args=(False, True, reason, note), identifier=12345)

    def test_get_billing_item_from_invoice(self):
        self.manager.get_billing_item_from_invoice(12345)
        self.assert_called_with('SoftLayer_Billing_Invoice_Item', 'getBillingItem', identifier=12345)

    def test_get_item_details_with_billing_item_id(self):
        self.manager.get_item_detail(12345)
        self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier=12345)

    def test_get_item_details_with_invoice_item_id(self):
        mock = self.set_mock('SoftLayer_Billing_Item', 'getObject')
        mock.side_effect = SoftLayerAPIError(404, "Unable to find object with id of '123456'.")
        self.manager.get_item_detail(123456)
        self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier=123456)
        self.assert_called_with('SoftLayer_Billing_Invoice_Item', 'getBillingItem', identifier=123456)

    def test_get_routers(self):
        self.manager.get_routers()
        self.assert_called_with("SoftLayer_Account", "getRouters")

    def test_get_active_account_licenses(self):
        self.manager.get_active_account_licenses()
        self.assert_called_with("SoftLayer_Account", "getActiveAccountLicenses")

    def test_get_active_virtual_licenses(self):
        self.manager.get_active_virtual_licenses()
        self.assert_called_with("SoftLayer_Account", "getActiveVirtualLicenses")

    def test_get_routers_with_datacenter(self):
        self.manager.get_routers(location='dal13')
        object_filter = {'routers': {'topLevelLocation': {'name': {'operation': 'dal13'}}}}
        self.assert_called_with("SoftLayer_Account", "getRouters", filter=object_filter)

    def test_get_bandwidth_pools(self):
        self.manager.get_bandwidth_pools()
        self.assert_called_with('SoftLayer_Account', 'getBandwidthAllotments', mask=mock.ANY)

    def test_get_bandwidth_pool_counts(self):
        total = self.manager.get_bandwidth_pool_counts(1234)
        self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'getObject', identifier=1234)
        self.assertEqual(total, 2)

    def test_get_provisioning_scripts(self):
        self.manager.get_provisioning_scripts()
        self.assert_called_with("SoftLayer_Account", "getPostProvisioningHooks")

    def test_create_provisioning_scripts(self):
        self.manager.create_provisioning('testslcli', 'http://slclitest.com')
        self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

    def test_delete_provisioning_scripts(self):
        self.manager.delete_provisioning(123456)
        self.assert_called_with("SoftLayer_Provisioning_Hook", "deleteObject")

    def test_get_upgrades_orders(self):
        self.manager.get_account_upgrade_orders()
        self.assert_called_with("SoftLayer_Account", "getUpgradeRequests")