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


Python stub.Stubber类代码示例

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


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

示例1: boto_volume_for_test

def boto_volume_for_test(test, cluster_id):
    """
    Create an in-memory boto3 Volume, avoiding any AWS API calls.
    """
    # Create a session directly rather than allow lazy loading of a default
    # session.
    region_name = u"some-test-region-1"
    s = Boto3Session(
        botocore_session=botocore_get_session(),
        region_name=region_name,
    )
    ec2 = s.resource("ec2", region_name=region_name)
    stubber = Stubber(ec2.meta.client)
    # From this point, any attempt to interact with AWS API should fail with
    # botocore.exceptions.StubResponseError
    stubber.activate()
    volume_id = u"vol-{}".format(random_name(test))
    v = ec2.Volume(id=volume_id)
    tags = []
    if cluster_id is not None:
        tags.append(
            dict(
                Key=CLUSTER_ID_LABEL,
                Value=cluster_id,
            ),
        )
    # Pre-populate the metadata to prevent any attempt to load the metadata by
    # API calls.
    v.meta.data = dict(
        Tags=tags
    )
    return v
开发者ID:ClusterHQ,项目名称:flocker,代码行数:32,代码来源:test_ebs.py

示例2: test_cluster_info

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,代码行数:34,代码来源:test_provisioners.py

示例3: TestRoute53Pagination

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,代码行数:34,代码来源:test_route53.py

示例4: TestIdempotencyToken

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,代码行数:34,代码来源:test_ec2.py

示例5: test_mutating_filters

    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,代码行数:31,代码来源:test_ec2.py

示例6: test_ensure_cfn_bucket_doesnt_exist_us_west

 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,代码行数:26,代码来源:test_base.py

示例7: create_client_sts_stub

 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,代码行数:8,代码来源:test_credentials.py

示例8: test_stop_cluster

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,代码行数:10,代码来源:test_provisioners.py

示例9: TestLogsCommandContext_get_resource_id_from_stack

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,代码行数:54,代码来源:test_logs_context.py

示例10: test_delete_tags

 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,代码行数:8,代码来源:test_ec2.py

示例11: test_spark_job_remove

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,代码行数:13,代码来源:test_provisioners.py

示例12: test_operation_without_output

    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,代码行数:13,代码来源:test_table.py

示例13: test_create_cluster_valid_parameters

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,代码行数:13,代码来源:test_provisioning.py

示例14: setUp

 def setUp(self):
     self.stubber = Stubber(self.client)
     self.get_parameters_response = {
         'Parameters': [
             {
                 'Name': 'ssmkey',
                 'Type': 'String',
                 'Value': 'ssmvalue'
             }
         ],
         'InvalidParameters': [
             'invalidssmparam'
         ]
     }
     self.invalid_get_parameters_response = {
         'InvalidParameters': [
             'ssmkey'
         ]
     }
     self.expected_params = {
         'Names': ['ssmkey'],
         'WithDecryption': True
     }
     self.ssmkey = "ssmkey"
     self.ssmvalue = "ssmvalue"
开发者ID:acmcelwee,项目名称:stacker,代码行数:25,代码来源:test_ssmstore.py

示例15: setUp

 def setUp(self):
     super(TestMturk, self).setUp()
     self.region = 'us-west-2'
     self.client = self.session.create_client(
         'mturk', self.region)
     self.stubber = Stubber(self.client)
     self.stubber.activate()
开发者ID:kyleknap,项目名称:botocore,代码行数:7,代码来源:test_mturk.py


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