How to use the awscli.testutils.mock.Mock function in awscli

To help you get started, we’ve selected a few awscli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cli / tests / unit / autocomplete / test_completer.py View on Github external
def test_returns_empty_list_if_no_completers_have_results(self):
        first = mock.Mock(spec=completer.BaseCompleter)
        second = mock.Mock(spec=completer.BaseCompleter)

        first.complete.return_value = None
        second.complete.return_value = None

        auto_complete = completer.AutoCompleter(
            self.parser, completers=[first, second])
        self.assertEqual(auto_complete.autocomplete('aws e'), [])

        first.complete.assert_called_with(self.parsed_result)
        second.complete.assert_called_with(self.parsed_result)
github aws / aws-cli / tests / unit / customizations / history / test_show.py View on Github external
def test_disable_color(self, mock_is_a_tty):
        self.formatter = mock.Mock(DetailedFormatter)
        self.add_formatter('detailed', self.formatter)
        self.parsed_args.format = 'detailed'
        self.parsed_args.command_id = 'latest'

        self.parsed_globals.color = 'off'
        # Even with settings that would typically enable color, it
        # should be turned off because it was explicitly turned off
        mock_is_a_tty.return_value = True

        self.show_cmd._run_main(self.parsed_args, self.parsed_globals)
        self.assertEqual(
            self.formatter.call_args,
            mock.call(
                include=None, exclude=None,
                output=self.output_stream, colorize=False
            )
github aws / aws-cli / tests / unit / customizations / wizard / test_core.py View on Github external
def setUp(self):
        self.mock_session = mock.Mock(spec=Session)
        self.config_writer = mock.Mock(spec=ConfigFileWriter)
        self.config_filename = 'foo'
        self.mock_session.get_config_variable.return_value = \
            self.config_filename
        self.config_api = core.SharedConfigAPI(self.mock_session,
                                               self.config_writer)
github aws / aws-cli / tests / unit / customizations / wizard / test_core.py View on Github external
def setUp(self):
        self.session = mock.Mock(spec=Session)
        self.client = mock.Mock()
        self.session.create_client.return_value = self.client
        self.mock_config_writer = mock.Mock(spec=ConfigFileWriter)
        self.shared_config_file = 'shared-config-file'
        self.config_api = mock.Mock(spec=core.SharedConfigAPI)
        self.executor = core.Executor(
            step_handlers={
                'apicall': core.APICallExecutorStep(
                    core.APIInvoker(session=self.session),
                ),
                'sharedconfig': core.SharedConfigExecutorStep(
                    config_api=self.config_api,
                ),
github aws / aws-cli / tests / unit / autocomplete / test_generator.py View on Github external
def test_use_high_level_generator_for_index_creation(self):
        model_index = mock.Mock(spec=indexer.ModelIndexer)
        clidriver = mock.Mock(spec=CLIDriver)
        index = generator.IndexGenerator([model_index])
        index.generate_index(clidriver)
        model_index.generate_index.assert_called_with(clidriver)
github aws / aws-cli / tests / unit / customizations / history / test_list.py View on Github external
def setUp(self):
        self.session = mock.Mock(Session)

        self.output_stream_factory = mock.Mock(OutputStreamFactory)

        # MagicMock is needed because it can handle context managers.
        # Normal Mock will throw AttributeErrors
        output_stream_context = mock.MagicMock()
        self.output_stream = mock.Mock()
        output_stream_context.__enter__.return_value = self.output_stream

        self.output_stream_factory.get_output_stream.return_value = \
            output_stream_context

        self.db_reader = mock.Mock(DatabaseRecordReader)
        self.db_reader.iter_all_records.return_value = iter([])

        self.list_cmd = ListCommand(
            self.session, self.db_reader, self.output_stream_factory)
github aws / aws-cli / tests / unit / test_alias.py View on Github external
def test_alias_with_shadow_proxy_command_no_match(self):
        alias_value = 'some-other-command'
        self.alias_name = 'some-service'

        shadow_proxy_command = mock.Mock(spec=CLICommand)
        shadow_proxy_command.name = 'some-service'

        command_table = self.create_command_table([alias_value])
        parser = self.create_parser(command_table)

        alias_cmd = ServiceAliasCommand(
            self.alias_name, alias_value, self.session, command_table,
            parser, shadow_proxy_command)
        command_table[self.alias_name] = alias_cmd

        alias_cmd([], FakeParsedArgs(command=self.alias_name))
        command_table[alias_value].assert_called_with(
            [], FakeParsedArgs(command=alias_value))
        # Even though it was provided, it should not be called because
        # the alias value did not match the shadow command name.
        self.assertFalse(shadow_proxy_command.called)
github aws / aws-cli / tests / functional / s3 / test_presign_command.py View on Github external
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import datetime

from botocore.compat import urlsplit
from awscli.testutils import BaseAWSCommandParamsTest, mock, temporary_file
from awscli.testutils import create_clidriver


# Values used to fix time.time() and datetime.datetime.utcnow()
# so we know the exact values of the signatures generated.
FROZEN_TIMESTAMP = 1471305652
DEFAULT_EXPIRES = 3600
FROZEN_TIME = mock.Mock(return_value=FROZEN_TIMESTAMP)
FROZEN_DATETIME = mock.Mock(
    return_value=datetime.datetime(2016, 8, 18, 14, 33, 3, 0))


class TestPresignCommand(BaseAWSCommandParamsTest):

    prefix = 's3 presign '

    def enable_addressing_mode_in_config(self, fileobj, mode):
        fileobj.write(
            "[default]\n"
            "s3 =\n"
            "    addressing_style = %s\n" % mode
        )
        fileobj.flush()
        self.environ['AWS_CONFIG_FILE'] = fileobj.name
        self.driver = create_clidriver()
github aws / aws-cli / tests / unit / autocomplete / serverside / test_servercomp.py View on Github external
}
            }
        })
        key = (('aws', 'iam'), 'delete-user-policy', 'policy-name')
        self.completion_data = {
            key: {
                'completions': [{
                    "parameters": {},
                    "service": "iam",
                    "operation": "list_policies",
                    "jp_expr": "Policies[].PolicyName",
                }]
            }
        }
        self.parser = parser.CLIParser(self.index)
        self.mock_client = mock.Mock()
        self.mock_create_client = mock.Mock()
        self.mock_create_client.create_client.return_value = self.mock_client
        self.completion_lookup = FakeCompletionLookup(self.completion_data)
        self.completer = ServerSideCompleter(self.completion_lookup,
                                             self.mock_create_client)