def test_exit_dot_command_exits_shell(): mock_prompter = mock.Mock() # Simulate the user entering '.quit' fake_document = mock.Mock() fake_document.text = '.quit' mock_prompter.run.return_value = fake_document shell = app.AWSShell(mock.Mock(), mock.Mock(), mock.Mock()) shell.create_cli_interface = mock.Mock(return_value=mock_prompter) shell.run() # Should have only called run() once. As soon as we # see the .quit command, we immediately exit and stop prompting # for more shell commands. assert mock_prompter.run.call_count == 1
def test_history_stored_correctly(): mock_prompter = mock.Mock() mock_prompter.buffers = {'clidocs': mock.Mock()} # Simulate the user entering various commands quit_document = mock.Mock() quit_document.text = '.quit' command_document = mock.Mock() command_document.text = 'ec2 describe-instances' mock_prompter.run.side_effect = [command_document, quit_document] shell = app.AWSShell(mock.Mock(), mock.Mock(), mock.Mock(), popen_cls=mock.Mock()) shell.create_cli_interface = mock.Mock(return_value=mock_prompter) shell.run() # two calls should have been made, history should have added aws assert mock_prompter.run.call_count == 2 assert list(shell.history) == ['aws ec2 describe-instances']
def test_delegates_to_complete_changing_profile(): completer = mock.Mock(spec=shellcomplete.AWSShellCompleter) shell = app.AWSShell(completer, mock.Mock(), mock.Mock()) shell.profile = 'mynewprofile' assert completer.change_profile.call_args == mock.call('mynewprofile') assert shell.profile == 'mynewprofile'