Stubber | A minimal method stub for Swift | Mock library
kandi X-RAY | Stubber Summary
kandi X-RAY | Stubber Summary
A minimal method stub for Swift.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of Stubber
Stubber Key Features
Stubber Examples and Code Snippets
Community Discussions
Trending Discussions on Stubber
QUESTION
I have a S3 function that is defined as follows:
...ANSWER
Answered 2021-Dec-06 at 08:35After calling stubber.add_response("list_objects_v2", list_objects_v2_response)
, you need to call stubber.activate()
in order for the stubber to be used.
QUESTION
I have the following function that I need to test:
...ANSWER
Answered 2021-Jul-07 at 14:43It was suggested to look into https://pypi.org/project/boto3-mocking/ and https://github.com/spulec/moto but due to time constraints I did a more simple workaround.
QUESTION
There are a lot of resources out there for using pytest, Moto, and botocore Stubber to write unit tests.
EDIT. I am rephrasing this question after further investigation:
I have a lambda_function
python script that I want to test with pytest and the Boto Stubber. Inside of lambda_function
I import a ssm_client from another python files (ssm_clt = boto3.client('ssm', region_name=region)
)
The problem is when I setup the pytest like this:
...ANSWER
Answered 2021-Jan-28 at 13:46So I ended up just using the monkeypatch functionality of pytest. This was a lot simpler then trying to patch the Boto 3 client and get it to properly stub. Below is some example code of what I did.
here is the function I want to test. The problem was the AWS API call from within the param_dictionary = setup.get_ssm_parameters()
function never got stubbed correctly. This was not being stubbed because it was outside of the function the test was testing. This resulted in it trying to use the real boto3 client call during testing. All other API calls within the lambda_handler were always stubbed correctly.
QUESTION
self.cf_client = boto3.client('cloudformation')
self.cf_client_stubber = Stubber(self.cf_client)
print(f" cc {type(self.cf_client_stubber)}")
self.cf_client_stubber.add_response("describe_stacks", self.cf_describe_response,
self.cf_describe_params)
self.cf_client_stubber.activate()
stackList = self.cf_client_stubber.describe_stacks(StackName=self.cf_stack_name, NextToken='xyz')
...ANSWER
Answered 2020-Jun-30 at 17:56I have found the solution to this problem.
- When you are calling the method, don't use the stubber. Use the actual boto3 client.
- Put the stubber methods in the order of which the method you are testing methods you will invoke like
add_reponse
. For example, ifdescribe_stacks
is called beforedelete_stack
, then in the test adddescribe_stacks
beforedelete_stack
; otherwise, the methods will not be found.
QUESTION
I am trying to unit test the logic in a AWS Lambda function using mocking. The Lambda finishes it's execution by sending push notifications via AWS Pinpoint. The Lambda also uses AWS SSM Parameter Store. I have been mocking in other Lambdas, with multiple boto3 objects, with moto https://github.com/spulec/moto but there is no Pinpoint implementation in moto at present.
I found a solution in https://stackoverflow.com/a/55527212/839338 which I needed to modify to get it to work. The question it was answering was not about my exact scenario but the answer pointed me to a solution. So I am posting here to document my changes to the solution which I modified and to ask if there is a more elegant way of doing this. I have looked at botocore.stub.Stubber but can't see a way it is better, but I'm willing to be proved wrong.
My code so far:
test.py
...ANSWER
Answered 2020-Apr-25 at 17:41As I said in my comment in response to Bert Blommers answer
"I managed to register an additional service in the Moto-framework for pinpoint create_app() but failed to implement create_segment() as botocore takes "locationName": "application-id" from botocore/data/pinpoint/2016-12-01/service-2.json and then moto\core\responses.py tries to make a regex with it but creates '/v1/apps/{application-id}/segments' which has an invalid hyphen in it"
But I will post my working code for create_app() here for the benefit of other people who read this post.
The package structure is important in that the "pinpoint" package needs to be under one other package.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Stubber
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page