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


Python stub.Stubber方法代码示例

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


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

示例1: test_create_fails_existing_rule_set

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_create_fails_existing_rule_set():
    ses = botocore.session.get_session().create_client("ses")
    stubber = Stubber(ses)
    stubber.add_response(
        "describe_active_receipt_rule_set", active_receipt_rule_set_response
    )
    stubber.activate()
    provider._ses = ses
    request = Request("Create", "lists.binx.io")
    response = handler(request, {})
    assert response["Status"] == "FAILED", response["Reason"]
    assert (
        response["Reason"]
        == "active receipt rule set is already set in region eu-west-1 - lists.binx.io"
    )
    stubber.assert_no_pending_responses() 
开发者ID:binxio,项目名称:cfn-ses-provider,代码行数:18,代码来源:test_active_rule_set_provider.py

示例2: test_generate_key_data_success

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_generate_key_data_success(self):
        kms_client = boto3.client('kms')
        key_id = "test"
        encryption_context = {}
        with Stubber(kms_client) as stubber:
            stubber.add_response('generate_data_key', {
            'CiphertextBlob': b'ciphertext',
            'Plaintext': b'plaintext',
            'KeyId': 'string'
        }, expected_params = {
            'KeyId': key_id,
            'EncryptionContext': encryption_context,
            'NumberOfBytes': 1
        })
            key_service = KeyService(kms_client, key_id, encryption_context)
            response = key_service.generate_key_data(1)
        self.assertEqual(response[0], b'plaintext')
        self.assertEqual(response[1], b'ciphertext') 
开发者ID:fugue,项目名称:credstash,代码行数:20,代码来源:key_service_test.py

示例3: test_generate_key_data_error

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_generate_key_data_error(self):
        kms_client = boto3.client('kms')
        key_id = "test"
        encryption_context = {}
        with Stubber(kms_client) as stubber:
            stubber.add_client_error(
                'generate_key_data', 
                'KeyUnavailableException',
                'The request was rejected because the specified CMK was not available. The request can be retried.',
                500,
                expected_params={
                    'KeyId': key_id,
                    'EncryptionContext': encryption_context,
                    'NumberOfBytes': 1
                })
            key_service = KeyService(kms_client, key_id, encryption_context)
            with self.assertRaises(KmsError) as e:
                key_service.generate_key_data(1)
                self.assertEqual(e, KmsError("Could not generate key using KMS key %s (Details: %s)" % (key_id, 'The request was rejected because the specified CMK was not available. The request can be retried.'))) 
开发者ID:fugue,项目名称:credstash,代码行数:21,代码来源:key_service_test.py

示例4: test_decrypt_error

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_decrypt_error(self):
        kms_client = boto3.client('kms')
        key_id = "test"
        encryption_context = {}
        with Stubber(kms_client) as stubber:
            stubber.add_client_error(
                'decrypt',
                'NotFoundException',
                'The request was rejected because the specified entity or resource could not be found.',
                400, 
                expected_params = {
                    'CiphertextBlob': 'encoded_key',
                    'EncryptionContext': encryption_context
            })
            key_service = KeyService(kms_client, key_id, encryption_context)
            with self.assertRaises(KmsError) as e:
                response = key_service.decrypt('encoded_key')
                self.assertEqual(e, KmsError("Decryption error The request was rejected because the specified entity or resource could not be found.")) 
开发者ID:fugue,项目名称:credstash,代码行数:20,代码来源:key_service_test.py

示例5: test_decrypt_invalid_ciphertext_error_no_context

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_decrypt_invalid_ciphertext_error_no_context(self):
        kms_client = boto3.client('kms')
        key_id = "test"
        encryption_context = {}
        with Stubber(kms_client) as stubber:
            stubber.add_client_error(
                'decrypt',
                'InvalidCiphertextException',
                'The request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.',
                400, 
                expected_params = {
                    'CiphertextBlob': 'encoded_key',
                    'EncryptionContext': encryption_context
            })
            key_service = KeyService(kms_client, key_id, encryption_context)
            with self.assertRaises(KmsError) as e:
                msg = ("Could not decrypt hmac key with KMS. The credential may "
                        "require that an encryption context be provided to decrypt "
                        "it.")
                response = key_service.decrypt('encoded_key')
                self.assertEqual(e, KmsError(msg)) 
