This application is a simple movie management API built using Python's Sanic framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.
🪄 Dive into the world of Movie CRUD Apps and see how seamlessly Keploy integrated with Sanic and MongoDB. Buckle up, it's gonna be a fun ride! 🎢
Depending on your OS, choose your adventure:
Alright, let's equip ourselves with the latest Keploy binary:
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keployalias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v '"$HOME"'/.keploy-config:/root/.keploy-config -v '"$HOME"'/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy'Now head to the folder of the application and run
-
Navigate your project directory:
cd sample-python/sanic-mongo -
Create a Virtual Environment:
python -m venv venv
-
Activating the Virtual Environment
On Windows:
venv\Scripts\activate
On macOS and Linux:
source venv/bin/activate -
Install the required Python packages:
pip install -r requirements.txt
-
To exit your Virtual Environment:
deactivate
Capture the test-cases-
keploy record -c "python3 server.py"🔥Make some API calls. Postman, Hoppscotch or even curl - take your pick!
Let's make URLs short and sweet:
To generate testcases we just need to make some API calls.
1. Make a POST requests
curl -X "POST" "http://127.0.0.1:8000/add_movie" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"name": "Whiplash"
}' curl -X "POST" "http://127.0.0.1:8000/add_movie" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"name": "Chappie"
}' curl -X "POST" "http://127.0.0.1:8000/add_movie" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8' \
-d '{
"name": "Titanic"
}'2. Make a GET request
In order to see all the movies added to the database, run:
curl -X "GET" "http://127.0.0.1:8000/movies" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8'
3. Make a DELETE request
In order to delete all the movies, run:
curl -X "DELETE" "http://127.0.0.1:8000/movies" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8'You will now see a folder named keploy with your recorded tests.
Time to put things to the test 🧪
keploy test -c "python server.py"Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.😊🚀
Happy coding! ✨👩💻👨💻✨

