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


Python Stubber.add_response方法代码示例

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


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

示例1: test_mutating_filters

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
    def test_mutating_filters(self):
        stubber = Stubber(self.service_resource.meta.client)
        instance_filters = [
            {'Name': 'instance-state-name', 'Values': ['running']}
        ]
        running_instances = self.service_resource.instances.filter(
            Filters=instance_filters
        )

        # This should not impact the already-created filter.
        instance_filters.append(
            {'Name': 'instance-type', 'Values': ['c4.large']}
        )

        stubber.add_response(
            method='describe_instances',
            service_response={
                'Reservations': []
            },
            expected_params={
                'Filters': [{
                    'Name': 'instance-state-name',
                    'Values': ['running']
                }]
            }
        )

        with stubber:
            list(running_instances)

        stubber.assert_no_pending_responses()
开发者ID:boto,项目名称:boto3,代码行数:33,代码来源:test_ec2.py

示例2: TestIdempotencyToken

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
class TestIdempotencyToken(unittest.TestCase):
    def setUp(self):
        self.function_name = "purchase_scheduled_instances"
        self.region = "us-west-2"
        self.session = botocore.session.get_session()
        self.client = self.session.create_client("ec2", self.region)
        self.stubber = Stubber(self.client)
        self.service_response = {}
        self.params_seen = []

        # Record all the parameters that get seen
        self.client.meta.events.register_first("before-call.*.*", self.collect_params, unique_id="TestIdempotencyToken")

    def collect_params(self, model, params, *args, **kwargs):
        self.params_seen.extend(params["body"].keys())

    def test_provided_idempotency_token(self):
        expected_params = {"PurchaseRequests": [{"PurchaseToken": "foo", "InstanceCount": 123}], "ClientToken": ANY}
        self.stubber.add_response(self.function_name, self.service_response, expected_params)

        with self.stubber:
            self.client.purchase_scheduled_instances(
                PurchaseRequests=[{"PurchaseToken": "foo", "InstanceCount": 123}], ClientToken="foobar"
            )
            self.assertIn("ClientToken", self.params_seen)

    def test_insert_idempotency_token(self):
        expected_params = {"PurchaseRequests": [{"PurchaseToken": "foo", "InstanceCount": 123}]}

        self.stubber.add_response(self.function_name, self.service_response, expected_params)

        with self.stubber:
            self.client.purchase_scheduled_instances(PurchaseRequests=[{"PurchaseToken": "foo", "InstanceCount": 123}])
            self.assertIn("ClientToken", self.params_seen)
开发者ID:boto,项目名称:botocore,代码行数:36,代码来源:test_ec2.py

示例3: TestRoute53Pagination

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
class TestRoute53Pagination(unittest.TestCase):
    def setUp(self):
        self.session = botocore.session.get_session()
        self.client = self.session.create_client('route53', 'us-west-2')
        self.stubber = Stubber(self.client)
        # response has required fields
        self.response = {
            'HostedZones': [],
            'Marker': '',
            'IsTruncated': True,
            'MaxItems': '1'
        }
        self.operation_name = 'list_hosted_zones'

    def test_paginate_with_max_items_int(self):
        # Route53 has a string type for MaxItems.  We need to ensure that this
        # still works with integers as the cli auto converts the page size
        # argument to an integer.
        self.stubber.add_response(self.operation_name, self.response)
        paginator = self.client.get_paginator('list_hosted_zones')
        with self.stubber:
            config={'PageSize': 1}
            results = list(paginator.paginate(PaginationConfig=config))
            self.assertTrue(len(results) >= 0)

    def test_paginate_with_max_items_str(self):
        # Route53 has a string type for MaxItems.  We need to ensure that this
        # still works with strings as that's the expected type for this key.
        self.stubber.add_response(self.operation_name, self.response)
        paginator = self.client.get_paginator('list_hosted_zones')
        with self.stubber:
            config={'PageSize': '1'}
            results = list(paginator.paginate(PaginationConfig=config))
            self.assertTrue(len(results) >= 0)
开发者ID:boto,项目名称:botocore,代码行数:36,代码来源:test_route53.py

示例4: test_cluster_info

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
def test_cluster_info(cluster_provisioner):
    cluster_id = 'foo-bar-spam-egs'
    stubber = Stubber(cluster_provisioner.emr)
    response = {
        'Cluster': {
            'MasterPublicDnsName': '1.2.3.4',
            'Status': {
                'State': 'RUNNING',
                'StateChangeReason': {
                    'Code': 'ALL_STEPS_COMPLETED',
                    'Message': 'All steps completed.',
                },
                'Timeline': {
                    'CreationDateTime': datetime(2015, 1, 1),
                    'ReadyDateTime': datetime(2015, 1, 2),
                    'EndDateTime': datetime(2015, 1, 3),
                }
            },
        },
    }
    expected_params = {'ClusterId': cluster_id}
    stubber.add_response('describe_cluster', response, expected_params)

    with stubber:
        info = cluster_provisioner.info(cluster_id)
        assert info == {
            'creation_datetime': datetime(2015, 1, 1),
            'ready_datetime': datetime(2015, 1, 2),
            'end_datetime': datetime(2015, 1, 3),
            'state_change_reason_code': 'ALL_STEPS_COMPLETED',
            'state_change_reason_message': 'All steps completed.',
            'state': 'RUNNING',
            'public_dns': '1.2.3.4',
        }
