An example on how you can mock things in python.
Let's assume we have the following folder structure:
- and so on, check below in the code
To run the unit tests:
python3 -m unittest discover -p "*test*" -v
If you added a new subfolder in test, you need to also add an empty file called
__init__.py, to be discovered by the command from above.
When adding unit tests, you can enable logging for a specific testa case if you add the following line in the beginning of the test case:
Also, in all unit tests we inject fake response from aws using mock and we also enforce that a method be called with a specific set of params. To see the mock calls made on the boto3(aws) instances you can temporary add the following prints:
This will print all calls made on the aws instances, this way you can verify and add mock expectations in your tests.
In the file below you will notice that we import fake data or Helpers, those things are just strings that we want to return or the call params of a mock method, eg: