How to use the awscli.testutils.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 / functional / sso / test_login.py View on Github external
def setUp(self):
        super(TestLoginCommand, self).setUp()
        self.token_cache_dir = self.files.full_path('token-cache')
        self.token_cache_dir_patch = mock.patch(
            'awscli.customizations.sso.utils.SSO_TOKEN_DIR',
            self.token_cache_dir
        )
        self.token_cache_dir_patch.start()
        self.open_browser_mock = mock.Mock(spec=OpenBrowserHandler)
        self.open_browser_patch = mock.patch(
            'awscli.customizations.sso.utils.OpenBrowserHandler',
            self.open_browser_mock,
        )
        self.open_browser_patch.start()
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)
github aws / aws-cli / tests / functional / gamelift / test_upload_build.py View on Github external
self.assertEqual(
            self.operations_called[0][1],
            {'Name': 'mybuild', 'Version': 'myversion'}
        )

        # Second the credentials are requested.
        self.assertEqual(
            self.operations_called[1][0].name, 'RequestUploadCredentials')
        self.assertEqual(
            self.operations_called[1][1], {'BuildId': 'myid'})

        # The build is then uploaded to S3.
        self.assertEqual(self.operations_called[2][0].name, 'PutObject')
        self.assertEqual(
            self.operations_called[2][1],
            {'Body': mock.ANY, 'Bucket': 'mybucket', 'Key': 'mykey'}
        )

        # Check the output of the command.
        self.assertIn(
            'Successfully uploaded %s to AWS GameLift' % self.files.rootdir,
            stdout)
        self.assertIn('Build ID: myid', stdout)
github aws / aws-cli / tests / functional / test_output.py View on Github external
def setUp(self):
        super(TestOutput, self).setUp()
        self.files = FileCreator()

        self.patch_popen = mock.patch('awscli.utils.Popen')
        self.mock_popen = self.patch_popen.start()

        self.patch_tty = mock.patch('awscli.utils.is_a_tty')
        self.mock_is_a_tty = self.patch_tty.start()
        self.mock_is_a_tty.return_value = True

        self.cmdline = 'ec2 describe-regions'
        self.parsed_response = {
            "Regions": [
                {
                        "Endpoint": "ec2.ap-south-1.amazonaws.com",
                        "RegionName": "ap-south-1"
                },
            ]
        }
        self.expected_content = self.get_expected_content(self.parsed_response)
github aws / aws-cli / tests / unit / test_compat.py View on Github external
    @mock.patch('awscli.compat.is_windows', False)
    @mock.patch('awscli.compat.default_pager', 'less -R')
    def test_non_windows(self):
        kwargs = get_popen_kwargs_for_pager_cmd()
        self.assertEqual({'args': ['less', '-R']}, kwargs)
github aws / aws-cli / tests / unit / customizations / logs / test_tail.py View on Github external
def setUp(self):
        self.mock_now = mock.Mock()
        self.set_now()
        self.timestamp_utils = TimestampUtils(self.mock_now)
github aws / aws-cli / tests / unit / customizations / gamelift / test_getlog.py View on Github external
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)
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(
github aws / aws-cli / tests / unit / autocomplete / local / test_indexer.py View on Github external
def setUp(self):
        self.session = mock.Mock(spec=Session)
        self.aws_command = DummyCommand(
            # The CLIDriver doesn't actually have a ``name`` property,
            # but it should probably be 'aws'.
            command_name=None,
            arg_table={
                'region': DummyArg('region'),
                'endpoint-url': DummyArg('endpoint-url'),
            },
            subcommand_table={
                'ec2': DummyCommand(
                    command_name='ec2',
                    subcommand_table={
                        'describe-instances': DummyCommand(
                            'describe-instances',
                            arg_table={
                                'instance-ids': DummyArg('instance-ids'),
github aws / aws-cli / tests / functional / wizards / test_command.py View on Github external
def setUp(self):
        super(TestRunWizard, self).setUp()
        self.tempdir = tempfile.mkdtemp()
        with cd(self.tempdir):
            os.mkdir('iam')
        self.parsed_responses = [{"Roles": []}]
        self.root_dir_patch = mock.patch(
            'awscli.customizations.wizard.loader.WIZARD_SPEC_DIR',
            self.tempdir
        )
        self.root_dir_patch.start()