A sample user data CRUD app to test Keploy integration capabilities using Django and PostgreSQL.
Make the following requests to the respective endpoints -
GET /user/- To get all the data at once.GET /user/uuid/- To get the data of any particular user.POST /user/- To create a new user.PUT /user/uuid/- To update an existing user.DELETE /user/uuid/- To delete an existing user.
git clone https://github.com/keploy/samples-python.git && cd samples-python/django-postgres/django_postgresKeploy 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 -dThis is a one time setup of django application.
python3 -m virtualenv venv
source venv/bin/activate
pip3 install -r requirements.txt
python3 manage.py makemigrations
python3 manage.py migrateThis command will start the recording of API calls using ebpf:-
sudo -E keploy record -c "python3 manage.py runserver"Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
To generate testcases we just need to make some API calls. You can use Postman, Hoppscotch, or simply curl
curl --location 'http://127.0.0.1:8000/user/' \
--header 'Content-Type: application/json' \
--data-raw ' {
"name": "Jane Smith",
"email": "jane.smith@example.com",
"password": "smith567",
"website": "www.janesmith.com"
}'curl --location 'http://127.0.0.1:8000/user/' \
--header 'Content-Type: application/json' \
--data-raw ' {
"name": "John Doe",
"email": "john.doe@example.com",
"password": "john567",
"website": "www.johndoe.com"
}'curl --location 'http://127.0.0.1:8000/user/'This will return all the data saved in the database.
curl --location 'http://127.0.0.1:8000/user/c793c752-ad95-4cff-8cbe-5715a1e8a76e/'curl --location --request PUT 'http://127.0.0.1:8000/user/efbe12df-3cae-4cbc-b045-dc74840aa82b/' \
--header 'Content-Type: application/json' \
--data-raw ' {
"name": "Jane Smith",
"email": "smith.jane@example.com",
"password": "smith567",
"website": "www.smithjane.com"
}'curl --location --request DELETE 'http://127.0.0.1:8000/user/ee2af3fc-0503-4a6a-a452-b7d8c87a085b/'Now both 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 keploy test -c "python3 manage.py runserver" --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 😄