Skip to content

Commit 105b9ee

Browse files
committed
Fix shell CLI tests.
1 parent ab01bb2 commit 105b9ee

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

SoftLayer/testing/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def set_mock(self, service, method):
157157
"""Set and return mock on the current client."""
158158
return self.mocks.set_mock(service, method)
159159

160-
def run_command(self, args=None, env=None, fixtures=True, fmt='json'):
160+
def run_command(self, args=None, env=None, fixtures=True, fmt='json', input=None):
161161
"""A helper that runs a SoftLayer CLI command.
162162
163163
This returns a click.testing.Result object.
@@ -169,7 +169,7 @@ def run_command(self, args=None, env=None, fixtures=True, fmt='json'):
169169
args.insert(0, '--format=%s' % fmt)
170170

171171
runner = testing.CliRunner()
172-
return runner.invoke(core.cli, args=args, obj=env or self.env)
172+
return runner.invoke(core.cli, args=args, input=input, obj=env or self.env)
173173

174174

175175
def call_has_props(call, props):

tests/CLI/modules/shell_tests.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,24 @@
66
"""
77
from SoftLayer import testing
88

9-
import mock
9+
import tempfile
1010

1111

1212
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)
1813

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

Comments
 (0)