A simple Django + MongoDB inventory management application using mongoengine and Django REST Framework to test Keploy integration capabilities using Django and MongoDB. The endpoints available will be:
GET /api/items/- List all itemsPOST /api/items/- Create a new itemGET /api/items/<id>/- Retrieve an item by IDPUT /api/items/<id>/- Update an item by IDDELETE /api/items/<id>/- Delete an item by ID
- Python 3.x
- Django
- mongoengine
- djangorestframework
- Clone the repository and navigate to project directory.
git clone https://github.com/keploy/samples-python.git cd samples-python/django-mongo/django_mongo - Install Keploy.
curl --silent -O -L https://keploy.io/install.sh && source install.sh
- Start MongoDB instance.
docker pull mongo docker run --name mongodb -d -p 27017:27017 -v mongo_data:/data/db -e MONGO_INITDB_ROOT_USERNAME=<username> -e MONGO_INITDB_ROOT_PASSWORD=<password> mongo
- Set up Django appllication.
python3 -m virtualenv venv source venv/bin/activate pip3 install -r requirements.txt - Capture the testcases.
keploy record -c "python3 manage.py runserver" - Generate testcases by making API calls.
# List items # GET /api/items/ curl -X GET http://localhost:8000/api/items/
# Create Item # POST /api/items/ curl -X POST http://localhost:8000/api/items/ \ -H "Content-Type: application/json" \ -d '{ "name": "Gadget C", "quantity": 200, "description": "A versatile gadget with numerous features." }'
# Retrieve Item # GET /api/items/<id>/ curl -X GET http://localhost:8000/api/items/<id>/
# Update Item # PUT /api/items/<id>/ curl -X PUT http://localhost:8000/api/items/6142d21e122bda15f6f87b1d/ \ -H "Content-Type: application/json" \ -d '{ "name": "Updated Widget A", "quantity": 120, "description": "An updated description for Widget A." }'
Replace# Delete Item # DELETE /api/items/<id>/ curl -X DELETE http://localhost:8000/api/items/<id>/
<id>with the actual ID of the item you want to retrieve, update, or delete.
Shut down MongoDB, Keploy doesn't need it during tests.
keploy test -c "python3 manage.py runserver" --delay 10