File: event_log_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 (107 lines) | stat: -rw-r--r-- 3,746 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
"""
    SoftLayer.tests.CLI.modules.event_log_tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    :license: MIT, see LICENSE for more details.
"""

import json

from SoftLayer import SoftLayerAPIError
from SoftLayer import testing


class EventLogTests(testing.TestCase):

    def test_get_event_log_with_metadata(self):
        result = self.run_command(['event-log', 'get', '--metadata'])

        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
        self.assertIn('Metadata', result.output)

    def test_get_event_log_without_metadata(self):
        result = self.run_command(['event-log', 'get', '--no-metadata'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
        self.assert_called_with('SoftLayer_User_Customer', 'getObject', identifier=400)
        self.assertNotIn('Metadata', result.output)

    def test_get_event_log_empty(self):
        mock = self.set_mock('SoftLayer_Event_Log', 'getAllObjects')
        mock.return_value = None

        result = self.run_command(['event-log', 'get'])
        expected = 'Event, Object, Type, Date, Username\n' \
                   'No logs available for filter {}.\n'
        self.assert_no_fail(result)
        self.assertEqual(expected, result.output)

    def test_get_event_log_over_limit(self):
        result = self.run_command(['event-log', 'get', '-l 1'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
        self.assertEqual(2, result.output.count("\n"))

    def test_get_event_log_types(self):
        expected = [
            {
                "types": {"value": "Account"}
            },
            {
                "types": {"value": "CDN"}
            },
            {
                "types": {"value": "User"}
            },
            {
                "types": {"value": "Bare Metal Instance"}
            },
            {
                "types": {"value": "API Authentication"}
            },
            {
                "types": {"value": "Server"}
            },
            {
                "types": {"value": "CCI"}
            },
            {
                "types": {"value": "Image"}
            },
            {
                "types": {"value": "Bluemix LB"}
            },
            {
                "types": {"value": "Facility"}
            },
            {
                "types": {"value": "Cloud Object Storage"}
            },
            {
                "types": {"value": "Security Group"}
            }
        ]

        result = self.run_command(['event-log', 'types'])

        self.assert_no_fail(result)
        self.assertEqual(expected, json.loads(result.output))

    def test_get_unlimited_events(self):
        result = self.run_command(['event-log', 'get', '-l -1'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
        self.assertEqual(8, result.output.count("\n"))

    def test_issues1905(self):
        """https://github.com/softlayer/softlayer-python/issues/1905"""
        getUser = self.set_mock('SoftLayer_User_Customer', 'getObject')
        getUser.side_effect = SoftLayerAPIError(
            "SoftLayer_Exception_PermissionDenied",
            "You do not have permission to access this user")
        result = self.run_command(['event-log', 'get', '-l -1'])
        self.assert_no_fail(result)
        self.assert_called_with('SoftLayer_Event_Log', 'getAllObjects')
        self.assert_called_with('SoftLayer_User_Customer', 'getObject', identifier=400)
        user_calls = self.calls('SoftLayer_User_Customer', 'getObject')
        self.assertEqual(1, len(user_calls))