|
6 | 6 | """ |
7 | 7 | from SoftLayer import testing |
8 | 8 |
|
9 | | -import mock |
| 9 | +import tempfile |
10 | 10 |
|
11 | 11 |
|
12 | 12 | class ShellTests(testing.TestCase): |
13 | | - @mock.patch('prompt_toolkit.shortcuts.prompt') |
14 | | - def test_shell_quit(self, prompt): |
15 | | - prompt.return_value = "quit" |
16 | | - result = self.run_command(['shell']) |
17 | | - self.assertEqual(result.exit_code, 0) |
18 | 13 |
|
19 | | - @mock.patch('prompt_toolkit.shortcuts.prompt') |
20 | | - @mock.patch('shlex.split') |
21 | | - def test_shell_help(self, prompt, split): |
22 | | - split.side_effect = [(['help']), (['vs', 'list']), (False), (['quit'])] |
23 | | - prompt.return_value = "none" |
24 | | - result = self.run_command(['shell']) |
25 | | - if split.call_count is not 5: |
26 | | - raise Exception("Split not called correctly. Count: " + str(split.call_count)) |
27 | | - self.assertEqual(result.exit_code, 1) |
| 14 | + def test_shell_quit(self): |
| 15 | + # Use a file as stdin |
| 16 | + with tempfile.NamedTemporaryFile() as stdin: |
| 17 | + stdin.write(b'exit\n') |
| 18 | + stdin.seek(0) |
| 19 | + result = self.run_command(['shell'], input=stdin) |
| 20 | + self.assertEqual(result.exit_code, 0) |
| 21 | + |
| 22 | + def test_shell_help(self): |
| 23 | + # Use a file as stdin |
| 24 | + with tempfile.NamedTemporaryFile() as stdin: |
| 25 | + stdin.write(b'help\nexit\n') |
| 26 | + stdin.seek(0) |
| 27 | + result = self.run_command(['shell'], input=stdin) |
| 28 | + self.assertIn('Welcome to the SoftLayer shell.', result.output) |
| 29 | + self.assertEqual(result.exit_code, 0) |
0 commit comments