开发者ID:fugue,项目名称:credstash,代码行数:23,代码来源:key_service_test.py

示例6: test_create_cluster_valid_parameters

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

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

    emr_release = "5.0.0"
    with stubber:
        jobflow_id = cluster_provisioner.start(
            user_username="user",
            user_email="user@example.com",
            identifier="cluster",
            emr_release=emr_release,
            size=3,
            public_key="public-key",
        )

    assert jobflow_id == response["JobFlowId"] 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:21,代码来源:test_provisioners.py

示例7: test_spark_job_add

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_spark_job_add(notebook_maker, spark_job_provisioner):
    notebook = notebook_maker()
    identifier = "test-identifier"
    key = "jobs/%s/%s" % (identifier, notebook.name)

    stubber = Stubber(spark_job_provisioner.s3)
    response = {"Expiration": "whatever", "ETag": "12345", "VersionId": "1.0"}
    expected_params = {
        "Body": notebook,
        "Bucket": settings.AWS_CONFIG["CODE_BUCKET"],
        "Key": key,
    }
    stubber.add_response("put_object", response, expected_params)

    with stubber:
        result = spark_job_provisioner.add(
            identifier=identifier, notebook_file=notebook
        )
        assert result == key 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:21,代码来源:test_provisioners.py

示例8: test_create_no_existing_rule_set

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_create_no_existing_rule_set():
    ses = botocore.session.get_session().create_client("ses")
    stubber = Stubber(ses)
    stubber.add_response(
        "describe_active_receipt_rule_set", no_active_receipt_rule_set_response
    )
    stubber.add_response(
        "set_active_receipt_rule_set",
        no_active_receipt_rule_set_response,
        {"RuleSetName": "lists.binx.io"},
    )
    stubber.activate()
    provider._ses = ses
    request = Request("Create", "lists.binx.io")
    response = handler(request, {})
    assert response["Status"] == "SUCCESS", response["Reason"]
    stubber.assert_no_pending_responses() 
开发者ID:binxio,项目名称:cfn-ses-provider,代码行数:19,代码来源:test_active_rule_set_provider.py

示例9: test_update_receipt_change_region_with_existing_rule_set

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_update_receipt_change_region_with_existing_rule_set():
    ses = botocore.session.get_session().create_client("ses")
    stubber = Stubber(ses)
    stubber.add_response(
        "describe_active_receipt_rule_set", active_receipt_rule_set_response
    )
    stubber.activate()
    provider._ses = ses
    request = Request("Update", "lists.xebia.com")
    request["OldResourceProperties"] = {"Region": "us-east-1"}
    response = handler(request, {})
    assert response["Status"] == "FAILED"
    assert (
        response["Reason"]
        == "active receipt rule set is already set in region eu-west-1 - lists.binx.io"
    )
    stubber.assert_no_pending_responses() 
开发者ID:binxio,项目名称:cfn-ses-provider,代码行数:19,代码来源:test_active_rule_set_provider.py

示例10: test_no_such_identity

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_no_such_identity():
    ses = botocore.session.get_session().create_client("ses", region_name="eu-west-1")
    stubber = Stubber(ses)
    stubber.add_response(
        "get_identity_verification_attributes",
        GetIdentityVerificationAttributesReponse(),
        {"Identities": ["lists.binx.io"]},
    )
    stubber.activate()
    provider._ses = ses
    counter = Counter()
    provider.invoke_lambda = counter.increment

    request = Request("Create", "lists.binx.io", "eu-west-1")
    response = handler(request, ())
    assert response["Status"] == "FAILED", response["Reason"]
    assert not provider.asynchronous
    stubber.assert_no_pending_responses() 
开发者ID:binxio,项目名称:cfn-ses-provider,代码行数:20,代码来源:test_verified_identity_provider.py

示例11: test_refusal_to_overwrite_settings

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_refusal_to_overwrite_settings():
    ses = botocore.session.get_session().create_client("ses", region_name="eu-west-1")
    stubber = Stubber(ses)
    provider._ses = ses

    stubber.add_response(
        "get_identity_notification_attributes",
        GetIdentityNotificationAttributesResponse(attributes),
        {"Identities": ["lists.binx.io"]},
    )
    stubber.activate()
    provider._ses = ses

    request = Request("Create", attributes)
    response = handler(request, ())
    assert response["Status"] == "FAILED"
    stubber.assert_no_pending_responses() 
