This is a Flask-based web application that uses PostgreSQL as its database. The project is containerized using Docker and Docker Compose for easy deployment and management.
The endpoints available will be:
- GET / - Home Route
- GET /users - List all users
- POST /users - Create a new user
- PUT /users/<id> - Update a user
- DELETE /users/<id>/ - Delete a user
- Clone the repository and navigate to project directory.
git clone https://github.com/keploy/samples-python.git
cd samples-python/flask_postgresql_app
- Install Keploy.
curl --silent -O -L https://keploy.io/install.sh && source install.sh
- Build and run the Docker containers:
docker compose up --build
- Access the application:
Once the containers are running, the Flask app will be available at:
http://localhost:5000
- Capture the testcases.
keploy record -c "docker compose up" --container-name "flask_web_app"
- Generate testcases by making API calls.
curl -X GET http://localhost:5000
# Retrieves a list of all users.
# GET /users
curl -X GET http://localhost:5000/users \
# Create a new user by providing a name.
# POST /users
curl -X POST http://localhost:5000/users -H "Content-Type: application/json" -d '{"name": "Harsh"}'
# Retrieve a user by their ID.
# GET /users/<id>
curl -X GET http://localhost:8000/users/<id>/ \
# Update the name of a user by their ID.
# PUT /users/<id>
curl -X PUT http://localhost:5000/users/ -H "Content-Type: application/json" -d '{"name": "Updated Name"}'
```bash
# Delete a user by their ID
# DELETE /
curl -X DELETE http://localhost:5000/users/<id>
Replace `<id>` with the actual ID of the item you want to retrieve, update, or delete.
## Run the testcases
```bash
keploy test -c "docker compose up" --container-name "flask_web_app"