开发者ID:washort,项目名称:telemetry-analysis-service,代码行数:36,代码来源:test_provisioners.py

示例5: test_ensure_cfn_bucket_doesnt_exist_us_west

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
 def test_ensure_cfn_bucket_doesnt_exist_us_west(self):
     session = get_session("us-west-1")
     provider = Provider(session)
     action = BaseAction(
         context=mock_context("mynamespace"),
         provider_builder=MockProviderBuilder(provider, region="us-west-1")
     )
     stubber = Stubber(action.s3_conn)
     stubber.add_client_error(
         "head_bucket",
         service_error_code="NoSuchBucket",
         service_message="Not Found",
         http_status_code=404,
     )
     stubber.add_response(
         "create_bucket",
         service_response={},
         expected_params={
             "Bucket": ANY,
             "CreateBucketConfiguration": {
                 "LocationConstraint": "us-west-1",
             }
         }
     )
     with stubber:
         action.ensure_cfn_bucket()
开发者ID:acmcelwee,项目名称:stacker,代码行数:28,代码来源:test_base.py

示例6: test_delete_tags

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
 def test_delete_tags(self):
     stubber = Stubber(self.instance_resource.meta.client)
     stubber.add_response('delete_tags', {})
     stubber.activate()
     response = self.instance_resource.delete_tags(Tags=[{'Key': 'foo'}])
     stubber.assert_no_pending_responses()
     self.assertEqual(response, {})
     stubber.deactivate()
开发者ID:boto,项目名称:boto3,代码行数:10,代码来源:test_ec2.py

示例7: create_client_sts_stub

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
 def create_client_sts_stub(service, *args, **kwargs):
     client = _original_create_client(service, *args, **kwargs)
     stub = Stubber(client)
     response = self.create_assume_role_response(expected_creds)
     self.actual_client_region = client.meta.region_name
     stub.add_response('assume_role', response)
     stub.activate()
     return client
开发者ID:boto,项目名称:botocore,代码行数:10,代码来源:test_credentials.py

示例8: test_stop_cluster

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
def test_stop_cluster(cluster_provisioner):
    stubber = Stubber(cluster_provisioner.emr)
    response = {}
    expected_params = {
        'JobFlowIds': ['12345'],
    }
    stubber.add_response('terminate_job_flows', response, expected_params)

    with stubber:
        cluster_provisioner.stop(jobflow_id='12345')
开发者ID:washort,项目名称:telemetry-analysis-service,代码行数:12,代码来源:test_provisioners.py

示例9: TestLogsCommandContext_get_resource_id_from_stack

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
class TestLogsCommandContext_get_resource_id_from_stack(TestCase):

    def setUp(self):

        self.real_client = botocore.session.get_session().create_client('cloudformation', region_name="us-east-1")
        self.cfn_client_stubber = Stubber(self.real_client)

        self.logical_id = "name"
        self.stack_name = "stackname"
        self.physical_id = "myid"

    def test_must_get_from_cfn(self):

        expected_params = {
            "StackName": self.stack_name,
            "LogicalResourceId": self.logical_id
        }

        mock_response = {
            "StackResourceDetail": {
                "PhysicalResourceId": self.physical_id,
                "LogicalResourceId": self.logical_id,
                "ResourceType": "AWS::Lambda::Function",
                "ResourceStatus": "UPDATE_COMPLETE",
                "LastUpdatedTimestamp": "2017-07-28T23:34:13.435Z"
            }
        }

        self.cfn_client_stubber.add_response("describe_stack_resource", mock_response, expected_params)

        with self.cfn_client_stubber:
            result = LogsCommandContext._get_resource_id_from_stack(self.real_client,
                                                                    self.stack_name,
                                                                    self.logical_id)

        self.assertEquals(result, self.physical_id)

    def test_must_handle_resource_not_found(self):
        errmsg = "Something went wrong"
        errcode = "SomeException"

        self.cfn_client_stubber.add_client_error("describe_stack_resource",
                                                 service_error_code=errcode,
                                                 service_message=errmsg)
        expected_error_msg = "An error occurred ({}) when calling the DescribeStackResource operation: {}".format(
            errcode, errmsg)

        with self.cfn_client_stubber:
            with self.assertRaises(UserException) as context:
                LogsCommandContext._get_resource_id_from_stack(self.real_client,
                                                               self.stack_name,
                                                               self.logical_id)

            self.assertEquals(expected_error_msg, str(context.exception))
