本文整理汇总了Python中botocore.stub.Stubber.assert_no_pending_responses方法的典型用法代码示例。如果您正苦于以下问题:Python Stubber.assert_no_pending_responses方法的具体用法?Python Stubber.assert_no_pending_responses怎么用?Python Stubber.assert_no_pending_responses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botocore.stub.Stubber
的用法示例。
在下文中一共展示了Stubber.assert_no_pending_responses方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mutating_filters
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [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()
示例2: test_delete_tags
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [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()
示例3: test_operation_without_output
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [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()
示例4: test_multipart_download_with_multiple_parts_and_extra_args
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [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()
示例5: test_table_scan_can_be_stubbed_with_expressions
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
def test_table_scan_can_be_stubbed_with_expressions(self):
table = self.resource.Table('mytable')
filter_expr = Attr('myattr').eq('foo') & (
Attr('myattr2').lte('buzz') | Attr('myattr2').gte('fizz')
)
stubber = Stubber(table.meta.client)
stubber.add_response('scan', dict(Items=list()), expected_params=dict(
TableName='mytable',
FilterExpression=filter_expr
))
with stubber:
response = table.scan(FilterExpression=filter_expr)
self.assertEqual(list(), response['Items'])
stubber.assert_no_pending_responses()
示例6: test_provide_copy_source_client
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
def test_provide_copy_source_client(self):
source_client = self.session.create_client(
's3', 'eu-central-1', aws_access_key_id='foo',
aws_secret_access_key='bar')
source_stubber = Stubber(source_client)
source_stubber.activate()
self.addCleanup(source_stubber.deactivate)
self.add_head_object_response(stubber=source_stubber)
self.add_successful_copy_responses()
call_kwargs = self.create_call_kwargs()
call_kwargs['source_client'] = source_client
future = self.manager.copy(**call_kwargs)
future.result()
# Make sure that all of the responses were properly
# used for both clients.
source_stubber.assert_no_pending_responses()
self.stubber.assert_no_pending_responses()
示例7: TestMturk
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
class TestMturk(BaseSessionTest):
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()
def tearDown(self):
self.stubber.deactivate()
def test_list_hits_aliased(self):
self.stubber.add_response('list_hits_for_qualification_type', {})
self.stubber.add_response('list_hits_for_qualification_type', {})
params = {'QualificationTypeId': 'foo'}
self.client.list_hi_ts_for_qualification_type(**params)
self.client.list_hits_for_qualification_type(**params)
self.stubber.assert_no_pending_responses()
示例8: TestStubber
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
class TestStubber(unittest.TestCase):
def setUp(self):
self.event_emitter = hooks.HierarchicalEmitter()
self.client = mock.Mock()
self.client.meta.events = self.event_emitter
self.client.meta.method_to_api_mapping.get.return_value = 'foo'
self.stubber = Stubber(self.client)
self.validate_parameters_mock = mock.Mock()
self.validate_parameters_patch = mock.patch(
'botocore.stub.validate_parameters', self.validate_parameters_mock)
self.validate_parameters_patch.start()
def tearDown(self):
self.validate_parameters_patch.stop()
def emit_get_response_event(self, model=None, request_dict=None,
signer=None, context=None):
if model is None:
model = mock.Mock()
model.name = 'foo'
handler, response = self.event_emitter.emit_until_response(
event_name='before-call.myservice.foo', model=model,
params=request_dict, request_signer=signer, context=context)
return response
def test_stubber_registers_events(self):
self.event_emitter = mock.Mock()
self.client.meta.events = self.event_emitter
self.stubber.activate()
# This just ensures that we register at the correct event
# and nothing more
self.event_emitter.register_first.assert_called_with(
'before-parameter-build.*.*', mock.ANY, unique_id=mock.ANY)
self.event_emitter.register.assert_called_with(
'before-call.*.*', mock.ANY, unique_id=mock.ANY)
def test_stubber_unregisters_events(self):
self.event_emitter = mock.Mock()
self.client.meta.events = self.event_emitter
self.stubber.activate()
self.stubber.deactivate()
self.event_emitter.unregister.assert_any_call(
'before-parameter-build.*.*', mock.ANY, unique_id=mock.ANY)
self.event_emitter.unregister.assert_any_call(
'before-call.*.*', mock.ANY, unique_id=mock.ANY)
def test_add_response(self):
response = {'foo': 'bar'}
self.stubber.add_response('foo', response)
with self.assertRaises(AssertionError):
self.stubber.assert_no_pending_responses()
def test_add_response_fails_when_missing_client_method(self):
del self.client.foo
with self.assertRaises(ValueError):
self.stubber.add_response('foo', {})
def test_validates_service_response(self):
self.stubber.add_response('foo', {})
self.assertTrue(self.validate_parameters_mock.called)
def test_validate_ignores_response_metadata(self):
service_response = {'ResponseMetadata': {'foo': 'bar'}}
service_model = ServiceModel({
'documentation': '',
'operations': {
'foo': {
'name': 'foo',
'input': {'shape': 'StringShape'},
'output': {'shape': 'StringShape'}
}
},
'shapes': {
'StringShape': {'type': 'string'}
}
})
op_name = service_model.operation_names[0]
output_shape = service_model.operation_model(op_name).output_shape
self.client.meta.service_model = service_model
self.stubber.add_response('TestOperation', service_response)
self.validate_parameters_mock.assert_called_with(
{}, output_shape)
# Make sure service response hasn't been mutated
self.assertEqual(
service_response, {'ResponseMetadata': {'foo': 'bar'}})
def test_validates_on_empty_output_shape(self):
service_model = ServiceModel({
'documentation': '',
'operations': {
'foo': {
'name': 'foo'
}
}
})
#.........这里部分代码省略.........
示例9: TestStubber
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
class TestStubber(unittest.TestCase):
def setUp(self):
session = botocore.session.get_session()
config = botocore.client.Config(signature_version=botocore.UNSIGNED)
self.client = session.create_client('s3', config=config)
self.stubber = Stubber(self.client)
def test_stubber_returns_response(self):
service_response = {'ResponseMetadata': {'foo': 'bar'}}
self.stubber.add_response('list_objects', service_response)
self.stubber.activate()
response = self.client.list_objects(Bucket='foo')
self.assertEqual(response, service_response)
def test_activated_stubber_errors_with_no_registered_stubs(self):
self.stubber.activate()
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
def test_stubber_errors_when_stubs_are_used_up(self):
self.stubber.add_response('list_objects', {})
self.stubber.activate()
self.client.list_objects(Bucket='foo')
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
def test_client_error_response(self):
error_code = "AccessDenied"
error_message = "Access Denied"
self.stubber.add_client_error(
'list_objects', error_code, error_message)
self.stubber.activate()
with self.assertRaises(ClientError):
self.client.list_objects(Bucket='foo')
def test_expected_params_success(self):
service_response = {}
expected_params = {'Bucket': 'foo'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# This should be called successfully with no errors being thrown
# for mismatching expected params.
response = self.client.list_objects(Bucket='foo')
self.assertEqual(response, service_response)
def test_expected_params_fail(self):
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# This should call should raise an for mismatching expected params.
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
def test_expected_params_mixed_with_errors_responses(self):
# Add an error response
error_code = "AccessDenied"
error_message = "Access Denied"
self.stubber.add_client_error(
'list_objects', error_code, error_message)
# Add a response with incorrect expected params
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# The first call should throw and error as expected.
with self.assertRaises(ClientError):
self.client.list_objects(Bucket='foo')
# The second call should throw an error for unexpected parameters
with self.assertRaisesRegexp(StubResponseError, 'Expected parameters'):
self.client.list_objects(Bucket='foo')
def test_can_continue_to_call_after_expected_params_fail(self):
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# Throw an error for unexpected parameters
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
# The stubber should still have the responses queued up
# even though the original parameters did not match the expected ones.
self.client.list_objects(Bucket='bar')
self.stubber.assert_no_pending_responses()
def test_still_relies_on_param_validation_with_expected_params(self):
#.........这里部分代码省略.........
示例10: TestStubber
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
#.........这里部分代码省略.........
'list_objects', error_code, error_message)
# Add a response with incorrect expected params
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# The first call should throw and error as expected.
with self.assertRaises(ClientError):
self.client.list_objects(Bucket='foo')
# The second call should throw an error for unexpected parameters
with self.assertRaisesRegexp(StubResponseError, 'Expected parameters'):
self.client.list_objects(Bucket='foo')
def test_can_continue_to_call_after_expected_params_fail(self):
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# Throw an error for unexpected parameters
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
# The stubber should still have the responses queued up
# even though the original parameters did not match the expected ones.
self.client.list_objects(Bucket='bar')
self.stubber.assert_no_pending_responses()
def test_still_relies_on_param_validation_with_expected_params(self):
service_response = {}
expected_params = {'Buck': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# Throw an error for invalid parameters
with self.assertRaises(ParamValidationError):
self.client.list_objects(Buck='bar')
def test_any_ignores_param_for_validation(self):
service_response = {}
expected_params = {'Bucket': stub.ANY}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.add_response(
'list_objects', service_response, expected_params)
try:
with self.stubber:
self.client.list_objects(Bucket='foo')
self.client.list_objects(Bucket='bar')
except StubAssertionError:
self.fail("stub.ANY failed to ignore parameter for validation.")
def test_mixed_any_and_concrete_params(self):
service_response = {}
expected_params = {'Bucket': stub.ANY, 'Key': 'foo.txt'}
示例11: TestStubber
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
#.........这里部分代码省略.........
'list_objects', error_code, error_message)
# Add a response with incorrect expected params
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# The first call should throw and error as expected.
with self.assertRaises(ClientError):
self.client.list_objects(Bucket='foo')
# The second call should throw an error for unexpected parameters
with self.assertRaisesRegexp(StubResponseError, 'Expected parameters'):
self.client.list_objects(Bucket='foo')
def test_can_continue_to_call_after_expected_params_fail(self):
service_response = {}
expected_params = {'Bucket': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# Throw an error for unexpected parameters
with self.assertRaises(StubResponseError):
self.client.list_objects(Bucket='foo')
# The stubber should still have the responses queued up
# even though the original parameters did not match the expected ones.
self.client.list_objects(Bucket='bar')
self.stubber.assert_no_pending_responses()
def test_still_relies_on_param_validation_with_expected_params(self):
service_response = {}
expected_params = {'Buck': 'bar'}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.activate()
# Throw an error for invalid parameters
with self.assertRaises(ParamValidationError):
self.client.list_objects(Buck='bar')
def test_any_ignores_param_for_validation(self):
service_response = {}
expected_params = {'Bucket': stub.ANY}
self.stubber.add_response(
'list_objects', service_response, expected_params)
self.stubber.add_response(
'list_objects', service_response, expected_params)
try:
with self.stubber:
self.client.list_objects(Bucket='foo')
self.client.list_objects(Bucket='bar')
except StubAssertionError:
self.fail("stub.ANY failed to ignore parameter for validation.")
def test_mixed_any_and_concrete_params(self):
service_response = {}
expected_params = {'Bucket': stub.ANY, 'Key': 'foo.txt'}
示例12: test_bundle_ran_and_output_same
# 需要导入模块: from botocore.stub import Stubber [as 别名]
# 或者: from botocore.stub.Stubber import assert_no_pending_responses [as 别名]
def test_bundle_ran_and_output_same(self):
goal = self.create_goal('apply')
# The local bundle has a payload that will *always* do something
# It's an execute - there is no way for fuselage to skip running it
# So we expect the lambda
self.test_dir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, self.test_dir)
bundle = self.workspace.add_fuselage_bundle(
target=self.workspace.add_local()
)
lambda_zip = os.path.join(os.path.dirname(__file__), 'assets/lambda.zip')
bundle.add_file(
name=os.path.join(self.test_dir, 'lambda.zip'),
source=lambda_zip,
)
fn = self.aws.add_lambda_function(
name='myfunction',
role=self.aws.get_role(name='myrole'),
handler='mymodule.myfunction',
code=bundle.add_output(name=lambda_zip),
)
role_service = goal.get_service(fn.role, 'describe')
fn_service = goal.get_service(fn, 'apply')
role_stubber = Stubber(role_service.client)
role_stubber.add_response(
'list_roles',
service_response={
'Roles': [{
'RoleName': 'myrole',
'Path': '/iam/myrole',
'RoleId': '1234567890123456',
'Arn': '12345678901234567890',
'CreateDate': datetime.datetime.now(),
}],
},
expected_params={},
)
fn_stubber = Stubber(fn_service.client)
fn_stubber.add_response(
'get_function_configuration',
service_response={
'FunctionName': 'myfunction',
'CodeSha256': 'LjWn8H6iob8nXeoTeRwWTGctKEUJb6L6epmiwUQVCr0=',
'Handler': 'mymodule.myfunction',
'Role': '12345678901234567890',
},
expected_params={
'FunctionName': 'myfunction',
},
)
fn_stubber.add_response(
'list_versions_by_function',
service_response={
'Versions': [],
},
expected_params={
'FunctionName': 'myfunction',
},
)
fn_stubber.add_response(
'list_aliases',
service_response={
'Aliases': [],
},
expected_params={
'FunctionName': 'myfunction',
},
)
with role_stubber:
with fn_stubber:
goal.execute()
self.assertEqual(len(goal.get_changes(bundle)), 1)
self.assertEqual(len(goal.get_changes(fn)), 1)
fn_stubber.assert_no_pending_responses()