A sample FastAPI-Twilio app to test Keploy integration capabilities using FastAPI and Twilio.
git clone https://github.com/keploy/samples-python.git && cd samples-python/fastapi-twilio
pip3 install coverage
pip3 install -r requirements.txtKeploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release
curl -O https://keploy.io/install.sh && source install.shYou can get your Twilio credentials by signing in to Twilio Console.
Once you get the Twilio Account SID, Auth Token, and Phone Number, modify the .env file with your credentials.
This command will start the recording of API calls:-
keploy record -c "uvicorn main:app"Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
- Replace the place holder below i.e.
YOUR_REGISTERED_PERSONAL_PHONE_NUMBERwith your registered personal phone number that you linked with Twilio.
curl -X 'http://127.0.0.1:8000/send-sms/' \
-H 'Content-Type: application/json' \
-d '{
"Body": "Test",
"To": "<OUR_REGISTERED_PERSONAL_PHONE_NUMBER>"
}'- Replace the place holder below i.e.
SOME_WRONG_PHONE_NUMBERwith any wrong phone number and make the request.
curl -X 'http://127.0.0.1:8000/send-sms/' \
-H 'Content-Type: application/json' \
-d '{
"Body": "Test, testtt, testttttttssss :)",
"To": "<SOME_WRONG_PHONE_NUMBER>",
}'Now all these API calls were captured as editable testcases and written to keploy/tests folder. The keploy directory would also have mocks file that contains all the outputs of Twilio operations.
Now let's run the application in test mode.
keploy test -c "python3 -m uvicorn main:app" --delay 10So, no need to setup fake apis like Twilio or write mocks for them. Keploy automatically mocks them and, The application thinks it's talking to Twilio 😄 . We can notice that for a single API without using Twilio, we got around 89% of coverage :
