当前位置: 首页>>代码示例>>Python>>正文


Python Mock.client方法代码示例

本文整理汇总了Python中mock.Mock.client方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.client方法的具体用法?Python Mock.client怎么用?Python Mock.client使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mock.Mock的用法示例。


在下文中一共展示了Mock.client方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sagemaker_session_stopped

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
def sagemaker_session_stopped():
    boto_mock = Mock(name='boto_session')
    boto_mock.client('logs').describe_log_streams.return_value = DEFAULT_LOG_STREAMS
    boto_mock.client('logs').get_log_events.side_effect = DEFAULT_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.return_value = STOPPED_DESCRIBE_JOB_RESULT
    return ims
开发者ID:cheesama,项目名称:sagemaker-python-sdk,代码行数:9,代码来源:test_session.py

示例2: test_ecr_login_needed

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
def test_ecr_login_needed(check_output):
    session_mock = Mock()

    token = 'very-secure-token'
    token_response = 'AWS:%s' % token
    b64_token = base64.b64encode(token_response.encode('utf-8'))
    response = {
        u'authorizationData':
            [
                {
                    u'authorizationToken': b64_token,
                    u'proxyEndpoint': u'https://520713654638.dkr.ecr.us-east-1.amazonaws.com'
                }
            ],
        'ResponseMetadata':
            {
                'RetryAttempts': 0,
                'HTTPStatusCode': 200,
                'RequestId': '25b2ac63-36bf-11e8-ab6a-e5dc597d2ad9',
            }
    }
    session_mock.client('ecr').get_authorization_token.return_value = response
    image = '520713654638.dkr.ecr.us-east-1.amazonaws.com/image-i-need:1.1'
    sagemaker.local.image._ecr_login_if_needed(session_mock, image)

    expected_command = 'docker login -u AWS -p %s https://520713654638.dkr.ecr.us-east-1.amazonaws.com' % token

    check_output.assert_called_with(expected_command, shell=True)
    session_mock.client('ecr').get_authorization_token.assert_called_with(registryIds=['520713654638'])
开发者ID:duasahil8,项目名称:sagemaker-python-sdk,代码行数:31,代码来源:test_image.py

示例3: sagemaker_session_full_lifecycle

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
def sagemaker_session_full_lifecycle():
    boto_mock = Mock(name='boto_session')
    boto_mock.client('logs').describe_log_streams.side_effect = LIFECYCLE_LOG_STREAMS
    boto_mock.client('logs').get_log_events.side_effect = STREAM_LOG_EVENTS
    ims = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())
    ims.sagemaker_client.describe_training_job.side_effect = [IN_PROGRESS_DESCRIBE_JOB_RESULT,
                                                              IN_PROGRESS_DESCRIBE_JOB_RESULT,
                                                              COMPLETED_DESCRIBE_JOB_RESULT]
    return ims
开发者ID:cheesama,项目名称:sagemaker-python-sdk,代码行数:11,代码来源:test_session.py

示例4: test_should_not_include_files_outside_config_directory

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_should_not_include_files_outside_config_directory(self):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = 'svn://url/for/configuration/repository'
        mock_svn_service.path_to_config = '/config'
        mock_svn_service.client = Mock()
        mock_info = Mock()

        mock_path_object_1 = Mock()
        mock_path_object_1.path = '/config/foo'
        mock_path_object_1.action = 'A'

        mock_path_object_2 = Mock()
        mock_path_object_2.path = '/XXXXXX/bar'
        mock_path_object_2.action = 'A'

        mock_path_object_3 = Mock()
        mock_path_object_3.path = '/XXX/foobar'
        mock_path_object_3.action = 'A'

        mock_info.changed_paths = [mock_path_object_1, mock_path_object_2, mock_path_object_3]
        mock_svn_service.get_logs_for_revision.return_value = [mock_info]

        actual = SvnService.get_changed_paths_with_action(mock_svn_service, '1980')

        self.assertEqual([('foo', 'A')], actual)
开发者ID:yadt,项目名称:yadt-config-rpm-maker,代码行数:28,代码来源:svnservice_tests.py