开发者ID:binxio,项目名称:cfn-ses-provider,代码行数:19,代码来源:test_identity_notifications_provider.py

示例12: test_no_secret

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_no_secret(self):
        app.current_request = Request(
            push,
            {
                "X-GitHub-Event": "push",
                "X-Hub-Signature": "whatever",
                "X-GitHub-Delivery": uuid.uuid4().hex,
            },
        )

        stubber = Stubber(SNS)
        stubber.add_response(
            "list_topics", {"Topics": [{"TopicArn": "arn:foo:bar:123_push"}]}
        )
        stubber.add_response("publish", {"MessageId": "1234"})
        with stubber:
            response = index("123")
        assert response == {"Code": "Ok", "Message": "Webhook received."} 
开发者ID:FussyFox,项目名称:github-webhook-lambda,代码行数:20,代码来源:test_app.py

示例13: test_create_missing_topic

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_create_missing_topic(self):
        app.current_request = Request(
            push,
            {
                "X-GitHub-Event": "comment",
                "X-Hub-Signature": "sha=whatever",
                "X-GitHub-Delivery": uuid.uuid4().hex,
            },
        )

        stubber = Stubber(SNS)
        stubber.add_response(
            "list_topics", {"Topics": [{"TopicArn": "arn:foo:bar:push"}]}
        )
        stubber.add_response("create_topic", {"TopicArn": "arn:foo:baz:123_push"})
        stubber.add_response("publish", {"MessageId": "1234"})

        with stubber:
            response = index("123")
        assert response == {"Code": "Ok", "Message": "Webhook received."} 
开发者ID:FussyFox,项目名称:github-webhook-lambda,代码行数:22,代码来源:test_app.py

示例14: test_adjusts_nothing_when_equal

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test_adjusts_nothing_when_equal(cluster_response):
    ecs = lambda_function.ecs_client()
    stubber = Stubber(ecs)

    describe_services_response = {
        'services': [
            {
                'serviceArn': AGENT_SERVICE_ARN,
                'serviceName': 'AgentService',
                'clusterArn': CLUSTER_ARN,
                'desiredCount': 3,
            }
        ]
    }
    expected_params = {'cluster': 'cluster1', 'services': [AGENT_SERVICE_ARN]}
    stubber.add_response('describe_services', describe_services_response, expected_params)

    expected_params = {'clusters': ['cluster1']}
    stubber.add_response('describe_clusters', cluster_response, expected_params)

    with stubber:
        response = lambda_function.adjust_service_desired_count(ecs, 'cluster1', AGENT_SERVICE_ARN)
        assert response is None 
开发者ID:miketheman,项目名称:ecs-host-service-scale,代码行数:25,代码来源:test_lambda_function.py

示例15: test__create_bucket_fails

# 需要导入模块: from botocore import stub [as 别名]
# 或者: from botocore.stub import Stubber [as 别名]
def test__create_bucket_fails(self, mock_consul):
        """
        Test s3 provisioning fails on bucket creation, and retries up to 4 times
        """
        instance = OpenEdXInstanceFactory()
        instance.s3_access_key = 'test'
        instance.s3_secret_access_key = 'test'
        instance.s3_bucket_name = 'test'
        max_tries = 4
        stubber = Stubber(s3_client)
        for _ in range(max_tries):
            stubber.add_client_error('create_bucket')
        with self.assertLogs('instance.models.instance', level='INFO') as cm:
            with stubber:
                with self.assertRaises(ClientError):
                    instance._create_bucket(max_tries=max_tries)

            base_log_text = (
                'INFO:instance.models.instance:instance={} ({!s:.15}) | Retrying bucket creation'
                ' due to "", attempt %s of {}.'.format(instance.ref.pk, instance.ref.name, max_tries)
            )
            self.assertEqual(
                cm.output,
                [base_log_text % i for i in range(1, max_tries + 1)]
            ) 
开发者ID:open-craft,项目名称:opencraft,代码行数:27,代码来源:test_openedx_storage_mixins.py


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