|
13 | 13 | from SoftLayer import testing |
14 | 14 |
|
15 | 15 |
|
| 16 | +class FakeTTY(): |
| 17 | + """A fake object to fake STD input""" |
| 18 | + def __init__(self, isatty=False, read="Default Output"): |
| 19 | + """Sets isatty and read""" |
| 20 | + self._isatty = isatty |
| 21 | + self._read = read |
| 22 | + |
| 23 | + def isatty(self): |
| 24 | + """returns self.isatty""" |
| 25 | + return self._isatty |
| 26 | + |
| 27 | + def read(self): |
| 28 | + """returns self.read""" |
| 29 | + return self._read |
| 30 | + |
| 31 | + |
16 | 32 | class TicketTests(testing.TestCase): |
17 | 33 |
|
18 | 34 | def test_list(self): |
@@ -99,18 +115,33 @@ def test_create_and_attach(self): |
99 | 115 | identifier=100) |
100 | 116 |
|
101 | 117 | @mock.patch('click.edit') |
102 | | - def test_create_no_body(self, edit_mock): |
| 118 | + @mock.patch('click.get_text_stream') |
| 119 | + def test_create_no_body(self, isatty_mock, edit_mock): |
| 120 | + fake_tty = FakeTTY(True, "TEST") |
| 121 | + isatty_mock.return_value = fake_tty |
103 | 122 | edit_mock.return_value = 'ticket body' |
104 | | - result = self.run_command(['ticket', 'create', '--title=Test', |
105 | | - '--subject-id=1000']) |
| 123 | + result = self.run_command(['ticket', 'create', '--title=Test', '--subject-id=1000']) |
106 | 124 | self.assert_no_fail(result) |
107 | 125 |
|
108 | 126 | args = ({'subjectId': 1000, |
109 | 127 | 'assignedUserId': 12345, |
110 | 128 | 'title': 'Test'}, 'ticket body') |
111 | 129 |
|
112 | | - self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', |
113 | | - args=args) |
| 130 | + self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', args=args) |
| 131 | + |
| 132 | + @mock.patch('click.get_text_stream') |
| 133 | + def test_create_no_body_stdin(self, isatty_mock): |
| 134 | + fake_tty = FakeTTY(False, "TEST TICKET BODY") |
| 135 | + isatty_mock.return_value = fake_tty |
| 136 | + result = self.run_command(['ticket', 'create', '--title=Test', '--subject-id=1000']) |
| 137 | + print(result.output) |
| 138 | + self.assert_no_fail(result) |
| 139 | + |
| 140 | + args = ({'subjectId': 1000, |
| 141 | + 'assignedUserId': 12345, |
| 142 | + 'title': 'Test'}, 'TEST TICKET BODY') |
| 143 | + |
| 144 | + self.assert_called_with('SoftLayer_Ticket', 'createStandardTicket', args=args) |
114 | 145 |
|
115 | 146 | def test_subjects(self): |
116 | 147 | list_expected_ids = [1001, 1002, 1003, 1004, 1005] |
@@ -294,12 +325,24 @@ def test_ticket_update(self): |
294 | 325 | self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing'},), identifier=100) |
295 | 326 |
|
296 | 327 | @mock.patch('click.edit') |
297 | | - def test_ticket_update_no_body(self, edit_mock): |
| 328 | + @mock.patch('click.get_text_stream') |
| 329 | + def test_ticket_update_no_body(self, isatty_mock, edit_mock): |
| 330 | + fake_tty = FakeTTY(True, "TEST TICKET BODY") |
| 331 | + isatty_mock.return_value = fake_tty |
298 | 332 | edit_mock.return_value = 'Testing1' |
299 | 333 | result = self.run_command(['ticket', 'update', '100']) |
300 | 334 | self.assert_no_fail(result) |
301 | 335 | self.assert_called_with('SoftLayer_Ticket', 'addUpdate', args=({'entry': 'Testing1'},), identifier=100) |
302 | 336 |
|
| 337 | + @mock.patch('click.get_text_stream') |
| 338 | + def test_ticket_update_no_body_stdin(self, isatty_mock): |
| 339 | + fake_tty = FakeTTY(False, "TEST TICKET BODY") |
| 340 | + isatty_mock.return_value = fake_tty |
| 341 | + result = self.run_command(['ticket', 'update', '100']) |
| 342 | + self.assert_no_fail(result) |
| 343 | + self.assert_called_with('SoftLayer_Ticket', 'addUpdate', |
| 344 | + args=({'entry': 'TEST TICKET BODY'},), identifier=100) |
| 345 | + |
303 | 346 | def test_ticket_json(self): |
304 | 347 | result = self.run_command(['--format=json', 'ticket', 'detail', '1']) |
305 | 348 | expected = {'Case_Number': 'CS123456', |
|
0 commit comments