示例5: test_sendEvent_should_use_kwargs_as_event_items

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_sendEvent_should_use_kwargs_as_event_items(self):
        mock_broadcaster = Mock(WampBroadcaster)
        mock_broadcaster.target = "broadcaster-target"
        mock_broadcaster.logger = Mock()
        mock_broadcaster.client = Mock()

        WampBroadcaster._sendEvent(
            mock_broadcaster,
            "event-id",
            "event-data",
            tracking_id="tracking-id",
            target="target",
            state="foobar",
            bar="baz",
        )

        actual_call = mock_broadcaster.client.publish.call_args
        self.assertEqual(
            call(
                "target",
                {
                    "payload": "event-data",
                    "type": "event",
                    "id": "event-id",
                    "tracking_id": "tracking-id",
                    "target": "target",
                    "state": "foobar",
                    "bar": "baz",
                },
            ),
            actual_call,
        )
开发者ID:yadt,项目名称:yadtbroadcast-client,代码行数:34,代码来源:yadtbroadcastclient_tests.py

示例6: test_check_connection_should_return_true_when_link_is_up

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_check_connection_should_return_true_when_link_is_up(self):
        mock_broadcaster = Mock(WampBroadcaster)
        mock_broadcaster.logger = Mock()
        mock_broadcaster.url = "ws://broadcaster"
        mock_broadcaster.client = Mock()

        self.assertEqual(WampBroadcaster._check_connection(mock_broadcaster), True)
        self.assertFalse(hasattr(mock_broadcaster, "not_connected_warning_sent"))
开发者ID:yadt,项目名称:yadtbroadcast-client,代码行数:10,代码来源:yadtbroadcastclient_tests.py

示例7: test_should_set_the_client_to_none

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_should_set_the_client_to_none(self, mock_log):
        mock_receiver = Mock(Receiver)
        mock_broadcaster = Mock()
        mock_broadcaster.client = 'Test client'
        mock_receiver.broadcaster = mock_broadcaster

        Receiver.onConnectionLost(mock_receiver, 'Spam eggs.')

        self.assertEquals(None, mock_broadcaster.client)
开发者ID:andante-project,项目名称:yadtreceiver,代码行数:11,代码来源:yadtreceiver_tests.py

示例8: test_successfully_adds_kinesis_subscription

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
 def test_successfully_adds_kinesis_subscription(self, mocked_session):
     _mocked_lambda = Mock()
     _mocked_session = Mock()
     _mocked_session.client = Mock()
     _mocked_session.client.return_value = _mocked_lambda
     mocked_session.return_value = _mocked_session
     conf = config.Config(path.dirname(__file__),
                          config_file=path.join(EX_CONFIG, 'lambda-with-subscription.json'))
     subscribers.create_subscriptions(conf, None)
     nt.assert_equals(True, _mocked_lambda.create_event_source_mapping.called)
开发者ID:timpitman,项目名称:lambda-uploader,代码行数:12,代码来源:test_subscribers.py

示例9: test_should_raise_exception_when_pysvn_client_fails_to_log

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_should_raise_exception_when_pysvn_client_fails_to_log(self):

        mock_svn_service = Mock(SvnService)
        mock_svn_service.config_url = 'svn://url/for/configuration/repository/config'
        mock_svn_service.base_url = 'svn://url/for/configuration/repository'
        mock_svn_service.path_to_config = '/config'
        mock_svn_service.client = Mock()
        mock_svn_service.client.log.side_effect = Exception("Aaarrrgggghh...")

        self.assertRaises(SvnServiceException, SvnService.get_logs_for_revision, mock_svn_service, '1980')
开发者ID:yadt,项目名称:yadt-config-rpm-maker,代码行数:12,代码来源:svnservice_tests.py

示例10: test___init__

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
 def test___init__(self):
     parser = common.CliOptions().create_optparser(False)
     common.AuthedCommandsBase.debug = True
     dbaas = Mock()
     dbaas.authenticate = Mock(return_value=None)
     dbaas.client = Mock()
     dbaas.client.auth_token = Mock()
     dbaas.client.service_url = Mock()
     dbaas.client.authenticate_with_token = Mock()
     common.AuthedCommandsBase._get_client = Mock(return_value=dbaas)
     authed_cmd = common.AuthedCommandsBase(parser)
