|
4 | 4 |
|
5 | 5 | :license: MIT, see LICENSE for more details. |
6 | 6 | """ |
7 | | -from SoftLayer import testing |
8 | | - |
9 | 7 | import json |
| 8 | +import mock |
| 9 | + |
| 10 | +from SoftLayer.CLI import exceptions |
| 11 | +from SoftLayer import testing |
10 | 12 |
|
11 | 13 |
|
12 | 14 | class TicketTests(testing.TestCase): |
@@ -38,3 +40,130 @@ def test_detail(self): |
38 | 40 | } |
39 | 41 | self.assertEqual(result.exit_code, 0) |
40 | 42 | self.assertEqual(json.loads(result.output), expected) |
| 43 | + |
| 44 | + def test_create(self): |
| 45 | + result = self.run_command(['ticket', 'create', '--title=Test', |
| 46 | + '--subject-id=1000', |
| 47 | + '--body=ticket body']) |
| 48 | + |
| 49 | + self.assertEqual(result.exit_code, 0) |
| 50 | + |
| 51 | + args = ({'subjectId': 1000, |
| 52 | + 'contents': 'ticket body', |
| 53 | + 'assignedUserId': 12345, |
| 54 | + 'title': 'Test'}, 'ticket body') |
| 55 | + |
| 56 | + self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', |
| 57 | + args=args) |
| 58 | + |
| 59 | + def test_create_and_attach(self): |
| 60 | + result = self.run_command(['ticket', 'create', '--title=Test', |
| 61 | + '--subject-id=1000', |
| 62 | + '--body=ticket body', |
| 63 | + '--hardware=234', |
| 64 | + '--virtual=567']) |
| 65 | + |
| 66 | + self.assertEqual(result.exit_code, 0) |
| 67 | + |
| 68 | + args = ({'subjectId': 1000, |
| 69 | + 'contents': 'ticket body', |
| 70 | + 'assignedUserId': 12345, |
| 71 | + 'title': 'Test'}, 'ticket body') |
| 72 | + |
| 73 | + self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', |
| 74 | + args=args) |
| 75 | + self.assert_called_with('SoftLayer_Ticket', 'addAttachedHardware', |
| 76 | + args=(234,), |
| 77 | + identifier=100) |
| 78 | + self.assert_called_with('SoftLayer_Ticket', 'addAttachedVirtualGuest', |
| 79 | + args=(567,), |
| 80 | + identifier=100) |
| 81 | + |
| 82 | + @mock.patch('click.edit') |
| 83 | + def test_create_no_body(self, edit_mock): |
| 84 | + edit_mock.return_value = 'ticket body' |
| 85 | + result = self.run_command(['ticket', 'create', '--title=Test', |
| 86 | + '--subject-id=1000']) |
| 87 | + self.assertEqual(result.exit_code, 0) |
| 88 | + |
| 89 | + args = ({'subjectId': 1000, |
| 90 | + 'contents': 'ticket body', |
| 91 | + 'assignedUserId': 12345, |
| 92 | + 'title': 'Test'}, 'ticket body') |
| 93 | + |
| 94 | + self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', |
| 95 | + args=args) |
| 96 | + |
| 97 | + def test_subjects(self): |
| 98 | + list_expected_ids = [1001, 1002, 1003, 1004, 1005] |
| 99 | + result = self.run_command(['ticket', 'subjects']) |
| 100 | + |
| 101 | + self.assertEqual(result.exit_code, 0) |
| 102 | + results = json.loads(result.output) |
| 103 | + for result in results: |
| 104 | + self.assertIn(result['id'], list_expected_ids) |
| 105 | + |
| 106 | + def test_attach_no_identifier(self): |
| 107 | + result = self.run_command(['ticket', 'attach', '1']) |
| 108 | + |
| 109 | + self.assertEqual(result.exit_code, 2) |
| 110 | + self.assertIsInstance(result.exception, exceptions.ArgumentError) |
| 111 | + |
| 112 | + def test_attach_two_identifiers(self): |
| 113 | + result = self.run_command(['ticket', |
| 114 | + 'attach', |
| 115 | + '1', |
| 116 | + '--hardware=100', |
| 117 | + '--virtual=100']) |
| 118 | + |
| 119 | + self.assertEqual(result.exit_code, 2) |
| 120 | + self.assertIsInstance(result.exception, exceptions.ArgumentError) |
| 121 | + |
| 122 | + def test_ticket_attach_hardware(self): |
| 123 | + result = self.run_command(['ticket', 'attach', '1', '--hardware=100']) |
| 124 | + |
| 125 | + self.assertEqual(result.exit_code, 0) |
| 126 | + self.assert_called_with('SoftLayer_Ticket', 'addAttachedHardware', |
| 127 | + args=(100,), |
| 128 | + identifier=1) |
| 129 | + |
| 130 | + def test_ticket_attach_virtual_server(self): |
| 131 | + result = self.run_command(['ticket', 'attach', '1', '--virtual=100']) |
| 132 | + |
| 133 | + self.assertEqual(result.exit_code, 0) |
| 134 | + self.assert_called_with('SoftLayer_Ticket', 'addAttachedVirtualGuest', |
| 135 | + args=(100,), |
| 136 | + identifier=1) |
| 137 | + |
| 138 | + def test_detach_no_identifier(self): |
| 139 | + result = self.run_command(['ticket', 'detach', '1']) |
| 140 | + |
| 141 | + self.assertEqual(result.exit_code, 2) |
| 142 | + self.assertIsInstance(result.exception, exceptions.ArgumentError) |
| 143 | + |
| 144 | + def test_detach_two_identifiers(self): |
| 145 | + result = self.run_command(['ticket', |
| 146 | + 'detach', |
| 147 | + '1', |
| 148 | + '--hardware=100', |
| 149 | + '--virtual=100']) |
| 150 | + self.assertEqual(result.exit_code, 2) |
| 151 | + self.assertIsInstance(result.exception, exceptions.ArgumentError) |
| 152 | + |
| 153 | + def test_ticket_detach_hardware(self): |
| 154 | + result = self.run_command(['ticket', 'detach', '1', '--hardware=100']) |
| 155 | + |
| 156 | + self.assertEqual(result.exit_code, 0) |
| 157 | + self.assert_called_with('SoftLayer_Ticket', |
| 158 | + 'removeAttachedHardware', |
| 159 | + args=(100,), |
| 160 | + identifier=1) |
| 161 | + |
| 162 | + def test_ticket_detach_virtual_server(self): |
| 163 | + result = self.run_command(['ticket', 'detach', '1', '--virtual=100']) |
| 164 | + |
| 165 | + self.assertEqual(result.exit_code, 0) |
| 166 | + self.assert_called_with('SoftLayer_Ticket', |
| 167 | + 'removeAttachedVirtualGuest', |
| 168 | + args=(100,), |
| 169 | + identifier=1) |
0 commit comments