A sample user data CRUD app to test Keploy integration capabilities using FastAPI and PostgreSQL.
Make the following requests to the respective endpoints -
GET students/- Get all students.GET students/{id}- Get a student by id.POST students/- Create a student.PUT students/{id}- Update a student by id.DELETE students/{id}- Delete a student by id.
git clone https://github.com/keploy/samples-python.git && cd samples-python/fastapi-postgres
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://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
keploy# Start the application
docker-compose up -dNote: Update the
SQLALCHEMY_DATABASE_URLin thedatabase.pyfile if you want to use a keploy with docker.
This command will start the recording of API calls using ebpf:-
sudo -E PATH=$PATH keploy record -c "uvicorn application.main:app --reload"Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
curl --location 'http://127.0.0.1:8000/students/' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Eva White",
"email": "evawhite@example.com",
"password": "evawhite111"
}'curl --location 'http://127.0.0.1:8000/students/' \
--header 'Content-Type: application/json' \
--data-raw ' {
"name": "John Doe",
"email": "johndoe@example.com",
"password": "johndoe123"
}'curl --location 'http://127.0.0.1:8000/students/'This will return all the data saved in the database.
curl --location 'http://127.0.0.1:8000/students/1'curl --location --request PUT 'http://127.0.0.1:8000/students/2' \
--header 'Content-Type: application/json' \
--data-raw ' {
"name": "John Dow",
"email": "doe.john@example.com",
"password": "johndoe123",
"stream": "Arts"
}'curl --location --request DELETE 'http://127.0.0.1:8000/students/1'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 postgres operations.
Now let's run the application in test mode.
sudo -E PATH=$PATH keploy test -c "uvicorn application.main:app --reload" --delay 10So, no need to setup fake database/apis like Postgres or write mocks for them. Keploy automatically mocks them and, The application thinks it's talking to Postgres 😄