开发者ID:neumerance,项目名称:cloudcapped,代码行数:13,代码来源:test_common.py

示例11: test_download_file

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
def test_download_file():
    boto_mock = Mock(name='boto_session')
    boto_mock.client('sts').get_caller_identity.return_value = {'Account': '123'}
    bucket_mock = Mock()
    boto_mock.resource('s3').Bucket.return_value = bucket_mock
    session = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())

    sagemaker_container = _SageMakerContainer('local', 2, 'my-image', sagemaker_session=session)
    sagemaker_container._download_file(BUCKET_NAME, '/prefix/path/file.tar.gz', '/tmp/file.tar.gz')

    bucket_mock.download_file.assert_called_with('prefix/path/file.tar.gz', '/tmp/file.tar.gz')
开发者ID:duasahil8,项目名称:sagemaker-python-sdk,代码行数:13,代码来源:test_image.py

示例12: test_should_return_logs_for_revision

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_should_return_logs_for_revision(self):
        mock_svn_service = Mock(SvnService)
        mock_svn_service.base_url = 'svn://url/for/configuration/repository'
        mock_svn_service.path_to_config = '/config'
        mock_svn_service.client = Mock()
        mock_logs = Mock()
        mock_svn_service.client.log.return_value = mock_logs

        actual = SvnService.get_logs_for_revision(mock_svn_service, '1980')

        self.assertEqual(mock_logs, actual)
开发者ID:yadt,项目名称:yadt-config-rpm-maker,代码行数:13,代码来源:svnservice_tests.py

示例13: sagemaker_session

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
def sagemaker_session():
    boto_mock = Mock(name='boto_session', region_name=REGION)
    boto_mock.client('sts').get_caller_identity.return_value = {'Account': '123'}
    boto_mock.resource('s3').Bucket(BUCKET_NAME).objects.filter.return_value = []

    sms = sagemaker.Session(boto_session=boto_mock, sagemaker_client=Mock())

    sms.default_bucket = Mock(name='default_bucket', return_value=BUCKET_NAME)
    sms.expand_role = Mock(return_value=EXPANDED_ROLE)

    return sms
开发者ID:duasahil8,项目名称:sagemaker-python-sdk,代码行数:13,代码来源:test_image.py

示例14: test_attach

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
    def test_attach(self):
        i = BaseIterator(name="test123", priority=111, classname="com.test.Class")

        it_s = i.get_iterator_setting()
        scopes = set([IteratorScope.SCAN, IteratorScope.MINC, IteratorScope.MAJC])

        conn = Mock()
        conn.client = Mock()
        conn.client.attachIterator = Mock()
        conn.login = "Login"

        i.attach(conn, "mytable123", scopes)
        conn.client.attachIterator.assert_called_with("Login", "mytable123", it_s, scopes)
开发者ID:rweeks,项目名称:pyaccumulo,代码行数:15,代码来源:test_iterator.py

示例15: test_successfully_updates_kinesis_subscription

# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import client [as 别名]
 def test_successfully_updates_kinesis_subscription(self, mocked_session):
     resonse = {"Error": {"Code": "ResourceConflictException", "Message": ""}}
     err = botocore.exceptions.ClientError(resonse, "create_event_source_mapping")
     _mocked_lambda = Mock()
     _mocked_lambda.create_event_source_mapping.side_effect = err
     _mocked_lambda.list_event_source_mappings.return_value = {
         'EventSourceMappings': [{'UUID': 'myuuid'}]
     }
     _mocked_session = Mock()
     _mocked_session.client = Mock()
     _mocked_session.client.return_value = _mocked_lambda
     mocked_session.return_value = _mocked_session
     conf = config.Config(path.dirname(__file__),
                          config_file=path.join(EX_CONFIG, 'lambda-with-subscription.json'))
     subscribers.create_subscriptions(conf, None)
     nt.assert_equals(True, _mocked_lambda.update_event_source_mapping.called)
开发者ID:timpitman,项目名称:lambda-uploader,代码行数:18,代码来源:test_subscribers.py


注:本文中的mock.Mock.client方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。