1"""
2    SoftLayer.tests.CLI.modules.account_tests
3    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5    Tests for the user cli command
6"""
7from SoftLayer.fixtures import SoftLayer_Account as SoftLayer_Account
8from SoftLayer import testing
9
10
11class AccountCLITests(testing.TestCase):
12
13    def set_up(self):
14        self.SLNOE = 'SoftLayer_Notification_Occurrence_Event'
15
16    # slcli account event-detail
17    def test_event_detail(self):
18        result = self.run_command(['account', 'event-detail', '1234'])
19        self.assert_no_fail(result)
20        self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
21
22    def test_event_details_ack(self):
23        result = self.run_command(['account', 'event-detail', '1234', '--ack'])
24        self.assert_no_fail(result)
25        self.assert_called_with(self.SLNOE, 'getObject', identifier='1234')
26        self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier='1234')
27
28    # slcli account events
29    def test_events(self):
30        result = self.run_command(['account', 'events'])
31        self.assert_no_fail(result)
32        self.assert_called_with(self.SLNOE, 'getAllObjects')
33
34    def test_event_ack_all(self):
35        result = self.run_command(['account', 'events', '--ack-all'])
36        self.assert_no_fail(result)
37        self.assert_called_with(self.SLNOE, 'getAllObjects')
38        self.assert_called_with(self.SLNOE, 'acknowledgeNotification', identifier=1234)
39
40    # slcli account invoice-detail
41
42    def test_invoice_detail(self):
43        result = self.run_command(['account', 'invoice-detail', '1234'])
44        self.assert_no_fail(result)
45        self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
46
47    def test_invoice_detail_details(self):
48        result = self.run_command(['account', 'invoice-detail', '1234', '--details'])
49        self.assert_no_fail(result)
50        self.assert_called_with('SoftLayer_Billing_Invoice', 'getInvoiceTopLevelItems', identifier='1234')
51
52    # slcli account invoices
53    def test_invoices(self):
54        result = self.run_command(['account', 'invoices'])
55        self.assert_no_fail(result)
56        self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
57
58    def test_invoices_limited(self):
59        result = self.run_command(['account', 'invoices', '--limit=10'])
60        self.assert_no_fail(result)
61        self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=10)
62
63    def test_invoices_closed(self):
64        _filter = {
65            'invoices': {
66                'createDate': {
67                    'operation': 'orderBy',
68                    'options': [{
69                        'name': 'sort',
70                        'value': ['DESC']
71                    }]
72                }
73            }
74        }
75        result = self.run_command(['account', 'invoices', '--closed'])
76        self.assert_no_fail(result)
77        self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50, filter=_filter)
78
79    def test_invoices_all(self):
80        result = self.run_command(['account', 'invoices', '--all'])
81        self.assert_no_fail(result)
82        self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=50)
83
84    def test_single_invoice(self):
85        amock = self.set_mock('SoftLayer_Account', 'getInvoices')
86        amock.return_value = SoftLayer_Account.getInvoices[0]
87        result = self.run_command(['account', 'invoices', '--limit=1'])
88        self.assert_no_fail(result)
89        self.assert_called_with('SoftLayer_Account', 'getInvoices', limit=1)
90
91    # slcli account summary
92    def test_account_summary(self):
93        result = self.run_command(['account', 'summary'])
94        self.assert_no_fail(result)
95        self.assert_called_with('SoftLayer_Account', 'getObject')
96
97    # slcli account billing-items
98    def test_account_billing_items(self):
99        result = self.run_command(['account', 'billing-items'])
100        self.assert_no_fail(result)
101        self.assert_called_with('SoftLayer_Account', 'getAllTopLevelBillingItems')
102
103    # slcli account item-detail
104    def test_account_get_billing_item_detail(self):
105        result = self.run_command(['account', 'item-detail', '12345'])
106        self.assert_no_fail(result)
107        self.assert_called_with('SoftLayer_Billing_Item', 'getObject', identifier='12345')
108
109    # slcli account cancel-item
110    def test_account_cancel_item(self):
111        result = self.run_command(['account', 'cancel-item', '12345'])
112        self.assert_no_fail(result)
113        self.assert_called_with('SoftLayer_Billing_Item', 'cancelItem', identifier='12345')
114
115    def test_acccount_order(self):
116        result = self.run_command(['account', 'orders'])
117        self.assert_no_fail(result)
118        self.assert_called_with('SoftLayer_Billing_Order', 'getAllObjects')
119
120    def test_acccount_licenses(self):
121        result = self.run_command(['account', 'licenses'])
122        self.assert_no_fail(result)
123        self.assert_called_with('SoftLayer_Account', 'getActiveVirtualLicenses')
124        self.assert_called_with('SoftLayer_Account', 'getActiveAccountLicenses')
125