Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_error_message_when_directory_is_empty(self):
with mock.patch('sys.stderr', six.StringIO()) as mock_stderr:
self.cmd(self.args, self.global_args)
self.assertEqual(
mock_stderr.getvalue(),
'Fail to upload %s. '
'The build root directory is empty or does not exist.\n'
% (self.build_root)
)
def get_presigned_url_for_cmd(self, cmdline):
with mock.patch('time.time', FROZEN_TIME):
with mock.patch('datetime.datetime') as d:
d.utcnow = FROZEN_DATETIME
stdout = self.assert_params_for_cmd(cmdline, None)[0].strip()
return stdout
@mock.patch('awscli.customizations.history.list.OutputStreamFactory')
def test_uses_sr_less_flags(self, mock_factory):
ListCommand(self.session)
mock_factory.assert_called_with(self.session, default_less_flags='SR')
def _apply_history_recorder_patch(self, module, history_recorder):
patch_history_recorder = mock.patch(
module + '.HISTORY_RECORDER', history_recorder)
patch_history_recorder.start()
self.addCleanup(patch_history_recorder.stop)
@mock.patch('awscli.customizations.history.db.sqlite3')
@mock.patch('awscli.customizations.history.HISTORY_RECORDER',
spec=HistoryRecorder)
def test_profile_does_not_exist(self, mock_recorder, mock_db_sqlite3,
mock_sqlite3):
mock_session = mock.Mock(Session)
mock_session.get_scoped_config.side_effect = ProfileNotFound(
profile='no-exist')
parsed_args = argparse.Namespace()
parsed_args.command = 'configure'
attach_history_handler(session=mock_session, parsed_args=parsed_args)
self.assertFalse(mock_recorder.add_handler.called)
self.assertFalse(mock_db_sqlite3.connect.called)
@mock.patch('awscli.utils.get_popen_kwargs_for_pager_cmd')
def test_env_configured_pager(self, mock_get_popen_pager):
mock_get_popen_pager.return_value = {
'args': ['mypager', '--option']
}
with self.stream_factory.get_pager_stream('mypager --option'):
mock_get_popen_pager.assert_called_with('mypager --option')
self.assertEqual(
self.popen.call_args_list,
[mock.call(
args=['mypager', '--option'],
stdin=subprocess.PIPE)]
)
def test_errors_when_service_command_is_invalid(self):
alias_value = 'non-existent-service myoperation'
command_table = self.create_command_table(['myservice'])
parser = self.create_parser(command_table)
alias_cmd = ServiceAliasCommand(
self.alias_name, alias_value, self.session, command_table, parser)
with self.assertRaises(SystemExit):
# Even though we catch the system exit, a message will always
# be forced to screen because it happened at system exit.
# The patch is to ensure it does not get displayed by nosetests.
with mock.patch('sys.stderr'):
alias_cmd([], FakeParsedArgs(command=self.alias_name))
def setUp(self):
self.create_client_patch = mock.patch(
'botocore.session.Session.create_client')
self.mock_create_client = self.create_client_patch.start()
self.session = get_session()
self.client = mock.Mock()
self.mock_create_client.return_value = self.client
self.cmd = GetGameSessionLogCommand(self.session)
self.contents = b'mycontents'
self.file_creator = FileCreator()
self.urlopen_patch = mock.patch(
'awscli.customizations.gamelift.getlog.urlopen')
self.urlopen_mock = self.urlopen_patch.start()
self.urlopen_mock.return_value = six.BytesIO(self.contents)
@mock.patch('awscli.customizations.history.commands.is_a_tty')
def test_detailed_formatter_is_a_tty(self, mock_is_a_tty):
mock_is_a_tty.return_value = True
self.formatter = mock.Mock(DetailedFormatter)
self.add_formatter('detailed', self.formatter)
self.parsed_args.format = 'detailed'
self.parsed_args.command_id = 'latest'
self.show_cmd._run_main(self.parsed_args, self.parsed_globals)
call = self.output_stream_factory.get_pager_stream.call_args
self.assertEqual(
self.formatter.call_args,
mock.call(
include=None, exclude=None,
output=self.output_stream, colorize=True
)