File: ticket_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 (111 lines) | stat: -rw-r--r-- 4,226 bytes parent folder | download | duplicates (3)
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
"""
    SoftLayer.tests.managers.ticket_tests
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    :license: MIT, see LICENSE for more details.
"""
import SoftLayer
from SoftLayer import fixtures
from SoftLayer import testing


class TicketTests(testing.TestCase):

    def set_up(self):
        self.ticket = SoftLayer.TicketManager(self.client)

    def test_list_tickets(self):
        results = self.ticket.list_tickets()

        for result in results:
            self.assertIn(result['id'], [100, 101, 102])
        self.assert_called_with('SoftLayer_Account', 'getTickets')

    def test_list_tickets_all(self):
        results = self.ticket.list_tickets(open_status=True,
                                           closed_status=True)

        for result in results:
            self.assertIn(result['id'], [100, 101, 102])
        self.assert_called_with('SoftLayer_Account', 'getTickets')

    def test_list_tickets_open(self):
        results = self.ticket.list_tickets(open_status=True,
                                           closed_status=False)
        for result in results:
            self.assertIn(result['id'], [102])
        self.assert_called_with('SoftLayer_Account', 'getOpenTickets')

    def test_list_tickets_closed(self):
        results = self.ticket.list_tickets(open_status=False,
                                           closed_status=True)
        for result in results:
            self.assertIn(result['id'], [100, 101])
        self.assert_called_with('SoftLayer_Account', 'getClosedTickets')

    def test_list_tickets_false(self):
        exception = self.assertRaises(ValueError,
                                      self.ticket.list_tickets,
                                      open_status=False,
                                      closed_status=False)

        self.assertEqual('open_status and closed_status cannot both be False', str(exception))

    def test_list_subjects(self):
        list_expected_ids = [1001, 1002, 1003, 1004, 1005]

        results = self.ticket.list_subjects()
        for result in results:
            self.assertIn(result['id'], list_expected_ids)

    def test_get_instance(self):
        result = self.ticket.get_ticket(100)

        self.assertEqual(result, fixtures.SoftLayer_Ticket.getObject)
        self.assert_called_with('SoftLayer_Ticket', 'getObject',
                                identifier=100)

    def test_create_ticket(self):
        self.ticket.create_ticket(
            title="Cloud Instance Cancellation - 08/01/13",
            body="body",
            subject=1004)

        args = ({"assignedUserId": 12345,
                 "subjectId": 1004,
                 "title": "Cloud Instance Cancellation - 08/01/13"},
                "body")
        self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket',
                                args=args)

    def test_update_ticket(self):
        # test a full update
        self.ticket.update_ticket(100, body='Update1')
        self.assert_called_with('SoftLayer_Ticket', 'addUpdate',
                                args=({'entry': 'Update1'},),
                                identifier=100)

    def test_attach_hardware(self):
        self.ticket.attach_hardware(100, 123)
        self.assert_called_with('SoftLayer_Ticket', 'addAttachedHardware',
                                args=(123,),
                                identifier=100)

    def test_attach_virtual_server(self):
        self.ticket.attach_virtual_server(100, 123)
        self.assert_called_with('SoftLayer_Ticket', 'addAttachedVirtualGuest',
                                args=(123,),
                                identifier=100)

    def test_detach_hardware(self):
        self.ticket.detach_hardware(100, 123)
        self.assert_called_with('SoftLayer_Ticket', 'removeAttachedHardware',
                                args=(123,),
                                identifier=100)

    def test_detach_virtual_server(self):
        self.ticket.detach_virtual_server(100, 123)
        self.assert_called_with('SoftLayer_Ticket',
                                'removeAttachedVirtualGuest',
                                args=(123,),
                                identifier=100)