开发者ID:Frameio,项目名称:aws-sam-cli,代码行数:56,代码来源:test_logs_context.py

示例10: set_cloudformation_stubber_for_client

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
    def set_cloudformation_stubber_for_client(self, redshift_client):
        stubber = Stubber(redshift_client)
        with open(self.resource_path+'/DescribeSourceClusterResponse.json') as describe_source_response:
            describe_source_cluster_response = json.load(describe_source_response)
        expected_source_params = {'ClusterIdentifier': 'rscopyunloadtest3-redshiftclustersource-1so4t2ip0ei3a'}
        stubber.add_response('describe_clusters', describe_source_cluster_response, expected_source_params)

        with open(self.resource_path+'/DescribeTargetClusterResponse.json') as describe_target_response:
            describe_target_cluster_response = json.load(describe_target_response)
        expected_target_params = {'ClusterIdentifier': 'rscopyunloadtest3-redshiftclustertarget-oaw35zvu02h'}
        stubber.add_response('describe_clusters', describe_target_cluster_response, expected_target_params)
        stubber.activate()
开发者ID:awslabs,项目名称:amazon-redshift-utils,代码行数:14,代码来源:stack_parameters_builder_unittests.py

示例11: test_operation_without_output

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
    def test_operation_without_output(self):
        table = self.resource.Table('mytable')
        stubber = Stubber(table.meta.client)
        stubber.add_response('tag_resource', {})
        arn = 'arn:aws:dynamodb:us-west-2:123456789:table/mytable'

        with stubber:
            table.meta.client.tag_resource(
                ResourceArn=arn,
                Tags=[{'Key': 'project', 'Value': 'val'}]
            )

        stubber.assert_no_pending_responses()
开发者ID:boto,项目名称:boto3,代码行数:15,代码来源:test_table.py

示例12: test_spark_job_remove

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
def test_spark_job_remove(spark_job_provisioner):
    key = 's3://test/test-notebook.ipynb'

    stubber = Stubber(spark_job_provisioner.s3)
    response = {'DeleteMarker': False}
    expected_params = {
        'Bucket': settings.AWS_CONFIG['CODE_BUCKET'],
        'Key': key,
    }
    stubber.add_response('delete_object', response, expected_params)

    with stubber:
        spark_job_provisioner.remove(key)
开发者ID:washort,项目名称:telemetry-analysis-service,代码行数:15,代码来源:test_provisioners.py

示例13: test_create_cluster_valid_parameters

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
def test_create_cluster_valid_parameters():
    """Test that the parameters passed down to run_job_flow are valid"""

    stubber = Stubber(emr)
    response = {'JobFlowId': 'job-flow-id'}
    stubber.add_response('run_job_flow', response)

    emr_release = settings.AWS_CONFIG['EMR_RELEASES'][0]
    params = ['[email protected]', 'cluster', 3, 'public-key', emr_release]
    with stubber:
        job_flow_id = provisioning.cluster_start(*params)

    assert job_flow_id == response['JobFlowId']
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:15,代码来源:test_provisioning.py

示例14: test_spark_job_get

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
def test_spark_job_get(spark_job_provisioner):
    key = 's3://test/test-notebook.ipynb'

    stubber = Stubber(spark_job_provisioner.s3)
    response = {
        'Body': 'content',
    }
    expected_params = {
        'Bucket': settings.AWS_CONFIG['CODE_BUCKET'],
        'Key': key,
    }
    stubber.add_response('get_object', response, expected_params)

    with stubber:
        result = spark_job_provisioner.get(key)
        assert result == response
开发者ID:washort,项目名称:telemetry-analysis-service,代码行数:18,代码来源:test_provisioners.py

示例15: test_multipart_download_with_multiple_parts_and_extra_args

# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import add_response [as 别名]
 def test_multipart_download_with_multiple_parts_and_extra_args(self):
     client = Session().create_client('s3')
     stubber = Stubber(client)
     response_body = b'foobarbaz'
     response = {'Body': six.BytesIO(response_body)}
     expected_params = {
         'Range': mock.ANY, 'Bucket': mock.ANY, 'Key': mock.ANY,
         'RequestPayer': 'requester'}
     stubber.add_response('get_object', response, expected_params)
     stubber.activate()
     downloader = MultipartDownloader(
         client, TransferConfig(), InMemoryOSLayer({}), SequentialExecutor)
     downloader.download_file(
         'bucket', 'key', 'filename', len(response_body),
         {'RequestPayer': 'requester'})
     stubber.assert_no_pending_responses()
开发者ID:Armin-Smailzade,项目名称:boto3,代码行数:18,代码来源:test_transfer.py


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