本文整理匯總了Python中botocore.stub.ANY屬性的典型用法代碼示例。如果您正苦於以下問題:Python stub.ANY屬性的具體用法?Python stub.ANY怎麽用?Python stub.ANY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類botocore.stub
的用法示例。
在下文中一共展示了stub.ANY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_response
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def add_response(self, method, service_response, expected_params=None):
"""
Adds a service response to the response queue. This will be validated
against the service model to ensure correctness. It should be noted,
however, that while missing attributes are often considered correct,
your code may not function properly if you leave them out. Therefore
you should always fill in every value you see in a typical response for
your particular request.
:param method: The name of the client method to stub.
:type method: str
:param service_response: A dict response stub. Provided parameters will
be validated against the service model.
:type service_response: dict
:param expected_params: A dictionary of the expected parameters to
be called for the provided service response. The parameters match
the names of keyword arguments passed to that client call. If
any of the parameters differ a ``StubResponseError`` is thrown.
You can use stub.ANY to indicate a particular parameter to ignore
in validation. stub.ANY is only valid for top level params.
"""
self._add_response(method, service_response, expected_params)
示例2: test_map_parameter_grouping
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_map_parameter_grouping():
"""
Test special parameters that have shape of map are recorded
as a list of keys based on `para_whitelist.json`
"""
ddb = session.create_client('dynamodb', region_name='us-west-2')
response = {
'ResponseMetadata': {
'RequestId': REQUEST_ID,
'HTTPStatusCode': 500,
}
}
with Stubber(ddb) as stubber:
stubber.add_response('batch_write_item', response, {'RequestItems': ANY})
ddb.batch_write_item(RequestItems={'table1': [{}], 'table2': [{}]})
subsegment = xray_recorder.current_segment().subsegments[0]
assert subsegment.fault
assert subsegment.http['response']['status'] == 500
aws_meta = subsegment.aws
assert sorted(aws_meta['table_names']) == ['table1', 'table2']
示例3: test_s3_bucket_exists
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_s3_bucket_exists(self):
"""Test s3 bucket exists."""
context = Context(config=self.config)
stubber = Stubber(context.s3_conn)
stubber.add_response(
"head_bucket",
service_response={},
expected_params={
"Bucket": ANY,
}
)
with stubber:
self.assertIsNone(context._s3_bucket_verified)
self.assertTrue(context.s3_bucket_verified)
self.assertTrue(context._s3_bucket_verified)
stubber.assert_no_pending_responses()
示例4: test_s3_bucket_does_not_exist_us_east
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_s3_bucket_does_not_exist_us_east(self):
"""Create S3 bucket when it does not exist."""
context = Context(config=self.config, region='us-east-1')
stubber = Stubber(context.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,
}
)
with stubber:
self.assertIsNone(context._s3_bucket_verified)
self.assertTrue(context.s3_bucket_verified)
self.assertTrue(context._s3_bucket_verified)
stubber.assert_no_pending_responses()
示例5: test_ensure_cfn_bucket_exists
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_ensure_cfn_bucket_exists(self):
"""Test ensure cfn bucket exists."""
session = get_session("us-east-1")
provider = Provider(session)
action = BaseAction(
context=mock_context("mynamespace"),
provider_builder=MockProviderBuilder(provider)
)
stubber = Stubber(action.s3_conn)
stubber.add_response(
"head_bucket",
service_response={},
expected_params={
"Bucket": ANY,
}
)
with stubber:
action.ensure_cfn_bucket()
示例6: test_ensure_cfn_bucket_does_not_exist_us_east
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_ensure_cfn_bucket_does_not_exist_us_east(self):
"""Test ensure cfn bucket does not exist us east."""
session = get_session("us-east-1")
provider = Provider(session)
action = BaseAction(
context=mock_context("mynamespace"),
provider_builder=MockProviderBuilder(provider)
)
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,
}
)
with stubber:
action.ensure_cfn_bucket()
示例7: test_ensure_cfn_bucket_exists
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_ensure_cfn_bucket_exists(self):
session = get_session("us-east-1")
provider = Provider(session)
action = BaseAction(
context=mock_context("mynamespace"),
provider_builder=MockProviderBuilder(provider)
)
stubber = Stubber(action.s3_conn)
stubber.add_response(
"head_bucket",
service_response={},
expected_params={
"Bucket": ANY,
}
)
with stubber:
action.ensure_cfn_bucket()
示例8: test_ensure_cfn_bucket_doesnt_exist_us_east
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_ensure_cfn_bucket_doesnt_exist_us_east(self):
session = get_session("us-east-1")
provider = Provider(session)
action = BaseAction(
context=mock_context("mynamespace"),
provider_builder=MockProviderBuilder(provider)
)
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,
}
)
with stubber:
action.ensure_cfn_bucket()
示例9: test_random_id_can_be_omitted
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_random_id_can_be_omitted(self, stubbed_session):
stubbed_session.stub('apigateway').get_authorizers(
restApiId='rest-api-id').returns({
'items': [{'authorizerUri': self.GOOD_ARN, 'id': 'good'}]})
source_arn = (
'arn:aws:execute-api:us-west-2:1:rest-api-id/authorizers/good'
)
stubbed_session.stub('lambda').add_permission(
Action='lambda:InvokeFunction',
FunctionName='app-dev-name',
# Autogenerated value here.
StatementId=stub.ANY,
Principal='apigateway.amazonaws.com',
SourceArn=source_arn
).returns({})
stubbed_session.activate_stubs()
# Note the omission of the random id.
TypedAWSClient(stubbed_session).add_permission_for_authorizer(
'rest-api-id', self.FUNCTION_ARN
)
stubbed_session.verify_stubs()
示例10: test_add_permission_for_scheduled_event
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_add_permission_for_scheduled_event(stubbed_session):
lambda_client = stubbed_session.stub('lambda')
lambda_client.get_policy(FunctionName='function-arn').returns(
{'Policy': '{}'})
lambda_client.add_permission(
Action='lambda:InvokeFunction',
FunctionName='function-arn',
StatementId=stub.ANY,
Principal='events.amazonaws.com',
SourceArn='rule-arn'
).returns({})
stubbed_session.activate_stubs()
awsclient = TypedAWSClient(stubbed_session)
awsclient.add_permission_for_cloudwatch_event(
'rule-arn', 'function-arn')
stubbed_session.verify_stubs()
示例11: test_add_permission_for_s3_event
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_add_permission_for_s3_event(stubbed_session):
lambda_client = stubbed_session.stub('lambda')
lambda_client.get_policy(FunctionName='function-arn').returns(
{'Policy': '{}'})
lambda_client.add_permission(
Action='lambda:InvokeFunction',
FunctionName='function-arn',
StatementId=stub.ANY,
Principal='s3.amazonaws.com',
SourceArn='arn:aws:s3:::mybucket',
).returns({})
stubbed_session.activate_stubs()
awsclient = TypedAWSClient(stubbed_session)
awsclient.add_permission_for_s3_event(
'mybucket', 'function-arn')
stubbed_session.verify_stubs()
示例12: test_mturk_stubber
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_mturk_stubber(session):
async with session.create_client('mturk', region_name='us-east-1') as client:
with Stubber(client) as stubber:
stubber.add_response('list_hits_for_qualification_type',
_mturk_list_hits_response,
{'QualificationTypeId': ANY})
response = await client.list_hi_ts_for_qualification_type(
QualificationTypeId='string')
assert response == _mturk_list_hits_response
示例13: __repr__
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def __repr__(self):
return '<ANY>'
示例14: test_map_parameter_grouping
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_map_parameter_grouping(loop, recorder):
"""
Test special parameters that have shape of map are recorded
as a list of keys based on `para_whitelist.json`
"""
segment = recorder.begin_segment('name')
response = {
'ResponseMetadata': {
'RequestId': '1234',
'HTTPStatusCode': 500,
}
}
session = aiobotocore.get_session()
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
with Stubber(client) as stubber:
stubber.add_response('batch_write_item', response, {'RequestItems': ANY})
await client.batch_write_item(RequestItems={'table1': [{}], 'table2': [{}]})
subsegment = segment.subsegments[0]
assert subsegment.fault
assert subsegment.http['response']['status'] == 500
aws_meta = subsegment.aws
assert sorted(aws_meta['table_names']) == ['table1', 'table2']
示例15: test_context_missing_not_suppress_exception
# 需要導入模塊: from botocore import stub [as 別名]
# 或者: from botocore.stub import ANY [as 別名]
def test_context_missing_not_suppress_exception(loop, recorder):
xray_recorder.configure(service='test', sampling=False,
context=AsyncContext(loop=loop), context_missing='LOG_ERROR')
session = aiobotocore.get_session()
async with session.create_client('dynamodb', region_name='eu-west-2') as client:
with Stubber(client) as stubber:
stubber.add_client_error('describe_table', expected_params={'TableName': ANY})
with pytest.raises(ClientError):
await client.describe_table(TableName='mytable')