A sample App using flask and redis
- Clone the repository and move to flask-redis folder
- Create a .env file and copy-paste below credentials:
REDIS_HOST=redis
REDIS_PORT=6379
brew install redis
If homebrew is not installed, then go to https://brew.sh/ and install it.
git clone https://github.com/keploy/samples-typescript && cd samples-typescript/flask-redis
# Install the dependencies
pip3 install -r requirements.txt
Let's get started by setting up the Keploy alias with this command:
curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh
There are 2 ways you can run this sample application.
-
Install required packages:
sudo apt-get install -y --no-install-recommends ca-certificates curl
This command installs necessary packages without additional recommended packages.
-
Download CA certificate:
curl -o ca.crt https://raw.githubusercontent.com/keploy/keploy/main/pkg/core/proxy/asset/ca.crt
This command downloads the CA certificate to
ca.crt
. -
Download setup script:
curl -o setup_ca.sh https://raw.githubusercontent.com/keploy/keploy/main/pkg/core/proxy/asset/setup_ca.sh
This command downloads the setup script to
setup_ca.sh
. -
Make the setup script executable:
chmod +x setup_ca.sh
This command changes the permissions of
setup_ca.sh
to make it executable. -
Run the setup script:
source ./setup_ca.sh
This command executes the setup script in the current shell.
-
Start the redis server:
redis-server
This command starts the redis server.
- Start recording tests:
sudo -E env "PATH=$PATH" keploybin record -c 'python3 app.py'
Make API Calls using Hoppscotch, Postman or cURL command. Keploy will capture those calls to generate test suites containing test cases and data mocks.
-
Refer to flask-redis/api.txt to make api calls.
-
Observe terminal output: Let's go ahead and create a few more test cases for different endpoints!
-
Start the application:
python3 app.py
-
Run the recorded tests:
sudo -E env "PATH=$PATH" keploybin test -c 'python3 app.py' --delay 10
-
Observe test run results: Voila!! Our test cases have passed 🌟
Since we have to setup our app using docker(make sure your docker is running)
docker network create keploy-network
We will run the keploy in record mode with docker-compose to start our application:-
keploy record -c "sudo docker-compose up" --containerName "flask-web"
Make API Calls using Hoppscotch, Postman or curl command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.
- Refer to flask-redis/api.txt to make api calls
keploy test -c 'sudo docker-compose up' --containerName "flask-web" --delay 10
Voila!! Our testcases has passed 🌟