Python botocore.stub.ANY Examples
The following are 30
code examples of botocore.stub.ANY().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
botocore.stub
, or try the search function
.
Example #1
Source File: test_botocore.py From aws-xray-sdk-python with Apache License 2.0 | 7 votes |
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']
Example #2
Source File: test_context.py From runway with Apache License 2.0 | 7 votes |
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()
Example #3
Source File: test_base.py From runway with Apache License 2.0 | 7 votes |
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()
Example #4
Source File: test_base.py From runway with Apache License 2.0 | 7 votes |
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()
Example #5
Source File: test_base.py From stacker with BSD 2-Clause "Simplified" License | 7 votes |
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()
Example #6
Source File: stub.py From aws-builders-fair-projects with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: test_context.py From runway with Apache License 2.0 | 6 votes |
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()
Example #8
Source File: test_base.py From stacker with BSD 2-Clause "Simplified" License | 6 votes |
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()
Example #9
Source File: test_awsclient.py From chalice with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: test_awsclient.py From chalice with Apache License 2.0 | 6 votes |
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()
Example #11
Source File: test_awsclient.py From chalice with Apache License 2.0 | 6 votes |
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()
Example #12
Source File: test_base.py From stacker with BSD 2-Clause "Simplified" License | 5 votes |
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()
Example #13
Source File: test_awsclient.py From chalice with Apache License 2.0 | 5 votes |
def should_call_add_permission(self, lambda_stub, statement_id=stub.ANY): lambda_stub.add_permission( Action='lambda:InvokeFunction', FunctionName='name', StatementId=statement_id, Principal='apigateway.amazonaws.com', SourceArn='arn:aws:execute-api:us-west-2:123:rest-api-id/*', ).returns({})
Example #14
Source File: test_awsclient.py From chalice with Apache License 2.0 | 5 votes |
def should_call_add_permission(self, lambda_stub, statement_id=stub.ANY): lambda_stub.add_permission( Action='lambda:InvokeFunction', FunctionName='name', StatementId=statement_id, Principal='apigateway.amazonaws.com', SourceArn='arn:aws:execute-api:us-west-2:123:websocket-api-id/*', ).returns({})
Example #15
Source File: test_acm.py From runway with Apache License 2.0 | 5 votes |
def gen_change_batch(changes=ANY, comment=ANY): """Generate expected change batch.""" return { 'Comment': comment, 'Changes': changes }
Example #16
Source File: test_context.py From runway with Apache License 2.0 | 5 votes |
def test_s3_bucket_does_not_exist_us_west(self): """Create S3 bucket with loc constraints when it does not exist.""" region = 'us-west-1' context = Context(config=self.config, region=region) 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, "CreateBucketConfiguration": { "LocationConstraint": region, } } ) 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()
Example #17
Source File: stub.py From aws-builders-fair-projects with Apache License 2.0 | 5 votes |
def __repr__(self): return '<ANY>'
Example #18
Source File: stub.py From aws-extender with MIT License | 5 votes |
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)
Example #19
Source File: stubs.py From ray with Apache License 2.0 | 5 votes |
def describe_no_security_groups(ec2_client_stub): ec2_client_stub.add_response( "describe_security_groups", expected_params={"Filters": ANY}, service_response={})
Example #20
Source File: stub.py From bash-lambda-layer with MIT License | 5 votes |
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)
Example #21
Source File: stub.py From faces with GNU General Public License v2.0 | 5 votes |
def __repr__(self): return '<ANY>'
Example #22
Source File: stub.py From faces with GNU General Public License v2.0 | 5 votes |
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)
Example #23
Source File: stub.py From faces with GNU General Public License v2.0 | 5 votes |
def __repr__(self): return '<ANY>'
Example #24
Source File: stub.py From faces with GNU General Public License v2.0 | 5 votes |
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)
Example #25
Source File: stub.py From deepWordBug with Apache License 2.0 | 5 votes |
def __repr__(self): return '<ANY>'
Example #26
Source File: stub.py From deepWordBug with Apache License 2.0 | 5 votes |
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)
Example #27
Source File: stub.py From bash-lambda-layer with MIT License | 5 votes |
def __repr__(self): return '<ANY>'
Example #28
Source File: stub.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def __repr__(self): return '<ANY>'
Example #29
Source File: stub.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
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)
Example #30
Source File: stub.py From AWS-Transit-Gateway-Demo-MultiAccount with MIT License | 5 votes |
def __repr__(self): return '<ANY>'