From 34fa17b6bc1ec9b136d6f55dddd106d48957a7ea Mon Sep 17 00:00:00 2001 From: Swapnoneel Saha Date: Tue, 23 Apr 2024 17:47:28 +0530 Subject: [PATCH 1/5] Added Flask+Mongo app with unit tests, keploy tests and test coverage report Signed-off-by: Swapnoneel Saha --- flask-mongo-docker/Dockerfile | 17 + flask-mongo-docker/README.md | 600 ++++++++++++++++++ flask-mongo-docker/app.py | 42 ++ flask-mongo-docker/docker-compose.yml | 29 + .../keploy/test-set-1/config.yaml | 167 +++++ .../keploy/test-set-1/mocks.yaml | 64 ++ .../keploy/test-set-1/test-1.yaml | 38 ++ .../keploy/test-set-1/test-2.yaml | 34 + .../keploy/testReports/report-1.yaml | 181 ++++++ flask-mongo-docker/requirements.txt | 4 + flask-mongo-local/.coverage | Bin 0 -> 53248 bytes flask-mongo-local/.coveragerc | 4 + .../__pycache__/app.cpython-310.pyc | Bin 0 -> 2049 bytes .../test_app.cpython-310-pytest-8.1.1.pyc | Bin 0 -> 2471 bytes .../__pycache__/test_app.cpython-310.pyc | Bin 0 -> 2358 bytes .../test_keploy.cpython-310-pytest-8.1.1.pyc | Bin 0 -> 657 bytes flask-mongo-local/app.py | 56 ++ .../reports/test-run-0/test-set-0-report.yaml | 446 +++++++++++++ .../reports/test-run-1/test-set-0-report.yaml | 446 +++++++++++++ .../keploy/test-set-0/mocks.yaml | 319 ++++++++++ .../keploy/test-set-0/tests/test-1.yaml | 66 ++ .../keploy/test-set-0/tests/test-2.yaml | 56 ++ .../keploy/test-set-0/tests/test-3.yaml | 55 ++ .../keploy/test-set-0/tests/test-4.yaml | 51 ++ flask-mongo-local/postman_tests/delete.js | 17 + flask-mongo-local/postman_tests/get.js | 17 + flask-mongo-local/postman_tests/post.js | 14 + flask-mongo-local/postman_tests/put.js | 17 + flask-mongo-local/requirements.txt | 5 + flask-mongo-local/test_app.py | 45 ++ flask-mongo-local/test_keploy.py | 8 + 31 files changed, 2798 insertions(+) create mode 100644 flask-mongo-docker/Dockerfile create mode 100644 flask-mongo-docker/README.md create mode 100644 flask-mongo-docker/app.py create mode 100644 flask-mongo-docker/docker-compose.yml create mode 100644 flask-mongo-docker/keploy/test-set-1/config.yaml create mode 100644 flask-mongo-docker/keploy/test-set-1/mocks.yaml create mode 100644 flask-mongo-docker/keploy/test-set-1/test-1.yaml create mode 100644 flask-mongo-docker/keploy/test-set-1/test-2.yaml create mode 100644 flask-mongo-docker/keploy/testReports/report-1.yaml create mode 100644 flask-mongo-docker/requirements.txt create mode 100644 flask-mongo-local/.coverage create mode 100644 flask-mongo-local/.coveragerc create mode 100644 flask-mongo-local/__pycache__/app.cpython-310.pyc create mode 100644 flask-mongo-local/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc create mode 100644 flask-mongo-local/__pycache__/test_app.cpython-310.pyc create mode 100644 flask-mongo-local/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc create mode 100644 flask-mongo-local/app.py create mode 100644 flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml create mode 100644 flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml create mode 100644 flask-mongo-local/keploy/test-set-0/mocks.yaml create mode 100644 flask-mongo-local/keploy/test-set-0/tests/test-1.yaml create mode 100644 flask-mongo-local/keploy/test-set-0/tests/test-2.yaml create mode 100644 flask-mongo-local/keploy/test-set-0/tests/test-3.yaml create mode 100644 flask-mongo-local/keploy/test-set-0/tests/test-4.yaml create mode 100644 flask-mongo-local/postman_tests/delete.js create mode 100644 flask-mongo-local/postman_tests/get.js create mode 100644 flask-mongo-local/postman_tests/post.js create mode 100644 flask-mongo-local/postman_tests/put.js create mode 100644 flask-mongo-local/requirements.txt create mode 100644 flask-mongo-local/test_app.py create mode 100644 flask-mongo-local/test_keploy.py diff --git a/flask-mongo-docker/Dockerfile b/flask-mongo-docker/Dockerfile new file mode 100644 index 0000000..cbefd2c --- /dev/null +++ b/flask-mongo-docker/Dockerfile @@ -0,0 +1,17 @@ +# Use the official Python image as the base image +FROM python:3.9 + +# Set the working directory within the container +WORKDIR /app + +# Copy the application code into the container +COPY . . + +# Install the required packages +RUN pip3 install -r requirements.txt + +# Expose the port that the Flask app will run on +EXPOSE 6000 + +# Start the Flask application +CMD ["python3", "app.py"] diff --git a/flask-mongo-docker/README.md b/flask-mongo-docker/README.md new file mode 100644 index 0000000..54bc693 --- /dev/null +++ b/flask-mongo-docker/README.md @@ -0,0 +1,600 @@ +This application is a simple student management API built using Python's Flask framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on student records. The API supports CORS (Cross-Origin Resource Sharing) to facilitate cross-domain requests. + +## Table of Contents + +# Introduction + +๐Ÿช„ Dive into the world of Student CRUD Apps and see how seamlessly Keploy integrated with [Flask](https://flask.palletsprojects.com/en/3.0.x/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! ๐ŸŽข + +## Pre-Requisite ๐Ÿ› ๏ธ + +- Install WSL (`wsl --install`) for Windows Windows. + +## Optional ๐Ÿ› ๏ธ + +- Install Colima( `brew install colima && colima start` ) for MacOS MacOs. + +## Get Started! ๐ŸŽฌ + +## Setup the MongoDB Database ๐Ÿ“ฆ + +Create a docker network, run - + +```bash +docker network create backend +``` + +Start the MongoDB instance- + +```bash +docker run -p 27017:27017 -d --network backend --name mongo mongo +``` + +## Clone a simple Student Management API ๐Ÿงช + +```bash +git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo +``` + +## Installation ๐Ÿ“ฅ + +Depending on your OS, choose your adventure: + +-
+ Linux Linux or Windows Windows + + Alright, let's equip ourselves with the **latest Keploy binary**: + + ```bash + 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 && keploy + ``` + + If everything goes right, your screen should look a bit like this: + + Moving on... +
+ Run App with Docker Container Docker + + #### Add alias for Keploy: + + ```bash + alias 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' + ``` + + ### Lights, Camera, Record! ๐ŸŽฅ + + Build the app image: + + ```bash + docker build -t flask-app:1.0 . + ``` + + Capture the test-cases- + + ```shell + keploy record -c "docker run -p 6000:6000 --name flask-app --network backend flask-app:1.0" + ``` + + ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! + + Let's make URLs short and sweet: + + ### Generate testcases + + To generate testcases we just need to **make some API calls.** + + **1. Make a POST request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **2. Make a GET request** + + ```bash + curl http://localhost:6000/students + ``` + + **3. Make a PUT request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **4. Make a GET request** + + ```bash + curl http://localhost:6000/students/12345 + ``` + + **5. Make a DELETE request** + + ```bash + curl -X DELETE http://localhost:6000/students/12345 + ``` + + Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. + + ```yaml + version: api.keploy.io/v1beta2 + kind: Http + name: test-1 + spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:6000/students + header: + Accept: "*/*" + Content-Length: "56" + Content-Type: application/json + Host: localhost:6000 + User-Agent: curl/7.81.0 + body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' + body_type: "" + timestamp: 2023-11-13T13:02:32.241333562Z + resp: + status_code: 200 + header: + Content-Length: "48" + Content-Type: application/json + Date: Mon, 13 Nov 2023 13:02:32 GMT + Server: Werkzeug/2.2.2 Python/3.9.18 + body: | + { + "message": "Student created successfully" + } + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + timestamp: 2023-11-13T13:02:34.752123715Z + objects: [] + assertions: + noise: + - header.Date + created: 1699880554 + curl: |- + curl --request POST \ + --url http://localhost:6000/students \ + --header 'Host: localhost:6000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: */*' \ + --header 'Content-Type: application/json' \ + --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' + ``` + + This is how `mocks.yml` generated would look like:- + + ```yaml + version: api.keploy.io/v1beta2 + kind: Mongo + name: mocks + spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' + requests: + - header: + length: 187 + requestId: 2127584089 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' + checksum: 0 + read_delay: 3469848802 + responses: + - header: + length: 166 + requestId: 154 + responseTo: 2127584089 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 869555 + created: 1699880576 + reqTimestampMock: 2023-11-13T13:02:56.385067848Z + resTimestampMock: 2023-11-13T13:02:56.386374941Z + ``` + + Want to see if everything works as expected? + + #### Run Tests + + Time to put things to the test ๐Ÿงช + + ```shell + keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 + ``` + + > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. + + Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + + ## Wrapping it up ๐ŸŽ‰ + + 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + +
+
+ +
+ Run App on ๐Ÿง Linux + + We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (PostgreSQL) chill on Docker. Ready? Let's get the party started!๐ŸŽ‰ + + ### ๐Ÿ“ผ Roll the Tape - Recording Time! + + Install the dependencies: + + ```bash + pip install -r requirements.txt + ``` + + Now, let's Capture the test-cases- + + In `app.py`, replace the MongoDB connection URL with - `mongodb://0.0.0.0:27017/` + + Ready, set, record! Here's how: + + ```bash + keploy record -c "python3 app.py" + ``` + + Keep an eye out for the `-c `flag! It's the command charm to run the app. + + Alright, magician! With the app alive and kicking, let's weave some test cases. The spell? Making some API calls! Postman, Hoppscotch, or the classic curl - pick your wand. + + ### Generate testcases + + To generate testcases we just need to **make some API calls.** + + **1. Make a POST request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **2. Make a GET request** + + ```bash + curl http://localhost:6000/students + ``` + + **3. Make a PUT request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **4. Make a GET request** + + ```bash + curl http://localhost:6000/students/12345 + ``` + + **5. Make a DELETE request** + + ```bash + curl -X DELETE http://localhost:6000/students/12345 + ``` + + Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. + + ```yaml + version: api.keploy.io/v1beta2 + kind: Http + name: test-1 + spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:6000/students + header: + Accept: "*/*" + Content-Length: "56" + Content-Type: application/json + Host: localhost:6000 + User-Agent: curl/7.81.0 + body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' + body_type: "" + timestamp: 2023-11-13T13:02:32.241333562Z + resp: + status_code: 200 + header: + Content-Length: "48" + Content-Type: application/json + Date: Mon, 13 Nov 2023 13:02:32 GMT + Server: Werkzeug/2.2.2 Python/3.9.18 + body: | + { + "message": "Student created successfully" + } + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + timestamp: 2023-11-13T13:02:34.752123715Z + objects: [] + assertions: + noise: + - header.Date + created: 1699880554 + curl: |- + curl --request POST \ + --url http://localhost:6000/students \ + --header 'Host: localhost:6000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: */*' \ + --header 'Content-Type: application/json' \ + --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' + ``` + + This is how `mocks.yml` generated would look like:- + + ```yaml + version: api.keploy.io/v1beta2 + kind: Mongo + name: mocks + spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' + requests: + - header: + length: 187 + requestId: 2127584089 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' + checksum: 0 + read_delay: 3469848802 + responses: + - header: + length: 166 + requestId: 154 + responseTo: 2127584089 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 869555 + created: 1699880576 + reqTimestampMock: 2023-11-13T13:02:56.385067848Z + resTimestampMock: 2023-11-13T13:02:56.386374941Z + ``` + + Want to see if everything works as expected? + + #### Run Tests + + Time to put things to the test ๐Ÿงช + + ```shell + keploy test -c "python3 app.py" --delay 10 + ``` + + > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. + + Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + + ## Wrapping it up ๐ŸŽ‰ + + 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ +
+ +
+ +
+ +-
+ MacOS MacOs + + Dive straight in, but first in case you're using **Keploy** with **Colima**, give it a gentle nudge with (`colima start`). Let's make sure it's awake and ready for action! + + ### Add alias for Keploy ๐Ÿฐ: + + For the sake of convenience (and a bit of Mac magic ๐Ÿช„), let's set up a shortcut for Keploy: + + ### Use Keploy with Docker-Desktop + + Note: To run Keploy on MacOS through [Docker](https://docs.docker.com/desktop/release-notes/#4252) the version must be `4.25.2` or above. + + #### Creating Docker Volume + + ```bash + docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs + ``` + + ```bash + alias 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 debugfs:/sys/kernel/debug:rw -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' + ``` + + ### Use Keploy with Colima + + ```bash + alias 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' + ``` + + ### Lights, Camera, Record! ๐ŸŽฅ + + Build the app image: + + ```bash + docker build -t flask-app:1.0 . + ``` + + Capture the test-cases- + + ```shell + keploy record -c "docker run -p 6000:6000 --name DjangoApp --network backend --name flask-app flask-app:1.0" + ``` + + ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! + + Let's make URLs short and sweet: + + ### Generate testcases + + To generate testcases we just need to **make some API calls.** + + **1. Make a POST request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **2. Make a GET request** + + ```bash + curl http://localhost:6000/students + ``` + + **3. Make a PUT request** + + ```bash + curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 + ``` + + **4. Make a GET request** + + ```bash + curl http://localhost:6000/students/12345 + ``` + + **5. Make a DELETE request** + + ```bash + curl -X DELETE http://localhost:6000/students/12345 + ``` + + Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. + + ```yaml + version: api.keploy.io/v1beta2 + kind: Http + name: test-1 + spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:6000/students + header: + Accept: "*/*" + Content-Length: "56" + Content-Type: application/json + Host: localhost:6000 + User-Agent: curl/7.81.0 + body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' + body_type: "" + timestamp: 2023-11-13T13:02:32.241333562Z + resp: + status_code: 200 + header: + Content-Length: "48" + Content-Type: application/json + Date: Mon, 13 Nov 2023 13:02:32 GMT + Server: Werkzeug/2.2.2 Python/3.9.18 + body: | + { + "message": "Student created successfully" + } + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + timestamp: 2023-11-13T13:02:34.752123715Z + objects: [] + assertions: + noise: + - header.Date + created: 1699880554 + curl: |- + curl --request POST \ + --url http://localhost:6000/students \ + --header 'Host: localhost:6000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: */*' \ + --header 'Content-Type: application/json' \ + --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' + ``` + + This is how `mocks.yml` generated would look like:- + + ```yaml + version: api.keploy.io/v1beta2 + kind: Mongo + name: mocks + spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' + requests: + - header: + length: 187 + requestId: 2127584089 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' + checksum: 0 + read_delay: 3469848802 + responses: + - header: + length: 166 + requestId: 154 + responseTo: 2127584089 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 869555 + created: 1699880576 + reqTimestampMock: 2023-11-13T13:02:56.385067848Z + resTimestampMock: 2023-11-13T13:02:56.386374941Z + ``` + + Want to see if everything works as expected? + + #### Run Tests + + Time to put things to the test ๐Ÿงช + + ```shell + keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 + ``` + + > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. + + Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + + ## Wrapping it up ๐ŸŽ‰ + + 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ +
diff --git a/flask-mongo-docker/app.py b/flask-mongo-docker/app.py new file mode 100644 index 0000000..6e31416 --- /dev/null +++ b/flask-mongo-docker/app.py @@ -0,0 +1,42 @@ +from flask import Flask, request, jsonify +from pymongo import MongoClient +from flask_cors import CORS +import collections.abc + +app = Flask(__name__) +cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) + +# Connect to MongoDB +client = MongoClient('mongodb://mongo:27017/') +db = client['studentsdb'] +students_collection = db['students'] + +@app.route('/students', methods=['GET']) +def get_students(): + students = list(students_collection.find({}, {'_id': 0})) + return jsonify(students) + +@app.route('/students/', methods=['GET']) +def get_student(student_id): + student = students_collection.find_one({'student_id': student_id}, {'_id': 0}) + return jsonify(student) + +@app.route('/students', methods=['POST']) +def create_student(): + new_student = request.json + students_collection.insert_one(new_student) + return jsonify({'message': 'Student created successfully'}) + +@app.route('/students/', methods=['PUT']) +def update_student(student_id): + updated_student = request.json + students_collection.update_one({'student_id': student_id}, {'$set': updated_student}) + return jsonify({'message': 'Student updated successfully'}) + +@app.route('/students/', methods=['DELETE']) +def delete_student(student_id): + students_collection.delete_one({'student_id': student_id}) + return jsonify({'message': 'Student deleted successfully'}) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=6000, debug=True) diff --git a/flask-mongo-docker/docker-compose.yml b/flask-mongo-docker/docker-compose.yml new file mode 100644 index 0000000..7ef7346 --- /dev/null +++ b/flask-mongo-docker/docker-compose.yml @@ -0,0 +1,29 @@ +version: '3' +services: + mongo: + image: mongo + container_name: mongo + ports: + - "27017:27017" + volumes: + - data:/data/db + networks: + - backend + + flask-app: + image: flask-app:1.0 + container_name: flask-app + build: + context: . + ports: + - "6000:6000" + depends_on: + - mongo + networks: + - backend + +networks: + backend: + external: true +volumes: + data: diff --git a/flask-mongo-docker/keploy/test-set-1/config.yaml b/flask-mongo-docker/keploy/test-set-1/config.yaml new file mode 100644 index 0000000..e451518 --- /dev/null +++ b/flask-mongo-docker/keploy/test-set-1/config.yaml @@ -0,0 +1,167 @@ +version: api.keploy.io/v1beta2 +kind: Mongo +name: config +spec: + metadata: + operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"}}, returnFieldsSelector: }' + requests: + - header: + length: 262 + requestId: 1890541915 + responseTo: 0 + Opcode: 2004 + message: + flags: 0 + collection_name: admin.$cmd + number_to_skip: 0 + number_to_return: -1 + query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"}}' + return_fields_selector: "" + read_delay: 82208 + responses: + - header: + length: 329 + requestId: 3 + responseTo: 1890541915 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448932"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 659750 + created: 1692190448 +--- +version: api.keploy.io/v1beta2 +kind: Mongo +name: config +spec: + metadata: + operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"},"compression": []}, returnFieldsSelector: }' + requests: + - header: + length: 280 + requestId: 1076681270 + responseTo: 0 + Opcode: 2004 + message: + flags: 0 + collection_name: admin.$cmd + number_to_skip: 0 + number_to_return: -1 + query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"},"compression":[]}' + return_fields_selector: "" + read_delay: 51917 + responses: + - header: + length: 329 + requestId: 4 + responseTo: 1076681270 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448936"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"2"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 999250 + created: 1692190448 +--- +version: api.keploy.io/v1beta2 +kind: Mongo +name: config +spec: + metadata: + operation: '{ OpMsg flags: 65536, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }], checksum: 0 }' + requests: + - header: + length: 134 + requestId: 613273587 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 65536 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }' + checksum: 0 + read_delay: 3336333 + responses: + - header: + length: 313 + requestId: 10 + responseTo: 613273587 + Opcode: 2013 + message: + flagBits: 2 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458940"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 10005077213 + created: 1692190458 +--- +version: api.keploy.io/v1beta2 +kind: Mongo +name: config +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }], checksum: 0 }' + requests: + - header: + length: 52 + requestId: 1075693109 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }' + checksum: 0 + read_delay: 10043184088 + responses: + - header: + length: 313 + requestId: 11 + responseTo: 1075693109 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458982"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 746417 + created: 1692190458 +--- +version: api.keploy.io/v1beta2 +kind: Mongo +name: config +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }], checksum: 0 }' + requests: + - header: + length: 65 + requestId: 1299455543 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }' + checksum: 0 + read_delay: 10042282047 + responses: + - header: + length: 314 + requestId: 15 + responseTo: 1299455543 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190469027"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 1815417 + created: 1692190469 diff --git a/flask-mongo-docker/keploy/test-set-1/mocks.yaml b/flask-mongo-docker/keploy/test-set-1/mocks.yaml new file mode 100644 index 0000000..3051236 --- /dev/null +++ b/flask-mongo-docker/keploy/test-set-1/mocks.yaml @@ -0,0 +1,64 @@ +version: api.keploy.io/v1beta2 +kind: Mongo +name: mocks +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }, { SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }], checksum: 0 }' + requests: + - header: + length: 197 + requestId: 1340074696 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' + - '{ SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }' + checksum: 0 + read_delay: 566167 + responses: + - header: + length: 45 + requestId: 6 + responseTo: 1340074696 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 27458 + created: 1692190448 +--- +version: api.keploy.io/v1beta2 +kind: Mongo +name: mocks +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' + requests: + - header: + length: 140 + requestId: 1596327406 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' + checksum: 0 + read_delay: 9681533921 + responses: + - header: + length: 273 + requestId: 9 + responseTo: 1596327406 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 40167 + created: 1692190458 diff --git a/flask-mongo-docker/keploy/test-set-1/test-1.yaml b/flask-mongo-docker/keploy/test-set-1/test-1.yaml new file mode 100644 index 0000000..4141f28 --- /dev/null +++ b/flask-mongo-docker/keploy/test-set-1/test-1.yaml @@ -0,0 +1,38 @@ +version: api.keploy.io/v1beta2 +kind: Http +name: test-1 +spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:6000/students + header: + Accept: '*/*' + Content-Length: "51" + Content-Type: application/json + Host: localhost:6000 + User-Agent: curl/7.77.0 + body: '{"student_id": "123", "name": "Sarthak", "age": 20}' + body_type: "" + resp: + status_code: 200 + header: + Content-Length: "48" + Content-Type: application/json + Date: Wed, 16 Aug 2023 12:54:08 GMT + Server: Werkzeug/2.3.7 Python/3.9.17 + body: | + { + "message": "Student created successfully" + } + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + objects: [] + assertions: + noise: + - header.Date + created: 1692190448 diff --git a/flask-mongo-docker/keploy/test-set-1/test-2.yaml b/flask-mongo-docker/keploy/test-set-1/test-2.yaml new file mode 100644 index 0000000..77cb4a3 --- /dev/null +++ b/flask-mongo-docker/keploy/test-set-1/test-2.yaml @@ -0,0 +1,34 @@ +version: api.keploy.io/v1beta2 +kind: Http +name: test-2 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:6000/students + header: + Accept: '*/*' + Host: localhost:6000 + User-Agent: curl/7.77.0 + body: "" + body_type: "" + resp: + status_code: 200 + header: + Content-Length: "224" + Content-Type: application/json + Date: Wed, 16 Aug 2023 12:54:18 GMT + Server: Werkzeug/2.3.7 Python/3.9.17 + body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + objects: [] + assertions: + noise: + - header.Date + - body.name + created: 1692190458 diff --git a/flask-mongo-docker/keploy/testReports/report-1.yaml b/flask-mongo-docker/keploy/testReports/report-1.yaml new file mode 100644 index 0000000..14623ce --- /dev/null +++ b/flask-mongo-docker/keploy/testReports/report-1.yaml @@ -0,0 +1,181 @@ +version: api.keploy.io/v1beta1 +name: report-1 +status: PASSED +success: 2 +failure: 0 +total: 2 +tests: + - kind: Http + name: report-1 + status: PASSED + started: 1692258836 + completed: 1692258836 + test_case_path: /files/keploy + mock_path: "" + test_case_id: test-1 + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://172.19.0.4:6000/students + header: + Accept: '*/*' + Content-Length: "51" + Content-Type: application/json + Host: localhost:6000 + User-Agent: curl/7.77.0 + body: '{"student_id": "123", "name": "Sarthak", "age": 20}' + body_type: "" + resp: + status_code: 200 + header: + Content-Length: "48" + Content-Type: application/json + Date: Wed, 16 Aug 2023 12:54:08 GMT + Server: Werkzeug/2.3.7 Python/3.9.17 + body: | + { + "message": "Student created successfully" + } + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + noise: + - header.Date + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Server + value: + - Werkzeug/2.3.7 Python/3.9.17 + actual: + key: Server + value: + - Werkzeug/2.3.7 Python/3.9.17 + - normal: true + expected: + key: Content-Length + value: + - "48" + actual: + key: Content-Length + value: + - "48" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Wed, 16 Aug 2023 12:54:08 GMT + actual: + key: Date + value: + - Thu, 17 Aug 2023 07:53:56 GMT + body_result: + - normal: true + type: JSON + expected: | + { + "message": "Student created successfully" + } + actual: | + { + "message": "Student created successfully" + } + dep_result: [] + - kind: Http + name: report-1 + status: PASSED + started: 1692258836 + completed: 1692258836 + test_case_path: /files/keploy + mock_path: "" + test_case_id: test-2 + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://172.19.0.4:6000/students + header: + Accept: '*/*' + Host: localhost:6000 + User-Agent: curl/7.77.0 + body: "" + body_type: "" + resp: + status_code: 200 + header: + Content-Length: "224" + Content-Type: application/json + Date: Wed, 16 Aug 2023 12:54:18 GMT + Server: Werkzeug/2.3.7 Python/3.9.17 + body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" + body_type: "" + status_message: "" + proto_major: 0 + proto_minor: 0 + noise: + - header.Date + - body.name + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Date + value: + - Wed, 16 Aug 2023 12:54:18 GMT + actual: + key: Date + value: + - Thu, 17 Aug 2023 07:53:56 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/2.3.7 Python/3.9.17 + actual: + key: Server + value: + - Werkzeug/2.3.7 Python/3.9.17 + - normal: true + expected: + key: Content-Length + value: + - "224" + actual: + key: Content-Length + value: + - "224" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + body_result: + - normal: true + type: JSON + expected: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" + actual: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" + dep_result: [] diff --git a/flask-mongo-docker/requirements.txt b/flask-mongo-docker/requirements.txt new file mode 100644 index 0000000..7a03746 --- /dev/null +++ b/flask-mongo-docker/requirements.txt @@ -0,0 +1,4 @@ +Flask +pymongo==4.4.1 +Flask-Cors==3.0.10 +Werkzeug==2.2.2 \ No newline at end of file diff --git a/flask-mongo-local/.coverage b/flask-mongo-local/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..b9fdbfc3ab404e8c0cde6193a1f517351896e37a GIT binary patch literal 53248 zcmeI)+lw1j90%~3Oqw*=EK@1lxGrVSOWiKrY+Nje^+8v=V72z5RUZV?lgY{M*tw)L zlkVya-U+l#~WLOZg3PpBPbbtBc=lL1yAR)grC63GNb=@YBf6;Y2Tsf2?dEv+(mvUU%$WMcP?7G>b zE(h_BRA)xcHJYUAdiLe6>R0}X7^GZ@!|?nS!9h?9I5JbHzJ5^Gs8y<+@Ulbiw;Hk= z`SEsxD!;Kt50$T8*k7zJF6uWf#|?#f8cjP2`zxi9M$_Ltrs?qU@$H6t$!H_tUgS8! zZ^vDRQ;Vc>s5KAwnRO+*GUS(PUV7)(wf8&RVHZ-B=vgbox!8vDRNL_vQ=5>cWD4trRz-w6@Zx z;z$$9YI2WZG&|%f8FqtgAbHdvnWY$vl35=~k5D+ZVxhXeFfN?*yvAC(vcFf%7prq~ zdN1h_JTCEl-$)R=XV3*6mYr?tRV=Lz|{mp0>gh*`{pQ690f{8u|*}M z?s`$(s(&2P&k)qZZQ1eaC;e^D@nws)rQ2~-SnKRYTfSFsJ2JdfbA4~quQ|RYox1FF z=;sJN$Wcy=?@|Hz`+vhcq?w1zi{=m0Q^klB0uX=z z1Rwwb2tWV=5P$##AfRcd^1V6z$u6^#3wGm7o_+)H$#NRH{?DDu_l}gFLU#S@fBgO* z+B*aw009U<00Izz00bZa0SG`~q6G}y&}RAjf8G37qZ<|oKmY;|fB*y_009U<00Izz z00bsbz%XV@$^ZY~)Xaa(Kg^pG7$ic100bZa0SG_<0uX=z1Rwwb2u!*_#mMWWmyBQU z{8;?&%uh2p+Ilhf^PPKFf2$Vse5rKcgr5BW|832@Z~kT8o^%kz2LT8`00Izz00bZa z0SG_<0uY!2fdYL1pc_W~l*{Gm6M*>pf9=2&#EuXl009U<00Izz00bZa0SG_<0#hu& z-~Z$Ke~KFbLWckZAOHafKmY;|fB*y_0D-9xNdEu-F8}@iJ@f8Vgp42|009U<00Izz b00bZa0SG_<0+TOb81$?EMvfo&_y7L~KzQX( literal 0 HcmV?d00001 diff --git a/flask-mongo-local/.coveragerc b/flask-mongo-local/.coveragerc new file mode 100644 index 0000000..387d12b --- /dev/null +++ b/flask-mongo-local/.coveragerc @@ -0,0 +1,4 @@ +[run] +omit = + /usr/* +sigterm = true \ No newline at end of file diff --git a/flask-mongo-local/__pycache__/app.cpython-310.pyc b/flask-mongo-local/__pycache__/app.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e502979d3897a6d6fd44c61ea39de4daa6ed4ba8 GIT binary patch literal 2049 zcmZWqOK%iM5T5SodF<@N#x@W0Tp~mmB(sDI5<&JR9+!%6NGq)Q6grG?vd3Cd{B3a{(gxtse%&<*UI}%E&@^K9`|{Wk&N*08SOTN$7`_H6iptjI^C9N@j8qPqQ1Mx8@xFny!DLo1-|%$ z1A52i@?&%P5?{9RB`aUy$LI1B{G^pH&*i7)@>PD?%2!0h&pe@0!~Su8mY?J2`Gsfb zPkYO@_~I+@*oj@^-Om&C!~{}29SNmPu&b&v>+i?J)IYDvL3J|sYgh9IpP2Gl0J1@wg zGj%4w=qmPf)#2`QIwhLEa3|!DOsQs^X>USz{R6_i=M;LsPq&;n*fgHbbS_Mt3zf=j zsI#hkN#z1qmW$AhSGVDT?No|H3*J_v6ns_vQJ(L|6rZRRcx7nDU;PH^aUk)9CL9Re zLv&4)R(TE(f?X2NBa}y^I4%j3+uV46!giz&pzIOGlmq^}p6T zMX5V!=Mh*@9krJX%g%bWSLRj1VVxAiT&T6-KEPIX`pET~C1uSL0uT?c4fjob=1dQ7 zXo6YQfG(sy^@;ya#7+@;!M^R|jqP`!ryzyInn8aTCIf(d2LHPA&GM8?oEKCBo+7orjreA`eNPTW8ft5GiDp(FS28BH%HJ{%&~k5(vjDZ-cON z8_|Kc-7)UNN82fZ{Wl*L5-c?~1b>FfJOt5W3_(NIKqh=}l7pML3VIUtF69VNJ8jt=%eCC-!)XS|5oI-D@H1}7SL!gs!g z;x%R8F-Ukj?vXtwZf+jI@ff^QUW9JUE-9fUI%GT{WhKX#x53wTS?PAa8kM|VNm#Vg z$4NO5s=X(qXcq|=*-vmtE}@NCQjCTWs_!L5_9rOCHJb(UI9_V0i)Oku@-c=?tEhO^ z&mibixKq#4p|lo&1NBT= z_Ta)YDMYVlT*yYlP|5hI{r51G@60^(WHr*lRuh|G7V6oHT{$X`IBB!iCTw^c0%Mem kJBYrz0^N$!AovUE3bc@fKwd;zHE0pEg@}Y~g|OHE0^1|^1poj5 literal 0 HcmV?d00001 diff --git a/flask-mongo-local/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc b/flask-mongo-local/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ca0d856dc4193768233b03b4fada6881d7496a87 GIT binary patch literal 2471 zcma)8PjB2r6!+L(d-iYA6xs$_SR!aym1OCK1FBF&K`4hThbBU-kgTa^l6vE{&CD!O zR_Q6dR(ydTHpiU!8t@h7$|+wV5`y=}yU8YLQJu{5y!rd)_xsKB=FMi!foJdA`#XOG zj`KG<^N$bCIuvyXhC7_3PM_GfJM>(KI77c*A!Sd{51_|Q!(rGDZJU?UVYOc!*7~*S zn0mhsWBjx+Z1$VP`N8289=vpTAc8^b$m=hNMIP?C^05deH;!R_PM+G*p{Edm)9Vo9 zv7+d>rcy8+KR4A)wwuJ8dAtW*^v7od5$g>e4tC<;|x~r)3tlgwk6~?QOD*?FtzaSabGZ-GlN3iuwwS zb|&Q5Idmd8$DuQDB3FAy==-|DU1;%-z(xVof=Ou4?7%i&Z)@Cwldi>in!=fqJnK-2 z$1rsb`$ut_h)kOhog~|pNR?T*7#$4(6N#ai&_X4osVL2)J|V_eBHcN0WDB~_HoC)1 zcjNB15>j>5J}a{Bclmyn=8S{ShD9pWYH^^S=UI0rg@dmS^K3U?P4k$gT^kKXS{%Rz zLT?vUSXH60YJ?K%wn&SN-@gLdnjLu!Iy|6-4kJUj5IhtQKtg&QSK_h|zRnBTfT}$~ zX%?`DYQZE1e*-*)tHIuPuI@b>bZL8p3PH5ne+?Cs2lrmPFD!2Z!u>YiK+H1?xno!qmA?u}li2 z_^j4tMbgCq3TYasJUjghVo}RraItnQ1=E7J)hLdIQahtGJ?I3bGW;S}+SHi>CiVBf zj#z5yK)D{ND9*VswCvf)jL(^79Zxo4S@{tdL#0qfp219neh$(_j5#W|jWDwJpkGli zHL?iQE|GEjI>48wTml+dsX(znuR~?mGCd#>UI!1rB*z3npHvRXAmHv4{>l|*sCvU+zr+`bR?exBW_ zdhe`(cXyUJO%>CI;8DU)i2M}7I9s}qWEVT3Yuwl_KtP~El;rsKxxTaZXxf1!$eS=< z-bV8Ym=0fQ&`5^3Pi& zIydRTBn#VpSjxh-NKnK71KZrBUZ-kk6lH8EqR7-D z`0VgeiuFbmVFoIDEJ$btdk6~_C_)w?LRn;3#1>+N)M|H?$35=pZmMdq zJaSgfHsS}e7%#ozH{cg~%gVoC3BkS9Gxm%fBYIr7>(=Aet#eLQJ6~9+6L|K%y}$Fj zN6263%svh{8&K3X7*04%Nf+N%N(Zz{Dc0@O8rWTX;B+11)70&{(C(z(!0-B$d{4N` zy;p>Lg7n#u-K~i__xCK>7G&HwCNPV>FePB8uny@2w6vq52&~dAA|3CRwdYYUiJ#~3 z9(1uEw)-O1&v=Z3XCDik4Jhg{7(u#}ldi=nw_cI1&28?$+o_U)6n)OX_jrxh;qCJV zZ^E1Lg%>1PESENg(wmXmdmd#`Pso@;%;|%58_E+X>MJmsjOj5sBq8kMkn~AtY5NF$ zN4wmD7Uu|T=t0dJ`)1Dsma#jVqea;1dYq>z>?z5!fJxj&+0d|l7^jKIbm^m$WIc(5 zluH+*!vSC-F_qFcPzhPON=H(k(9%&N-8mt05xUQwwg;JR$L%d8q-v}EsL0yi<@;Hh zM;!cUP^3bw6$g4Z&)PdFY*jiQrCGQn@}~`S7r%&m==-5#NPo=VKi9#_T{yw zgXWe;m=Hj-{MS%HX>j|E_0n+Gr`$QD+1{FD(j4D zxM&L{GP<$3o2VB2MJ)uYrJ?Zz)TBVKFgvKFPl>6q0GWxqjV@Ltn8l9@&gzm@1nVFrW&~$JWi|%n~$*b5+W-G5ttuF zX=)%*@58VOCQZQPE*-7D6_dG1S5QGv4JsTedLqEr)^DpQvOeuw+}uyxe`9e5LPU&g zK*Zs-DMq}Gn4$M0NYR1ckzI-M5m68K;ZnxmPt!Bi=$tk2>`pJuvW8cN;9)~?p5w~XcbZ}1DRa5s!J0VoE5tyt{S ICUyS#7tjhZUjP6A literal 0 HcmV?d00001 diff --git a/flask-mongo-local/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc b/flask-mongo-local/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f77eaa007830cece0fdc1e3edd2404b67b75e3a8 GIT binary patch literal 657 zcmYjO&x;c=6izZT?R0D_h$x<%n^c(2LGZLL3;sAs1w|KoDcL5i!)B6@WGqv*BCJ>c z1OEa4rCdGjzu-k*rgUi_@8x@syzl!GH5z3I*27;!|h{?b{L~==ExPkhSNFv3=($u838yPOiUFm2j1`et4$a#VvZY05X_5r4}TGkD403 yF_q(fa9i^ILoI{L9Vs=ww-?g6?Vh6J>U', methods=['PUT']) +def update_task(task_id): + data = request.get_json() + updated_task = { + 'title': data['title'], + 'description': data['description'] + } + try: + result = collection.update_one({'_id': ObjectId(task_id)}, {'$set': updated_task}) + if result.modified_count == 0: + return jsonify({'error': 'Task not found or no changes were made'}), 404 + else: + return jsonify({'message': 'Task updated successfully'}) + except Exception as e: + return jsonify({'error': str(e)}), 500 + +@app.route('/api/tasks/', methods=['DELETE']) +def delete_task(task_id): + collection.delete_one({'_id': ObjectId(task_id)}) + return jsonify({'message': 'Task deleted successfully'}) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml b/flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml new file mode 100644 index 0000000..c4c5d3c --- /dev/null +++ b/flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml @@ -0,0 +1,446 @@ +version: api.keploy.io/v1beta1 +name: test-set-0-report +status: FAILED +success: 0 +failure: 4 +total: 4 +tests: + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873653 + completed: 1713873653 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-1 + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "59" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Task 6","description": "Description for Task 6"}' + timestamp: 2024-04-22T16:38:39.232565209+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "267" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:08:39 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "tasks": [ + { + "description": "should update", + "id": "6626362fc7c5eddf174c88e4", + "title": "Updated" + }, + { + "description": "Should work", + "id": "66263667c7c5eddf174c88e5", + "title": "Let's Check another time" + } + ] + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:38:41.245704918+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:08:39 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:00:53 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "267" + actual: + key: Content-Length + value: + - "191" + body_result: + - normal: true + type: JSON + expected: | + { + "tasks": [ + { + "description": "should update", + "id": "6626362fc7c5eddf174c88e4", + "title": "Updated" + }, + { + "description": "Should work", + "id": "66263667c7c5eddf174c88e5", + "title": "Let's Check another time" + } + ] + } + actual: | + {"tasks":[{"description":"should update","id":"6626362fc7c5eddf174c88e4","title":"Updated"},{"description":"Should work","id":"66263667c7c5eddf174c88e5","title":"Let's Check another time"}]} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873653 + completed: 1713873653 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-2 + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "57" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 7aabbe61-38ec-4169-a4d8-31cb3546ca01 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title":"Hey, let''s Check","description":"It will work"}' + timestamp: 2024-04-22T16:39:05.814517536+05:30 + resp: + status_code: 201 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "81" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:05 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "id": "66264551a6e962a1cbd50429", + "message": "Task created successfully" + } + status_message: Created + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:07.866639952+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 201 + actual: 201 + headers_result: + - normal: false + expected: + key: Content-Length + value: + - "81" + actual: + key: Content-Length + value: + - "72" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:09:05 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:00:53 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + body_result: + - normal: false + type: JSON + expected: | + { + "id": "66264551a6e962a1cbd50429", + "message": "Task created successfully" + } + actual: | + {"id":"6627a2f5a20cac37a4bb3d0f","message":"Task created successfully"} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873653 + completed: 1713873653 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-3 + req: + method: PUT + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/6626362fc7c5eddf174c88e4 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "53" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 89d42b67-eafb-474e-ac5a-1df4982a9fe3 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Updated again","description": "hey there"}' + timestamp: 2024-04-22T16:39:52.181533473+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:52 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task updated successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:54.273657454+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "45" + actual: + key: Content-Length + value: + - "40" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:09:52 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:00:53 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + body_result: + - normal: true + type: JSON + expected: | + { + "message": "Task updated successfully" + } + actual: | + {"message":"Task updated successfully"} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873653 + completed: 1713873653 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-4 + req: + method: DELETE + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/66263667c7c5eddf174c88e5 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Host: localhost:5000 + Postman-Token: 0f3d6037-f57c-4fb3-be52-e6ffed1566e6 + User-Agent: PostmanRuntime/7.32.1 + body: "" + timestamp: 2024-04-22T16:40:08.615353613+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:10:08 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task deleted successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:40:10.646676187+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "45" + actual: + key: Content-Length + value: + - "40" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:10:08 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:00:53 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + body_result: + - normal: true + type: JSON + expected: | + { + "message": "Task deleted successfully" + } + actual: | + {"message":"Task deleted successfully"} + dep_result: [] +test_set: test-set-0 diff --git a/flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml b/flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml new file mode 100644 index 0000000..61157f7 --- /dev/null +++ b/flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml @@ -0,0 +1,446 @@ +version: api.keploy.io/v1beta1 +name: test-set-0-report +status: FAILED +success: 0 +failure: 4 +total: 4 +tests: + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873824 + completed: 1713873824 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-1 + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "59" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Task 6","description": "Description for Task 6"}' + timestamp: 2024-04-22T16:38:39.232565209+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "267" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:08:39 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "tasks": [ + { + "description": "should update", + "id": "6626362fc7c5eddf174c88e4", + "title": "Updated" + }, + { + "description": "Should work", + "id": "66263667c7c5eddf174c88e5", + "title": "Let's Check another time" + } + ] + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:38:41.245704918+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:08:39 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:03:44 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "267" + actual: + key: Content-Length + value: + - "191" + body_result: + - normal: true + type: JSON + expected: | + { + "tasks": [ + { + "description": "should update", + "id": "6626362fc7c5eddf174c88e4", + "title": "Updated" + }, + { + "description": "Should work", + "id": "66263667c7c5eddf174c88e5", + "title": "Let's Check another time" + } + ] + } + actual: | + {"tasks":[{"description":"should update","id":"6626362fc7c5eddf174c88e4","title":"Updated"},{"description":"Should work","id":"66263667c7c5eddf174c88e5","title":"Let's Check another time"}]} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873824 + completed: 1713873824 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-2 + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "57" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 7aabbe61-38ec-4169-a4d8-31cb3546ca01 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title":"Hey, let''s Check","description":"It will work"}' + timestamp: 2024-04-22T16:39:05.814517536+05:30 + resp: + status_code: 201 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "81" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:05 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "id": "66264551a6e962a1cbd50429", + "message": "Task created successfully" + } + status_message: Created + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:07.866639952+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 201 + actual: 201 + headers_result: + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:09:05 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:03:44 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "81" + actual: + key: Content-Length + value: + - "72" + body_result: + - normal: false + type: JSON + expected: | + { + "id": "66264551a6e962a1cbd50429", + "message": "Task created successfully" + } + actual: | + {"id":"6627a3a0dcedca8503554d0d","message":"Task created successfully"} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873824 + completed: 1713873824 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-3 + req: + method: PUT + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/6626362fc7c5eddf174c88e4 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "53" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 89d42b67-eafb-474e-ac5a-1df4982a9fe3 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Updated again","description": "hey there"}' + timestamp: 2024-04-22T16:39:52.181533473+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:52 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task updated successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:54.273657454+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:09:52 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:03:44 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + - normal: false + expected: + key: Content-Length + value: + - "45" + actual: + key: Content-Length + value: + - "40" + body_result: + - normal: true + type: JSON + expected: | + { + "message": "Task updated successfully" + } + actual: | + {"message":"Task updated successfully"} + dep_result: [] + - kind: Http + name: test-set-0 + status: FAILED + started: 1713873824 + completed: 1713873824 + test_case_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0 + mock_path: /mnt/c/Users/swapn/Downloads/samples-python/flask-mongo-local/keploy/test-set-0/mocks.yaml + test_case_id: test-4 + req: + method: DELETE + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/66263667c7c5eddf174c88e5 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Host: localhost:5000 + Postman-Token: 0f3d6037-f57c-4fb3-be52-e6ffed1566e6 + User-Agent: PostmanRuntime/7.32.1 + body: "" + timestamp: 2024-04-22T16:40:08.615353613+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:10:08 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task deleted successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:40:10.646676187+05:30 + noise: + header.Date: [] + result: + status_code: + normal: true + expected: 200 + actual: 200 + headers_result: + - normal: false + expected: + key: Content-Length + value: + - "45" + actual: + key: Content-Length + value: + - "40" + - normal: true + expected: + key: Content-Type + value: + - application/json + actual: + key: Content-Type + value: + - application/json + - normal: true + expected: + key: Date + value: + - Mon, 22 Apr 2024 11:10:08 GMT + actual: + key: Date + value: + - Tue, 23 Apr 2024 12:03:44 GMT + - normal: true + expected: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + actual: + key: Server + value: + - Werkzeug/3.0.2 Python/3.10.12 + - normal: true + expected: + key: Access-Control-Allow-Origin + value: + - '*' + actual: + key: Access-Control-Allow-Origin + value: + - '*' + body_result: + - normal: true + type: JSON + expected: | + { + "message": "Task deleted successfully" + } + actual: | + {"message":"Task deleted successfully"} + dep_result: [] +test_set: test-set-0 diff --git a/flask-mongo-local/keploy/test-set-0/mocks.yaml b/flask-mongo-local/keploy/test-set-0/mocks.yaml new file mode 100644 index 0000000..8b4d319 --- /dev/null +++ b/flask-mongo-local/keploy/test-set-0/mocks.yaml @@ -0,0 +1,319 @@ +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-0 +spec: + metadata: + operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.6.3"},"os": {"type": "Linux","name": "Linux","architecture": "x86_64","version": "5.15.146.1-microsoft-standard-WSL2"},"platform": "CPython 3.10.12.final.0"}}, returnFieldsSelector: }' + type: config + requests: + - header: + length: 283 + requestId: 1804289383 + responseTo: 0 + Opcode: 2004 + message: + flags: 0 + collection_name: admin.$cmd + number_to_skip: 0 + number_to_return: -1 + query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.6.3"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.15.146.1-microsoft-standard-WSL2"},"platform":"CPython 3.10.12.final.0"}}' + return_fields_selector: "" + responses: + - header: + length: 329 + requestId: 238 + responseTo: 1804289383 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784113763"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"18"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 1010011 + created: 1713784113 + reqTimestampMock: 2024-04-22T16:38:33.762559618+05:30 + resTimestampMock: 2024-04-22T16:38:33.763749062+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-1 +spec: + metadata: + operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.6.3"},"os": {"type": "Linux","name": "Linux","architecture": "x86_64","version": "5.15.146.1-microsoft-standard-WSL2"},"platform": "CPython 3.10.12.final.0"},"compression": []}, returnFieldsSelector: }' + type: config + requests: + - header: + length: 301 + requestId: 1714636915 + responseTo: 0 + Opcode: 2004 + message: + flags: 0 + collection_name: admin.$cmd + number_to_skip: 0 + number_to_return: -1 + query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.6.3"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.15.146.1-microsoft-standard-WSL2"},"platform":"CPython 3.10.12.final.0"},"compression":[]}' + return_fields_selector: "" + responses: + - header: + length: 329 + requestId: 242 + responseTo: 1714636915 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784119236"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"22"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 527460 + created: 1713784119 + reqTimestampMock: 2024-04-22T16:38:39.236318621+05:30 + resTimestampMock: 2024-04-22T16:38:39.236994457+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-2 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"tasks","filter":{},"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }], checksum: 0 }' + requests: + - header: + length: 113 + requestId: 1957747793 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"tasks","filter":{},"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }' + checksum: 0 + read_delay: 336283 + responses: + - header: + length: 272 + requestId: 243 + responseTo: 1957747793 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"_id":{"$oid":"6626362fc7c5eddf174c88e4"},"title":"Updated","description":"should update"},{"_id":{"$oid":"66263667c7c5eddf174c88e5"},"title":"Let''s Check another time","description":"Should work"}],"id":{"$numberLong":"0"},"ns":"task_manager.tasks"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 712174 + created: 1713784119 + reqTimestampMock: 2024-04-22T16:38:39.237446806+05:30 + resTimestampMock: 2024-04-22T16:38:39.238329738+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-3 +spec: + metadata: + operation: '{ OpMsg flags: 65536, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 134 + requestId: 846930886 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 65536 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }' + checksum: 0 + read_delay: 2621927 + responses: + - header: + length: 313 + requestId: 244 + responseTo: 846930886 + Opcode: 2013 + message: + flagBits: 2 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784123771"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"18"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 10005242839 + created: 1713784123 + reqTimestampMock: 2024-04-22T16:38:33.766550283+05:30 + resTimestampMock: 2024-04-22T16:38:43.772009113+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-4 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 52 + requestId: 1714636915 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }' + checksum: 0 + read_delay: 10012944393 + responses: + - header: + length: 313 + requestId: 245 + responseTo: 1714636915 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784123781"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"19"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 458361 + created: 1713784123 + reqTimestampMock: 2024-04-22T16:38:43.781318376+05:30 + resTimestampMock: 2024-04-22T16:38:43.781975276+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-5 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 65 + requestId: 1957747793 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }' + checksum: 0 + read_delay: 10012662732 + responses: + - header: + length: 314 + requestId: 249 + responseTo: 1957747793 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784133794"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"19"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 430352 + created: 1713784133 + reqTimestampMock: 2024-04-22T16:38:53.794777057+05:30 + resTimestampMock: 2024-04-22T16:38:53.795333713+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-6 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }, { SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"66264551a6e962a1cbd50429"},"title":"Hey, let''s Check","description":"It will work"} ] }], checksum: 0 }' + requests: + - header: + length: 207 + requestId: 596516649 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"insert":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }' + - '{ SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"66264551a6e962a1cbd50429"},"title":"Hey, let''s Check","description":"It will work"} ] }' + checksum: 0 + read_delay: 26577872780 + responses: + - header: + length: 45 + requestId: 256 + responseTo: 596516649 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 5437683 + created: 1713784145 + reqTimestampMock: 2024-04-22T16:39:05.816402038+05:30 + resTimestampMock: 2024-04-22T16:39:05.822001482+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-7 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"update":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }, { SectionSingle identifier: updates , msgs: [ {"q":{"_id":{"$oid":"6626362fc7c5eddf174c88e4"}},"u":{"$set":{"title":"Updated again","description":"hey there"}},"multi":false,"upsert":false} ] }], checksum: 0 }' + requests: + - header: + length: 243 + requestId: 1102520059 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"update":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }' + - '{ SectionSingle identifier: updates , msgs: [ {"q":{"_id":{"$oid":"6626362fc7c5eddf174c88e4"}},"u":{"$set":{"title":"Updated again","description":"hey there"}},"multi":false,"upsert":false} ] }' + checksum: 0 + read_delay: 46361192429 + responses: + - header: + length: 60 + requestId: 273 + responseTo: 1102520059 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"nModified":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 5673350 + created: 1713784192 + reqTimestampMock: 2024-04-22T16:39:52.183391788+05:30 + resTimestampMock: 2024-04-22T16:39:52.189223944+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-8 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"delete":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }, { SectionSingle identifier: deletes , msgs: [ {"q":{"_id":{"$oid":"66263667c7c5eddf174c88e5"}},"limit":{"$numberInt":"1"}} ] }], checksum: 0 }' + requests: + - header: + length: 166 + requestId: 1365180540 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"delete":"tasks","ordered":true,"lsid":{"id":{"$binary":{"base64":"2JJr5nwqRNe8aRUchma6xQ==","subType":"04"}}},"$db":"task_manager"} }' + - '{ SectionSingle identifier: deletes , msgs: [ {"q":{"_id":{"$oid":"66263667c7c5eddf174c88e5"}},"limit":{"$numberInt":"1"}} ] }' + checksum: 0 + read_delay: 16427108137 + responses: + - header: + length: 45 + requestId: 286 + responseTo: 1365180540 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 1386879 + created: 1713784208 + reqTimestampMock: 2024-04-22T16:40:08.616520091+05:30 + resTimestampMock: 2024-04-22T16:40:08.61802554+05:30 diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-1.yaml b/flask-mongo-local/keploy/test-set-0/tests/test-1.yaml new file mode 100644 index 0000000..fae2cc0 --- /dev/null +++ b/flask-mongo-local/keploy/test-set-0/tests/test-1.yaml @@ -0,0 +1,66 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-1 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "59" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Task 6","description": "Description for Task 6"}' + timestamp: 2024-04-22T16:38:39.232565209+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "267" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:08:39 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "tasks": [ + { + "description": "should update", + "id": "6626362fc7c5eddf174c88e4", + "title": "Updated" + }, + { + "description": "Should work", + "id": "66263667c7c5eddf174c88e5", + "title": "Let's Check another time" + } + ] + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:38:41.245704918+05:30 + objects: [] + assertions: + noise: + header.Date: [] + created: 1713784121 +curl: |- + curl --request GET \ + --url http://localhost:5000/api/tasks \ + --header 'Host: localhost:5000' \ + --header 'User-Agent: PostmanRuntime/7.32.1' \ + --header 'Accept: */*' \ + --header 'Content-Type: application/json' \ + --header 'Connection: keep-alive' \ + --header 'Cache-Control: no-cache' \ + --header 'Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1' \ + --header 'Accept-Encoding: gzip, deflate, br' \ + --data '{"title": "Task 6","description": "Description for Task 6"}' diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-2.yaml b/flask-mongo-local/keploy/test-set-0/tests/test-2.yaml new file mode 100644 index 0000000..640154f --- /dev/null +++ b/flask-mongo-local/keploy/test-set-0/tests/test-2.yaml @@ -0,0 +1,56 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-2 +spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "57" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 7aabbe61-38ec-4169-a4d8-31cb3546ca01 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title":"Hey, let''s Check","description":"It will work"}' + timestamp: 2024-04-22T16:39:05.814517536+05:30 + resp: + status_code: 201 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "81" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:05 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "id": "66264551a6e962a1cbd50429", + "message": "Task created successfully" + } + status_message: Created + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:07.866639952+05:30 + objects: [] + assertions: + noise: + header.Date: [] + created: 1713784147 +curl: |- + curl --request POST \ + --url http://localhost:5000/api/tasks \ + --header 'Accept-Encoding: gzip, deflate, br' \ + --header 'Connection: keep-alive' \ + --header 'User-Agent: PostmanRuntime/7.32.1' \ + --header 'Host: localhost:5000' \ + --header 'Cache-Control: no-cache' \ + --header 'Accept: */*' \ + --header 'Postman-Token: 7aabbe61-38ec-4169-a4d8-31cb3546ca01' \ + --header 'Content-Type: application/json' \ + --data '{"title":"Hey, let's Check","description":"It will work"}' diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-3.yaml b/flask-mongo-local/keploy/test-set-0/tests/test-3.yaml new file mode 100644 index 0000000..3844c87 --- /dev/null +++ b/flask-mongo-local/keploy/test-set-0/tests/test-3.yaml @@ -0,0 +1,55 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-3 +spec: + metadata: {} + req: + method: PUT + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/6626362fc7c5eddf174c88e4 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Content-Length: "53" + Content-Type: application/json + Host: localhost:5000 + Postman-Token: 89d42b67-eafb-474e-ac5a-1df4982a9fe3 + User-Agent: PostmanRuntime/7.32.1 + body: '{"title": "Updated again","description": "hey there"}' + timestamp: 2024-04-22T16:39:52.181533473+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:09:52 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task updated successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:39:54.273657454+05:30 + objects: [] + assertions: + noise: + header.Date: [] + created: 1713784194 +curl: |- + curl --request PUT \ + --url http://localhost:5000/api/tasks/6626362fc7c5eddf174c88e4 \ + --header 'Accept: */*' \ + --header 'Content-Type: application/json' \ + --header 'User-Agent: PostmanRuntime/7.32.1' \ + --header 'Host: localhost:5000' \ + --header 'Accept-Encoding: gzip, deflate, br' \ + --header 'Cache-Control: no-cache' \ + --header 'Postman-Token: 89d42b67-eafb-474e-ac5a-1df4982a9fe3' \ + --header 'Connection: keep-alive' \ + --data '{"title": "Updated again","description": "hey there"}' diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-4.yaml b/flask-mongo-local/keploy/test-set-0/tests/test-4.yaml new file mode 100644 index 0000000..9888fea --- /dev/null +++ b/flask-mongo-local/keploy/test-set-0/tests/test-4.yaml @@ -0,0 +1,51 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-4 +spec: + metadata: {} + req: + method: DELETE + proto_major: 1 + proto_minor: 1 + url: http://localhost:5000/api/tasks/66263667c7c5eddf174c88e5 + header: + Accept: '*/*' + Accept-Encoding: gzip, deflate, br + Cache-Control: no-cache + Connection: keep-alive + Host: localhost:5000 + Postman-Token: 0f3d6037-f57c-4fb3-be52-e6ffed1566e6 + User-Agent: PostmanRuntime/7.32.1 + body: "" + timestamp: 2024-04-22T16:40:08.615353613+05:30 + resp: + status_code: 200 + header: + Access-Control-Allow-Origin: '*' + Content-Length: "45" + Content-Type: application/json + Date: Mon, 22 Apr 2024 11:10:08 GMT + Server: Werkzeug/3.0.2 Python/3.10.12 + body: | + { + "message": "Task deleted successfully" + } + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-04-22T16:40:10.646676187+05:30 + objects: [] + assertions: + noise: + header.Date: [] + created: 1713784210 +curl: | + curl --request DELETE \ + --url http://localhost:5000/api/tasks/66263667c7c5eddf174c88e5 \ + --header 'Accept-Encoding: gzip, deflate, br' \ + --header 'Connection: keep-alive' \ + --header 'User-Agent: PostmanRuntime/7.32.1' \ + --header 'Accept: */*' \ + --header 'Cache-Control: no-cache' \ + --header 'Postman-Token: 0f3d6037-f57c-4fb3-be52-e6ffed1566e6' \ + --header 'Host: localhost:5000' \ diff --git a/flask-mongo-local/postman_tests/delete.js b/flask-mongo-local/postman_tests/delete.js new file mode 100644 index 0000000..a2e8f13 --- /dev/null +++ b/flask-mongo-local/postman_tests/delete.js @@ -0,0 +1,17 @@ +pm.test("Status code is 200 or 404", function () { + pm.expect(pm.response.code).to.be.oneOf([200, 404]); +}); + +pm.test("Successful deletion response message", function () { + if (pm.response.code === 200) { + var jsonData = pm.response.json(); + pm.expect(jsonData.message).to.eql("Task deleted successfully"); + } +}); + +pm.test("Task not found", function () { + if (pm.response.code === 404) { + var jsonData = pm.response.json(); + pm.expect(jsonData.error).to.eql("Task not found"); + } +}); diff --git a/flask-mongo-local/postman_tests/get.js b/flask-mongo-local/postman_tests/get.js new file mode 100644 index 0000000..74b758a --- /dev/null +++ b/flask-mongo-local/postman_tests/get.js @@ -0,0 +1,17 @@ +pm.test("Status code is 200", function () { + pm.response.to.have.status(200); +}); + +pm.test("Response is an array", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData.tasks).to.be.an("array"); +}); + +pm.test("Each task has an id, title, and description", function () { + var jsonData = pm.response.json(); + jsonData.tasks.forEach(function (task) { + pm.expect(task).to.have.property("id"); + pm.expect(task).to.have.property("title"); + pm.expect(task).to.have.property("description"); + }); +}); diff --git a/flask-mongo-local/postman_tests/post.js b/flask-mongo-local/postman_tests/post.js new file mode 100644 index 0000000..9efeeb8 --- /dev/null +++ b/flask-mongo-local/postman_tests/post.js @@ -0,0 +1,14 @@ +pm.test("Status code is 201", function () { + pm.response.to.have.status(201); +}); + +pm.test("Response contains task ID", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData).to.have.property("id"); + pm.expect(jsonData.id).to.not.be.empty; +}); + +pm.test("Response message is correct", function () { + var jsonData = pm.response.json(); + pm.expect(jsonData.message).to.eql("Task created successfully"); +}); diff --git a/flask-mongo-local/postman_tests/put.js b/flask-mongo-local/postman_tests/put.js new file mode 100644 index 0000000..d8af377 --- /dev/null +++ b/flask-mongo-local/postman_tests/put.js @@ -0,0 +1,17 @@ +pm.test("Status code is 200 or 404", function () { + pm.expect(pm.response.code).to.be.oneOf([200, 404]); +}); + +pm.test("Successful update response message", function () { + if (pm.response.code === 200) { + var jsonData = pm.response.json(); + pm.expect(jsonData.message).to.eql("Task updated successfully"); + } +}); + +pm.test("Task not found or no changes made", function () { + if (pm.response.code === 404) { + var jsonData = pm.response.json(); + pm.expect(jsonData.error).to.eql("Task not found or no changes were made"); + } +}); diff --git a/flask-mongo-local/requirements.txt b/flask-mongo-local/requirements.txt new file mode 100644 index 0000000..7230e6a --- /dev/null +++ b/flask-mongo-local/requirements.txt @@ -0,0 +1,5 @@ +Flask==3.0.3 +Flask-Cors==4.0.0 +pymongo==4.6.3 +coverage==7.4.4 + diff --git a/flask-mongo-local/test_app.py b/flask-mongo-local/test_app.py new file mode 100644 index 0000000..30cf13f --- /dev/null +++ b/flask-mongo-local/test_app.py @@ -0,0 +1,45 @@ +import unittest +from app import app +from unittest.mock import patch, MagicMock +import json +from bson import ObjectId + +class TestTaskManager(unittest.TestCase): + + def setUp(self): + self.app = app.test_client() + self.app.testing = True + + self.collection_mock = MagicMock() + self.patcher = patch('app.collection', self.collection_mock) + self.patcher.start() + + def tearDown(self): + self.patcher.stop() + + def test_create_task(self): + data = {'title': 'Test Task', 'description': 'This is a test task'} + response = self.app.post('/api/tasks', json=data) + self.assertEqual(response.status_code, 201) + self.assertIn(b'Task created successfully', response.data) + + def test_get_all_tasks(self): + self.collection_mock.find.return_value = [] + response = self.app.get('/api/tasks') + self.assertEqual(response.status_code, 200) + self.assertEqual(json.loads(response.data)['tasks'], []) + + def test_update_task(self): + with patch('app.ObjectId', return_value='mocked_id'): + response = self.app.put('/api/tasks/mock_id', json={'title': 'Updated Task', 'description': 'This is an updated task'}) + self.assertEqual(response.status_code, 200) + self.assertIn(b'Task updated successfully', response.data) + + def test_delete_task(self): + with patch('app.ObjectId', return_value=ObjectId()): + response = self.app.delete('/api/tasks/mock_id') + self.assertEqual(response.status_code, 200) + self.assertIn(b'Task deleted successfully', response.data) + +if __name__ == '__main__': + unittest.main() diff --git a/flask-mongo-local/test_keploy.py b/flask-mongo-local/test_keploy.py new file mode 100644 index 0000000..4ee126a --- /dev/null +++ b/flask-mongo-local/test_keploy.py @@ -0,0 +1,8 @@ +from keploy import run, RunOptions + +def test_keploy(): + try: + options = RunOptions(delay=15, debug=False, port=0) + except ValueError as e: + print(e) + run("python3 -m coverage run -p --data-file=.coverage.keploy app.py", options) \ No newline at end of file From 68a2e71c530a876002f0465047265aab5a38e5c3 Mon Sep 17 00:00:00 2001 From: Swapnoneel Saha Date: Thu, 25 Apr 2024 20:08:28 +0530 Subject: [PATCH 2/5] Added README for sample-mongo-flask-local app Signed-off-by: Swapnoneel Saha --- flask-mongo-local/README.md | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 flask-mongo-local/README.md diff --git a/flask-mongo-local/README.md b/flask-mongo-local/README.md new file mode 100644 index 0000000..2d79824 --- /dev/null +++ b/flask-mongo-local/README.md @@ -0,0 +1,102 @@ +# Sample Flask+Mongo app to demo Keploy + +## Clone the sample flask-mongo application + +```bash +git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo-local +``` + +## Install all dependencies + +```bash +pip install -r requirements.txt +``` + +## Start the MongoDB server + +```bash +sudo service mongod start +``` + +## Setup Keploy + +Let's get started by setting up the Keploy alias with this command: + +```bash +curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh +``` + +You should see something like this: + +```bash + โ–“โ–ˆโ–ˆโ–“โ–„ + โ–“โ–“โ–“โ–“โ–ˆโ–ˆโ–“โ–ˆโ–“โ–„ + โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–“โ–’ + โ–€โ–“โ–“โ–ˆโ–ˆโ–ˆโ–„ โ–„โ–„ โ–„ โ–Œ + โ–„โ–Œโ–Œโ–“โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–„ โ–ˆโ–ˆ โ–“โ–ˆโ–€ โ–„โ–Œโ–€โ–„ โ–“โ–“โ–Œโ–„ โ–“โ–ˆ โ–„โ–Œโ–“โ–“โ–Œโ–„ โ–Œโ–Œ โ–“ + โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œโ–“โ–“ โ–ˆโ–ˆโ–“โ–ˆโ–„ โ–“โ–ˆโ–„โ–“โ–“ โ–โ–ˆโ–Œ โ–ˆโ–ˆ โ–“โ–ˆ โ–ˆโ–Œ โ–ˆโ–ˆ โ–ˆโ–Œ โ–ˆโ–“ + โ–“โ–“โ–“โ–“โ–€โ–€โ–€โ–€โ–“โ–“โ–“โ–“โ–“โ–“โ–Œ โ–ˆโ–ˆ โ–ˆโ–“ โ–“โ–Œโ–„โ–„ โ–โ–ˆโ–“โ–„โ–“โ–ˆโ–€ โ–ˆโ–“โ–ˆ โ–€โ–ˆโ–„โ–„โ–ˆโ–€ โ–ˆโ–“โ–ˆ + โ–“โ–Œ โ–โ–ˆโ–Œ โ–ˆโ–Œ + โ–“ + +Keploy CLI + +Available Commands: + example Example to record and test via keploy + generate-config generate the keploy configuration file + record record the keploy testcases from the API calls + test run the recorded testcases and execute assertions + update Update Keploy + +Flags: + --debug Run in debug mode + -h, --help help for keploy + -v, --version version for keploy + +Use "keploy [command] --help" for more information about a command. +``` + +## Lights, Camera, Record! ๐ŸŽฅ + +To initiate the recording of API calls, execute this command in your terminal: + +```bash +keploy record -c "python3 app.py" +``` + +Now, your app will start running, and you have to make some API calls!! + +And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`. + +## Check Test Coverage + +We have a `test-app.py` where all the unit test cases has been written. Now using Keploy, we can check it's code coverage!! +Now to run your unit tests with Keploy, you can run the command given below: + +```bash +python3 -m coverage run -p --data-file=.coverage.unit -m pytest -s test_keploy.py test_app.py +``` + +To combine the coverage from the unit tests, and Keploy's API tests we can use the command below: + +```bash +python3 -m coverage combine +``` + +Finally, to generate the coverage report for the test run, you can run: + +```bash +python3 -m coverage report +``` + +and if you want the coverage in an html file, you can run: + +```bash +python3 -m coverage html +``` + +## Wrapping it up ๐ŸŽ‰ + +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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ From 20388013dae132fdabdcc9ea56a553c5704fdc2d Mon Sep 17 00:00:00 2001 From: Swapnoneel Saha Date: Thu, 9 May 2024 20:46:47 +0530 Subject: [PATCH 3/5] restructured the folders Signed-off-by: Swapnoneel Saha --- docker-mongo/app.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docker-mongo/app.py diff --git a/docker-mongo/app.py b/docker-mongo/app.py new file mode 100644 index 0000000..6e31416 --- /dev/null +++ b/docker-mongo/app.py @@ -0,0 +1,42 @@ +from flask import Flask, request, jsonify +from pymongo import MongoClient +from flask_cors import CORS +import collections.abc + +app = Flask(__name__) +cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) + +# Connect to MongoDB +client = MongoClient('mongodb://mongo:27017/') +db = client['studentsdb'] +students_collection = db['students'] + +@app.route('/students', methods=['GET']) +def get_students(): + students = list(students_collection.find({}, {'_id': 0})) + return jsonify(students) + +@app.route('/students/', methods=['GET']) +def get_student(student_id): + student = students_collection.find_one({'student_id': student_id}, {'_id': 0}) + return jsonify(student) + +@app.route('/students', methods=['POST']) +def create_student(): + new_student = request.json + students_collection.insert_one(new_student) + return jsonify({'message': 'Student created successfully'}) + +@app.route('/students/', methods=['PUT']) +def update_student(student_id): + updated_student = request.json + students_collection.update_one({'student_id': student_id}, {'$set': updated_student}) + return jsonify({'message': 'Student updated successfully'}) + +@app.route('/students/', methods=['DELETE']) +def delete_student(student_id): + students_collection.delete_one({'student_id': student_id}) + return jsonify({'message': 'Student deleted successfully'}) + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=6000, debug=True) From 8138b07f2e6494aa460661e7499249b2f6f81196 Mon Sep 17 00:00:00 2001 From: Swapnoneel Saha Date: Thu, 9 May 2024 20:47:59 +0530 Subject: [PATCH 4/5] renamed two directories Signed-off-by: Swapnoneel Saha --- .../Dockerfile | 0 .../README.md | 0 .../docker-compose.yml | 0 .../keploy/test-set-1/config.yaml | 0 .../keploy/test-set-1/mocks.yaml | 0 .../keploy/test-set-1/test-1.yaml | 0 .../keploy/test-set-1/test-2.yaml | 0 .../keploy/testReports/report-1.yaml | 0 .../requirements.txt | 0 flask-mongo-docker/app.py | 42 ------------------ {flask-mongo-local => rest-mongo}/.coverage | Bin {flask-mongo-local => rest-mongo}/.coveragerc | 0 {flask-mongo-local => rest-mongo}/README.md | 0 .../__pycache__/app.cpython-310.pyc | Bin .../test_app.cpython-310-pytest-8.1.1.pyc | Bin .../__pycache__/test_app.cpython-310.pyc | Bin .../test_keploy.cpython-310-pytest-8.1.1.pyc | Bin {flask-mongo-local => rest-mongo}/app.py | 0 .../reports/test-run-0/test-set-0-report.yaml | 0 .../reports/test-run-1/test-set-0-report.yaml | 0 .../keploy/test-set-0/mocks.yaml | 0 .../keploy/test-set-0/tests/test-1.yaml | 0 .../keploy/test-set-0/tests/test-2.yaml | 0 .../keploy/test-set-0/tests/test-3.yaml | 0 .../keploy/test-set-0/tests/test-4.yaml | 0 .../postman_tests/delete.js | 0 .../postman_tests/get.js | 0 .../postman_tests/post.js | 0 .../postman_tests/put.js | 0 .../requirements.txt | 0 {flask-mongo-local => rest-mongo}/test_app.py | 0 .../test_keploy.py | 0 32 files changed, 42 deletions(-) rename {flask-mongo-docker => docker-mongo}/Dockerfile (100%) rename {flask-mongo-docker => docker-mongo}/README.md (100%) rename {flask-mongo-docker => docker-mongo}/docker-compose.yml (100%) rename {flask-mongo-docker => docker-mongo}/keploy/test-set-1/config.yaml (100%) rename {flask-mongo-docker => docker-mongo}/keploy/test-set-1/mocks.yaml (100%) rename {flask-mongo-docker => docker-mongo}/keploy/test-set-1/test-1.yaml (100%) rename {flask-mongo-docker => docker-mongo}/keploy/test-set-1/test-2.yaml (100%) rename {flask-mongo-docker => docker-mongo}/keploy/testReports/report-1.yaml (100%) rename {flask-mongo-docker => docker-mongo}/requirements.txt (100%) delete mode 100644 flask-mongo-docker/app.py rename {flask-mongo-local => rest-mongo}/.coverage (100%) rename {flask-mongo-local => rest-mongo}/.coveragerc (100%) rename {flask-mongo-local => rest-mongo}/README.md (100%) rename {flask-mongo-local => rest-mongo}/__pycache__/app.cpython-310.pyc (100%) rename {flask-mongo-local => rest-mongo}/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc (100%) rename {flask-mongo-local => rest-mongo}/__pycache__/test_app.cpython-310.pyc (100%) rename {flask-mongo-local => rest-mongo}/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc (100%) rename {flask-mongo-local => rest-mongo}/app.py (100%) rename {flask-mongo-local => rest-mongo}/keploy/reports/test-run-0/test-set-0-report.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/reports/test-run-1/test-set-0-report.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/test-set-0/mocks.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/test-set-0/tests/test-1.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/test-set-0/tests/test-2.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/test-set-0/tests/test-3.yaml (100%) rename {flask-mongo-local => rest-mongo}/keploy/test-set-0/tests/test-4.yaml (100%) rename {flask-mongo-local => rest-mongo}/postman_tests/delete.js (100%) rename {flask-mongo-local => rest-mongo}/postman_tests/get.js (100%) rename {flask-mongo-local => rest-mongo}/postman_tests/post.js (100%) rename {flask-mongo-local => rest-mongo}/postman_tests/put.js (100%) rename {flask-mongo-local => rest-mongo}/requirements.txt (100%) rename {flask-mongo-local => rest-mongo}/test_app.py (100%) rename {flask-mongo-local => rest-mongo}/test_keploy.py (100%) diff --git a/flask-mongo-docker/Dockerfile b/docker-mongo/Dockerfile similarity index 100% rename from flask-mongo-docker/Dockerfile rename to docker-mongo/Dockerfile diff --git a/flask-mongo-docker/README.md b/docker-mongo/README.md similarity index 100% rename from flask-mongo-docker/README.md rename to docker-mongo/README.md diff --git a/flask-mongo-docker/docker-compose.yml b/docker-mongo/docker-compose.yml similarity index 100% rename from flask-mongo-docker/docker-compose.yml rename to docker-mongo/docker-compose.yml diff --git a/flask-mongo-docker/keploy/test-set-1/config.yaml b/docker-mongo/keploy/test-set-1/config.yaml similarity index 100% rename from flask-mongo-docker/keploy/test-set-1/config.yaml rename to docker-mongo/keploy/test-set-1/config.yaml diff --git a/flask-mongo-docker/keploy/test-set-1/mocks.yaml b/docker-mongo/keploy/test-set-1/mocks.yaml similarity index 100% rename from flask-mongo-docker/keploy/test-set-1/mocks.yaml rename to docker-mongo/keploy/test-set-1/mocks.yaml diff --git a/flask-mongo-docker/keploy/test-set-1/test-1.yaml b/docker-mongo/keploy/test-set-1/test-1.yaml similarity index 100% rename from flask-mongo-docker/keploy/test-set-1/test-1.yaml rename to docker-mongo/keploy/test-set-1/test-1.yaml diff --git a/flask-mongo-docker/keploy/test-set-1/test-2.yaml b/docker-mongo/keploy/test-set-1/test-2.yaml similarity index 100% rename from flask-mongo-docker/keploy/test-set-1/test-2.yaml rename to docker-mongo/keploy/test-set-1/test-2.yaml diff --git a/flask-mongo-docker/keploy/testReports/report-1.yaml b/docker-mongo/keploy/testReports/report-1.yaml similarity index 100% rename from flask-mongo-docker/keploy/testReports/report-1.yaml rename to docker-mongo/keploy/testReports/report-1.yaml diff --git a/flask-mongo-docker/requirements.txt b/docker-mongo/requirements.txt similarity index 100% rename from flask-mongo-docker/requirements.txt rename to docker-mongo/requirements.txt diff --git a/flask-mongo-docker/app.py b/flask-mongo-docker/app.py deleted file mode 100644 index 6e31416..0000000 --- a/flask-mongo-docker/app.py +++ /dev/null @@ -1,42 +0,0 @@ -from flask import Flask, request, jsonify -from pymongo import MongoClient -from flask_cors import CORS -import collections.abc - -app = Flask(__name__) -cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) - -# Connect to MongoDB -client = MongoClient('mongodb://mongo:27017/') -db = client['studentsdb'] -students_collection = db['students'] - -@app.route('/students', methods=['GET']) -def get_students(): - students = list(students_collection.find({}, {'_id': 0})) - return jsonify(students) - -@app.route('/students/', methods=['GET']) -def get_student(student_id): - student = students_collection.find_one({'student_id': student_id}, {'_id': 0}) - return jsonify(student) - -@app.route('/students', methods=['POST']) -def create_student(): - new_student = request.json - students_collection.insert_one(new_student) - return jsonify({'message': 'Student created successfully'}) - -@app.route('/students/', methods=['PUT']) -def update_student(student_id): - updated_student = request.json - students_collection.update_one({'student_id': student_id}, {'$set': updated_student}) - return jsonify({'message': 'Student updated successfully'}) - -@app.route('/students/', methods=['DELETE']) -def delete_student(student_id): - students_collection.delete_one({'student_id': student_id}) - return jsonify({'message': 'Student deleted successfully'}) - -if __name__ == '__main__': - app.run(host='0.0.0.0', port=6000, debug=True) diff --git a/flask-mongo-local/.coverage b/rest-mongo/.coverage similarity index 100% rename from flask-mongo-local/.coverage rename to rest-mongo/.coverage diff --git a/flask-mongo-local/.coveragerc b/rest-mongo/.coveragerc similarity index 100% rename from flask-mongo-local/.coveragerc rename to rest-mongo/.coveragerc diff --git a/flask-mongo-local/README.md b/rest-mongo/README.md similarity index 100% rename from flask-mongo-local/README.md rename to rest-mongo/README.md diff --git a/flask-mongo-local/__pycache__/app.cpython-310.pyc b/rest-mongo/__pycache__/app.cpython-310.pyc similarity index 100% rename from flask-mongo-local/__pycache__/app.cpython-310.pyc rename to rest-mongo/__pycache__/app.cpython-310.pyc diff --git a/flask-mongo-local/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc b/rest-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc similarity index 100% rename from flask-mongo-local/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc rename to rest-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc diff --git a/flask-mongo-local/__pycache__/test_app.cpython-310.pyc b/rest-mongo/__pycache__/test_app.cpython-310.pyc similarity index 100% rename from flask-mongo-local/__pycache__/test_app.cpython-310.pyc rename to rest-mongo/__pycache__/test_app.cpython-310.pyc diff --git a/flask-mongo-local/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc b/rest-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc similarity index 100% rename from flask-mongo-local/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc rename to rest-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc diff --git a/flask-mongo-local/app.py b/rest-mongo/app.py similarity index 100% rename from flask-mongo-local/app.py rename to rest-mongo/app.py diff --git a/flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml b/rest-mongo/keploy/reports/test-run-0/test-set-0-report.yaml similarity index 100% rename from flask-mongo-local/keploy/reports/test-run-0/test-set-0-report.yaml rename to rest-mongo/keploy/reports/test-run-0/test-set-0-report.yaml diff --git a/flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml b/rest-mongo/keploy/reports/test-run-1/test-set-0-report.yaml similarity index 100% rename from flask-mongo-local/keploy/reports/test-run-1/test-set-0-report.yaml rename to rest-mongo/keploy/reports/test-run-1/test-set-0-report.yaml diff --git a/flask-mongo-local/keploy/test-set-0/mocks.yaml b/rest-mongo/keploy/test-set-0/mocks.yaml similarity index 100% rename from flask-mongo-local/keploy/test-set-0/mocks.yaml rename to rest-mongo/keploy/test-set-0/mocks.yaml diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-1.yaml b/rest-mongo/keploy/test-set-0/tests/test-1.yaml similarity index 100% rename from flask-mongo-local/keploy/test-set-0/tests/test-1.yaml rename to rest-mongo/keploy/test-set-0/tests/test-1.yaml diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-2.yaml b/rest-mongo/keploy/test-set-0/tests/test-2.yaml similarity index 100% rename from flask-mongo-local/keploy/test-set-0/tests/test-2.yaml rename to rest-mongo/keploy/test-set-0/tests/test-2.yaml diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-3.yaml b/rest-mongo/keploy/test-set-0/tests/test-3.yaml similarity index 100% rename from flask-mongo-local/keploy/test-set-0/tests/test-3.yaml rename to rest-mongo/keploy/test-set-0/tests/test-3.yaml diff --git a/flask-mongo-local/keploy/test-set-0/tests/test-4.yaml b/rest-mongo/keploy/test-set-0/tests/test-4.yaml similarity index 100% rename from flask-mongo-local/keploy/test-set-0/tests/test-4.yaml rename to rest-mongo/keploy/test-set-0/tests/test-4.yaml diff --git a/flask-mongo-local/postman_tests/delete.js b/rest-mongo/postman_tests/delete.js similarity index 100% rename from flask-mongo-local/postman_tests/delete.js rename to rest-mongo/postman_tests/delete.js diff --git a/flask-mongo-local/postman_tests/get.js b/rest-mongo/postman_tests/get.js similarity index 100% rename from flask-mongo-local/postman_tests/get.js rename to rest-mongo/postman_tests/get.js diff --git a/flask-mongo-local/postman_tests/post.js b/rest-mongo/postman_tests/post.js similarity index 100% rename from flask-mongo-local/postman_tests/post.js rename to rest-mongo/postman_tests/post.js diff --git a/flask-mongo-local/postman_tests/put.js b/rest-mongo/postman_tests/put.js similarity index 100% rename from flask-mongo-local/postman_tests/put.js rename to rest-mongo/postman_tests/put.js diff --git a/flask-mongo-local/requirements.txt b/rest-mongo/requirements.txt similarity index 100% rename from flask-mongo-local/requirements.txt rename to rest-mongo/requirements.txt diff --git a/flask-mongo-local/test_app.py b/rest-mongo/test_app.py similarity index 100% rename from flask-mongo-local/test_app.py rename to rest-mongo/test_app.py diff --git a/flask-mongo-local/test_keploy.py b/rest-mongo/test_keploy.py similarity index 100% rename from flask-mongo-local/test_keploy.py rename to rest-mongo/test_keploy.py From 38a67c2eb4c9ecb34488a15f8f62365b68dd049c Mon Sep 17 00:00:00 2001 From: Swapnoneel Saha Date: Sun, 26 May 2024 23:44:53 +0530 Subject: [PATCH 5/5] merged the local and docker flask + mongo apps Signed-off-by: Swapnoneel Saha --- docker-mongo/Dockerfile | 17 - docker-mongo/README.md | 600 ---------------- docker-mongo/app.py | 42 -- docker-mongo/docker-compose.yml | 29 - docker-mongo/keploy/test-set-1/config.yaml | 167 ----- docker-mongo/keploy/test-set-1/mocks.yaml | 64 -- docker-mongo/keploy/test-set-1/test-1.yaml | 38 -- docker-mongo/keploy/test-set-1/test-2.yaml | 34 - docker-mongo/keploy/testReports/report-1.yaml | 181 ----- docker-mongo/requirements.txt | 4 - {rest-mongo => flask-mongo}/.coverage | Bin {rest-mongo => flask-mongo}/.coveragerc | 0 flask-mongo/Dockerfile | 4 +- flask-mongo/README.md | 642 ++---------------- .../__pycache__/app.cpython-310.pyc | Bin .../test_app.cpython-310-pytest-8.1.1.pyc | Bin .../__pycache__/test_app.cpython-310.pyc | Bin .../test_keploy.cpython-310-pytest-8.1.1.pyc | Bin flask-mongo/app.py | 80 ++- flask-mongo/docker-compose.yml | 4 +- .../reports/test-run-0/test-set-0-report.yaml | 0 .../reports/test-run-1/test-set-0-report.yaml | 0 .../keploy/test-set-0/mocks.yaml | 0 .../keploy/test-set-0/tests/test-1.yaml | 0 .../keploy/test-set-0/tests/test-2.yaml | 0 .../keploy/test-set-0/tests/test-3.yaml | 0 .../keploy/test-set-0/tests/test-4.yaml | 0 flask-mongo/keploy/test-set-1/config.yaml | 167 ----- flask-mongo/keploy/test-set-1/mocks.yaml | 64 -- flask-mongo/keploy/test-set-1/test-1.yaml | 38 -- flask-mongo/keploy/test-set-1/test-2.yaml | 34 - flask-mongo/keploy/testReports/report-1.yaml | 181 ----- .../postman_tests/delete.js | 0 .../postman_tests/get.js | 0 .../postman_tests/post.js | 0 .../postman_tests/put.js | 0 flask-mongo/requirements.txt | 10 +- {rest-mongo => flask-mongo}/test_app.py | 0 {rest-mongo => flask-mongo}/test_keploy.py | 0 rest-mongo/README.md | 102 --- rest-mongo/app.py | 56 -- rest-mongo/requirements.txt | 5 - 42 files changed, 129 insertions(+), 2434 deletions(-) delete mode 100644 docker-mongo/Dockerfile delete mode 100644 docker-mongo/README.md delete mode 100644 docker-mongo/app.py delete mode 100644 docker-mongo/docker-compose.yml delete mode 100644 docker-mongo/keploy/test-set-1/config.yaml delete mode 100644 docker-mongo/keploy/test-set-1/mocks.yaml delete mode 100644 docker-mongo/keploy/test-set-1/test-1.yaml delete mode 100644 docker-mongo/keploy/test-set-1/test-2.yaml delete mode 100644 docker-mongo/keploy/testReports/report-1.yaml delete mode 100644 docker-mongo/requirements.txt rename {rest-mongo => flask-mongo}/.coverage (100%) rename {rest-mongo => flask-mongo}/.coveragerc (100%) rename {rest-mongo => flask-mongo}/__pycache__/app.cpython-310.pyc (100%) rename {rest-mongo => flask-mongo}/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc (100%) rename {rest-mongo => flask-mongo}/__pycache__/test_app.cpython-310.pyc (100%) rename {rest-mongo => flask-mongo}/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc (100%) rename {rest-mongo => flask-mongo}/keploy/reports/test-run-0/test-set-0-report.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/reports/test-run-1/test-set-0-report.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/test-set-0/mocks.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/test-set-0/tests/test-1.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/test-set-0/tests/test-2.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/test-set-0/tests/test-3.yaml (100%) rename {rest-mongo => flask-mongo}/keploy/test-set-0/tests/test-4.yaml (100%) delete mode 100755 flask-mongo/keploy/test-set-1/config.yaml delete mode 100755 flask-mongo/keploy/test-set-1/mocks.yaml delete mode 100755 flask-mongo/keploy/test-set-1/test-1.yaml delete mode 100755 flask-mongo/keploy/test-set-1/test-2.yaml delete mode 100755 flask-mongo/keploy/testReports/report-1.yaml rename {rest-mongo => flask-mongo}/postman_tests/delete.js (100%) rename {rest-mongo => flask-mongo}/postman_tests/get.js (100%) rename {rest-mongo => flask-mongo}/postman_tests/post.js (100%) rename {rest-mongo => flask-mongo}/postman_tests/put.js (100%) rename {rest-mongo => flask-mongo}/test_app.py (100%) rename {rest-mongo => flask-mongo}/test_keploy.py (100%) delete mode 100644 rest-mongo/README.md delete mode 100644 rest-mongo/app.py delete mode 100644 rest-mongo/requirements.txt diff --git a/docker-mongo/Dockerfile b/docker-mongo/Dockerfile deleted file mode 100644 index cbefd2c..0000000 --- a/docker-mongo/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -# Use the official Python image as the base image -FROM python:3.9 - -# Set the working directory within the container -WORKDIR /app - -# Copy the application code into the container -COPY . . - -# Install the required packages -RUN pip3 install -r requirements.txt - -# Expose the port that the Flask app will run on -EXPOSE 6000 - -# Start the Flask application -CMD ["python3", "app.py"] diff --git a/docker-mongo/README.md b/docker-mongo/README.md deleted file mode 100644 index 54bc693..0000000 --- a/docker-mongo/README.md +++ /dev/null @@ -1,600 +0,0 @@ -This application is a simple student management API built using Python's Flask framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on student records. The API supports CORS (Cross-Origin Resource Sharing) to facilitate cross-domain requests. - -## Table of Contents - -# Introduction - -๐Ÿช„ Dive into the world of Student CRUD Apps and see how seamlessly Keploy integrated with [Flask](https://flask.palletsprojects.com/en/3.0.x/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! ๐ŸŽข - -## Pre-Requisite ๐Ÿ› ๏ธ - -- Install WSL (`wsl --install`) for Windows Windows. - -## Optional ๐Ÿ› ๏ธ - -- Install Colima( `brew install colima && colima start` ) for MacOS MacOs. - -## Get Started! ๐ŸŽฌ - -## Setup the MongoDB Database ๐Ÿ“ฆ - -Create a docker network, run - - -```bash -docker network create backend -``` - -Start the MongoDB instance- - -```bash -docker run -p 27017:27017 -d --network backend --name mongo mongo -``` - -## Clone a simple Student Management API ๐Ÿงช - -```bash -git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo -``` - -## Installation ๐Ÿ“ฅ - -Depending on your OS, choose your adventure: - --
- Linux Linux or Windows Windows - - Alright, let's equip ourselves with the **latest Keploy binary**: - - ```bash - 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 && keploy - ``` - - If everything goes right, your screen should look a bit like this: - - Moving on... -
- Run App with Docker Container Docker - - #### Add alias for Keploy: - - ```bash - alias 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' - ``` - - ### Lights, Camera, Record! ๐ŸŽฅ - - Build the app image: - - ```bash - docker build -t flask-app:1.0 . - ``` - - Capture the test-cases- - - ```shell - keploy record -c "docker run -p 6000:6000 --name flask-app --network backend flask-app:1.0" - ``` - - ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! - - Let's make URLs short and sweet: - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - -
-
- -
- Run App on ๐Ÿง Linux - - We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (PostgreSQL) chill on Docker. Ready? Let's get the party started!๐ŸŽ‰ - - ### ๐Ÿ“ผ Roll the Tape - Recording Time! - - Install the dependencies: - - ```bash - pip install -r requirements.txt - ``` - - Now, let's Capture the test-cases- - - In `app.py`, replace the MongoDB connection URL with - `mongodb://0.0.0.0:27017/` - - Ready, set, record! Here's how: - - ```bash - keploy record -c "python3 app.py" - ``` - - Keep an eye out for the `-c `flag! It's the command charm to run the app. - - Alright, magician! With the app alive and kicking, let's weave some test cases. The spell? Making some API calls! Postman, Hoppscotch, or the classic curl - pick your wand. - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "python3 app.py" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ -
- -
- -
- --
- MacOS MacOs - - Dive straight in, but first in case you're using **Keploy** with **Colima**, give it a gentle nudge with (`colima start`). Let's make sure it's awake and ready for action! - - ### Add alias for Keploy ๐Ÿฐ: - - For the sake of convenience (and a bit of Mac magic ๐Ÿช„), let's set up a shortcut for Keploy: - - ### Use Keploy with Docker-Desktop - - Note: To run Keploy on MacOS through [Docker](https://docs.docker.com/desktop/release-notes/#4252) the version must be `4.25.2` or above. - - #### Creating Docker Volume - - ```bash - docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs - ``` - - ```bash - alias 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 debugfs:/sys/kernel/debug:rw -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' - ``` - - ### Use Keploy with Colima - - ```bash - alias 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' - ``` - - ### Lights, Camera, Record! ๐ŸŽฅ - - Build the app image: - - ```bash - docker build -t flask-app:1.0 . - ``` - - Capture the test-cases- - - ```shell - keploy record -c "docker run -p 6000:6000 --name DjangoApp --network backend --name flask-app flask-app:1.0" - ``` - - ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! - - Let's make URLs short and sweet: - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ -
diff --git a/docker-mongo/app.py b/docker-mongo/app.py deleted file mode 100644 index 6e31416..0000000 --- a/docker-mongo/app.py +++ /dev/null @@ -1,42 +0,0 @@ -from flask import Flask, request, jsonify -from pymongo import MongoClient -from flask_cors import CORS -import collections.abc - -app = Flask(__name__) -cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) - -# Connect to MongoDB -client = MongoClient('mongodb://mongo:27017/') -db = client['studentsdb'] -students_collection = db['students'] - -@app.route('/students', methods=['GET']) -def get_students(): - students = list(students_collection.find({}, {'_id': 0})) - return jsonify(students) - -@app.route('/students/', methods=['GET']) -def get_student(student_id): - student = students_collection.find_one({'student_id': student_id}, {'_id': 0}) - return jsonify(student) - -@app.route('/students', methods=['POST']) -def create_student(): - new_student = request.json - students_collection.insert_one(new_student) - return jsonify({'message': 'Student created successfully'}) - -@app.route('/students/', methods=['PUT']) -def update_student(student_id): - updated_student = request.json - students_collection.update_one({'student_id': student_id}, {'$set': updated_student}) - return jsonify({'message': 'Student updated successfully'}) - -@app.route('/students/', methods=['DELETE']) -def delete_student(student_id): - students_collection.delete_one({'student_id': student_id}) - return jsonify({'message': 'Student deleted successfully'}) - -if __name__ == '__main__': - app.run(host='0.0.0.0', port=6000, debug=True) diff --git a/docker-mongo/docker-compose.yml b/docker-mongo/docker-compose.yml deleted file mode 100644 index 7ef7346..0000000 --- a/docker-mongo/docker-compose.yml +++ /dev/null @@ -1,29 +0,0 @@ -version: '3' -services: - mongo: - image: mongo - container_name: mongo - ports: - - "27017:27017" - volumes: - - data:/data/db - networks: - - backend - - flask-app: - image: flask-app:1.0 - container_name: flask-app - build: - context: . - ports: - - "6000:6000" - depends_on: - - mongo - networks: - - backend - -networks: - backend: - external: true -volumes: - data: diff --git a/docker-mongo/keploy/test-set-1/config.yaml b/docker-mongo/keploy/test-set-1/config.yaml deleted file mode 100644 index e451518..0000000 --- a/docker-mongo/keploy/test-set-1/config.yaml +++ /dev/null @@ -1,167 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"}}, returnFieldsSelector: }' - requests: - - header: - length: 262 - requestId: 1890541915 - responseTo: 0 - Opcode: 2004 - message: - flags: 0 - collection_name: admin.$cmd - number_to_skip: 0 - number_to_return: -1 - query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"}}' - return_fields_selector: "" - read_delay: 82208 - responses: - - header: - length: 329 - requestId: 3 - responseTo: 1890541915 - Opcode: 1 - message: - response_flags: 8 - cursor_id: 0 - starting_from: 0 - number_returned: 1 - documents: - - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448932"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' - read_delay: 659750 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"},"compression": []}, returnFieldsSelector: }' - requests: - - header: - length: 280 - requestId: 1076681270 - responseTo: 0 - Opcode: 2004 - message: - flags: 0 - collection_name: admin.$cmd - number_to_skip: 0 - number_to_return: -1 - query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"},"compression":[]}' - return_fields_selector: "" - read_delay: 51917 - responses: - - header: - length: 329 - requestId: 4 - responseTo: 1076681270 - Opcode: 1 - message: - response_flags: 8 - cursor_id: 0 - starting_from: 0 - number_returned: 1 - documents: - - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448936"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"2"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' - read_delay: 999250 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 65536, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 134 - requestId: 613273587 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 65536 - sections: - - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }' - checksum: 0 - read_delay: 3336333 - responses: - - header: - length: 313 - requestId: 10 - responseTo: 613273587 - Opcode: 2013 - message: - flagBits: 2 - sections: - - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458940"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 10005077213 - created: 1692190458 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 52 - requestId: 1075693109 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }' - checksum: 0 - read_delay: 10043184088 - responses: - - header: - length: 313 - requestId: 11 - responseTo: 1075693109 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458982"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 746417 - created: 1692190458 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 65 - requestId: 1299455543 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }' - checksum: 0 - read_delay: 10042282047 - responses: - - header: - length: 314 - requestId: 15 - responseTo: 1299455543 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190469027"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 1815417 - created: 1692190469 diff --git a/docker-mongo/keploy/test-set-1/mocks.yaml b/docker-mongo/keploy/test-set-1/mocks.yaml deleted file mode 100644 index 3051236..0000000 --- a/docker-mongo/keploy/test-set-1/mocks.yaml +++ /dev/null @@ -1,64 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Mongo -name: mocks -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }, { SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }], checksum: 0 }' - requests: - - header: - length: 197 - requestId: 1340074696 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' - - '{ SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }' - checksum: 0 - read_delay: 566167 - responses: - - header: - length: 45 - requestId: 6 - responseTo: 1340074696 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 27458 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: mocks -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 140 - requestId: 1596327406 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 9681533921 - responses: - - header: - length: 273 - requestId: 9 - responseTo: 1596327406 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 40167 - created: 1692190458 diff --git a/docker-mongo/keploy/test-set-1/test-1.yaml b/docker-mongo/keploy/test-set-1/test-1.yaml deleted file mode 100644 index 4141f28..0000000 --- a/docker-mongo/keploy/test-set-1/test-1.yaml +++ /dev/null @@ -1,38 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Http -name: test-1 -spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: '*/*' - Content-Length: "51" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: '{"student_id": "123", "name": "Sarthak", "age": 20}' - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:08 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - objects: [] - assertions: - noise: - - header.Date - created: 1692190448 diff --git a/docker-mongo/keploy/test-set-1/test-2.yaml b/docker-mongo/keploy/test-set-1/test-2.yaml deleted file mode 100644 index 77cb4a3..0000000 --- a/docker-mongo/keploy/test-set-1/test-2.yaml +++ /dev/null @@ -1,34 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Http -name: test-2 -spec: - metadata: {} - req: - method: GET - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: '*/*' - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: "" - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "224" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:18 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - objects: [] - assertions: - noise: - - header.Date - - body.name - created: 1692190458 diff --git a/docker-mongo/keploy/testReports/report-1.yaml b/docker-mongo/keploy/testReports/report-1.yaml deleted file mode 100644 index 14623ce..0000000 --- a/docker-mongo/keploy/testReports/report-1.yaml +++ /dev/null @@ -1,181 +0,0 @@ -version: api.keploy.io/v1beta1 -name: report-1 -status: PASSED -success: 2 -failure: 0 -total: 2 -tests: - - kind: Http - name: report-1 - status: PASSED - started: 1692258836 - completed: 1692258836 - test_case_path: /files/keploy - mock_path: "" - test_case_id: test-1 - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://172.19.0.4:6000/students - header: - Accept: '*/*' - Content-Length: "51" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: '{"student_id": "123", "name": "Sarthak", "age": 20}' - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:08 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - noise: - - header.Date - result: - status_code: - normal: true - expected: 200 - actual: 200 - headers_result: - - normal: true - expected: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - actual: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - - normal: true - expected: - key: Content-Length - value: - - "48" - actual: - key: Content-Length - value: - - "48" - - normal: true - expected: - key: Content-Type - value: - - application/json - actual: - key: Content-Type - value: - - application/json - - normal: true - expected: - key: Date - value: - - Wed, 16 Aug 2023 12:54:08 GMT - actual: - key: Date - value: - - Thu, 17 Aug 2023 07:53:56 GMT - body_result: - - normal: true - type: JSON - expected: | - { - "message": "Student created successfully" - } - actual: | - { - "message": "Student created successfully" - } - dep_result: [] - - kind: Http - name: report-1 - status: PASSED - started: 1692258836 - completed: 1692258836 - test_case_path: /files/keploy - mock_path: "" - test_case_id: test-2 - req: - method: GET - proto_major: 1 - proto_minor: 1 - url: http://172.19.0.4:6000/students - header: - Accept: '*/*' - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: "" - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "224" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:18 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - noise: - - header.Date - - body.name - result: - status_code: - normal: true - expected: 200 - actual: 200 - headers_result: - - normal: true - expected: - key: Date - value: - - Wed, 16 Aug 2023 12:54:18 GMT - actual: - key: Date - value: - - Thu, 17 Aug 2023 07:53:56 GMT - - normal: true - expected: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - actual: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - - normal: true - expected: - key: Content-Length - value: - - "224" - actual: - key: Content-Length - value: - - "224" - - normal: true - expected: - key: Content-Type - value: - - application/json - actual: - key: Content-Type - value: - - application/json - body_result: - - normal: true - type: JSON - expected: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - actual: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - dep_result: [] diff --git a/docker-mongo/requirements.txt b/docker-mongo/requirements.txt deleted file mode 100644 index 7a03746..0000000 --- a/docker-mongo/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -Flask -pymongo==4.4.1 -Flask-Cors==3.0.10 -Werkzeug==2.2.2 \ No newline at end of file diff --git a/rest-mongo/.coverage b/flask-mongo/.coverage similarity index 100% rename from rest-mongo/.coverage rename to flask-mongo/.coverage diff --git a/rest-mongo/.coveragerc b/flask-mongo/.coveragerc similarity index 100% rename from rest-mongo/.coveragerc rename to flask-mongo/.coveragerc diff --git a/flask-mongo/Dockerfile b/flask-mongo/Dockerfile index cbefd2c..961d93b 100644 --- a/flask-mongo/Dockerfile +++ b/flask-mongo/Dockerfile @@ -1,5 +1,5 @@ # Use the official Python image as the base image -FROM python:3.9 +FROM python:3.10.12 # Set the working directory within the container WORKDIR /app @@ -11,7 +11,7 @@ COPY . . RUN pip3 install -r requirements.txt # Expose the port that the Flask app will run on -EXPOSE 6000 +EXPOSE 5000 # Start the Flask application CMD ["python3", "app.py"] diff --git a/flask-mongo/README.md b/flask-mongo/README.md index 54bc693..2d79824 100644 --- a/flask-mongo/README.md +++ b/flask-mongo/README.md @@ -1,600 +1,102 @@ -This application is a simple student management API built using Python's Flask framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on student records. The API supports CORS (Cross-Origin Resource Sharing) to facilitate cross-domain requests. +# Sample Flask+Mongo app to demo Keploy -## Table of Contents +## Clone the sample flask-mongo application -# Introduction +```bash +git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo-local +``` -๐Ÿช„ Dive into the world of Student CRUD Apps and see how seamlessly Keploy integrated with [Flask](https://flask.palletsprojects.com/en/3.0.x/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! ๐ŸŽข +## Install all dependencies -## Pre-Requisite ๐Ÿ› ๏ธ +```bash +pip install -r requirements.txt +``` -- Install WSL (`wsl --install`) for Windows Windows. +## Start the MongoDB server -## Optional ๐Ÿ› ๏ธ +```bash +sudo service mongod start +``` -- Install Colima( `brew install colima && colima start` ) for MacOS MacOs. +## Setup Keploy -## Get Started! ๐ŸŽฌ +Let's get started by setting up the Keploy alias with this command: -## Setup the MongoDB Database ๐Ÿ“ฆ +```bash +curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh +``` -Create a docker network, run - +You should see something like this: ```bash -docker network create backend + โ–“โ–ˆโ–ˆโ–“โ–„ + โ–“โ–“โ–“โ–“โ–ˆโ–ˆโ–“โ–ˆโ–“โ–„ + โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–“โ–’ + โ–€โ–“โ–“โ–ˆโ–ˆโ–ˆโ–„ โ–„โ–„ โ–„ โ–Œ + โ–„โ–Œโ–Œโ–“โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–„ โ–ˆโ–ˆ โ–“โ–ˆโ–€ โ–„โ–Œโ–€โ–„ โ–“โ–“โ–Œโ–„ โ–“โ–ˆ โ–„โ–Œโ–“โ–“โ–Œโ–„ โ–Œโ–Œ โ–“ + โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œโ–“โ–“ โ–ˆโ–ˆโ–“โ–ˆโ–„ โ–“โ–ˆโ–„โ–“โ–“ โ–โ–ˆโ–Œ โ–ˆโ–ˆ โ–“โ–ˆ โ–ˆโ–Œ โ–ˆโ–ˆ โ–ˆโ–Œ โ–ˆโ–“ + โ–“โ–“โ–“โ–“โ–€โ–€โ–€โ–€โ–“โ–“โ–“โ–“โ–“โ–“โ–Œ โ–ˆโ–ˆ โ–ˆโ–“ โ–“โ–Œโ–„โ–„ โ–โ–ˆโ–“โ–„โ–“โ–ˆโ–€ โ–ˆโ–“โ–ˆ โ–€โ–ˆโ–„โ–„โ–ˆโ–€ โ–ˆโ–“โ–ˆ + โ–“โ–Œ โ–โ–ˆโ–Œ โ–ˆโ–Œ + โ–“ + +Keploy CLI + +Available Commands: + example Example to record and test via keploy + generate-config generate the keploy configuration file + record record the keploy testcases from the API calls + test run the recorded testcases and execute assertions + update Update Keploy + +Flags: + --debug Run in debug mode + -h, --help help for keploy + -v, --version version for keploy + +Use "keploy [command] --help" for more information about a command. ``` -Start the MongoDB instance- +## Lights, Camera, Record! ๐ŸŽฅ + +To initiate the recording of API calls, execute this command in your terminal: ```bash -docker run -p 27017:27017 -d --network backend --name mongo mongo +keploy record -c "python3 app.py" ``` -## Clone a simple Student Management API ๐Ÿงช +Now, your app will start running, and you have to make some API calls!! + +And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`. + +## Check Test Coverage + +We have a `test-app.py` where all the unit test cases has been written. Now using Keploy, we can check it's code coverage!! +Now to run your unit tests with Keploy, you can run the command given below: ```bash -git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo +python3 -m coverage run -p --data-file=.coverage.unit -m pytest -s test_keploy.py test_app.py ``` -## Installation ๐Ÿ“ฅ - -Depending on your OS, choose your adventure: +To combine the coverage from the unit tests, and Keploy's API tests we can use the command below: --
- Linux Linux or Windows Windows +```bash +python3 -m coverage combine +``` - Alright, let's equip ourselves with the **latest Keploy binary**: +Finally, to generate the coverage report for the test run, you can run: - ```bash - curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp +```bash +python3 -m coverage report +``` - sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy - ``` +and if you want the coverage in an html file, you can run: - If everything goes right, your screen should look a bit like this: +```bash +python3 -m coverage html +``` - Moving on... -
- Run App with Docker Container Docker +## Wrapping it up ๐ŸŽ‰ - #### Add alias for Keploy: +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.๐Ÿ˜Š๐Ÿš€ - ```bash - alias 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' - ``` - - ### Lights, Camera, Record! ๐ŸŽฅ - - Build the app image: - - ```bash - docker build -t flask-app:1.0 . - ``` - - Capture the test-cases- - - ```shell - keploy record -c "docker run -p 6000:6000 --name flask-app --network backend flask-app:1.0" - ``` - - ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! - - Let's make URLs short and sweet: - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - -
-
- -
- Run App on ๐Ÿง Linux - - We'll be running our sample application right on Linux, but just to make things a tad more thrilling, we'll have the database (PostgreSQL) chill on Docker. Ready? Let's get the party started!๐ŸŽ‰ - - ### ๐Ÿ“ผ Roll the Tape - Recording Time! - - Install the dependencies: - - ```bash - pip install -r requirements.txt - ``` - - Now, let's Capture the test-cases- - - In `app.py`, replace the MongoDB connection URL with - `mongodb://0.0.0.0:27017/` - - Ready, set, record! Here's how: - - ```bash - keploy record -c "python3 app.py" - ``` - - Keep an eye out for the `-c `flag! It's the command charm to run the app. - - Alright, magician! With the app alive and kicking, let's weave some test cases. The spell? Making some API calls! Postman, Hoppscotch, or the classic curl - pick your wand. - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "python3 app.py" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ -
- -
- -
- --
- MacOS MacOs - - Dive straight in, but first in case you're using **Keploy** with **Colima**, give it a gentle nudge with (`colima start`). Let's make sure it's awake and ready for action! - - ### Add alias for Keploy ๐Ÿฐ: - - For the sake of convenience (and a bit of Mac magic ๐Ÿช„), let's set up a shortcut for Keploy: - - ### Use Keploy with Docker-Desktop - - Note: To run Keploy on MacOS through [Docker](https://docs.docker.com/desktop/release-notes/#4252) the version must be `4.25.2` or above. - - #### Creating Docker Volume - - ```bash - docker volume create --driver local --opt type=debugfs --opt device=debugfs debugfs - ``` - - ```bash - alias 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 debugfs:/sys/kernel/debug:rw -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' - ``` - - ### Use Keploy with Colima - - ```bash - alias 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' - ``` - - ### Lights, Camera, Record! ๐ŸŽฅ - - Build the app image: - - ```bash - docker build -t flask-app:1.0 . - ``` - - Capture the test-cases- - - ```shell - keploy record -c "docker run -p 6000:6000 --name DjangoApp --network backend --name flask-app flask-app:1.0" - ``` - - ๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! - - Let's make URLs short and sweet: - - ### Generate testcases - - To generate testcases we just need to **make some API calls.** - - **1. Make a POST request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **2. Make a GET request** - - ```bash - curl http://localhost:6000/students - ``` - - **3. Make a PUT request** - - ```bash - curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345 - ``` - - **4. Make a GET request** - - ```bash - curl http://localhost:6000/students/12345 - ``` - - **5. Make a DELETE request** - - ```bash - curl -X DELETE http://localhost:6000/students/12345 - ``` - - Give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **Keploy directory** and you'll discover your handiwork in `test-1.yml` and `mocks.yml`. - - ```yaml - version: api.keploy.io/v1beta2 - kind: Http - name: test-1 - spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: "*/*" - Content-Length: "56" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.81.0 - body: '{"student_id": "12344", "name": "John Doeww", "age": 10}' - body_type: "" - timestamp: 2023-11-13T13:02:32.241333562Z - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Mon, 13 Nov 2023 13:02:32 GMT - Server: Werkzeug/2.2.2 Python/3.9.18 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - timestamp: 2023-11-13T13:02:34.752123715Z - objects: [] - assertions: - noise: - - header.Date - created: 1699880554 - curl: |- - curl --request POST \ - --url http://localhost:6000/students \ - --header 'Host: localhost:6000' \ - --header 'User-Agent: curl/7.81.0' \ - --header 'Accept: */*' \ - --header 'Content-Type: application/json' \ - --data '{"student_id": "12344", "name": "John Doeww", "age": 10}' - ``` - - This is how `mocks.yml` generated would look like:- - - ```yaml - version: api.keploy.io/v1beta2 - kind: Mongo - name: mocks - spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 187 - requestId: 2127584089 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{"student_id":"12345"},"projection":{"_id":{"$numberInt":"0"}},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"vPKsEFRdTLytlbnyVimqIA==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 3469848802 - responses: - - header: - length: 166 - requestId: 154 - responseTo: 2127584089 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"12345","name":"John Doe","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 869555 - created: 1699880576 - reqTimestampMock: 2023-11-13T13:02:56.385067848Z - resTimestampMock: 2023-11-13T13:02:56.386374941Z - ``` - - Want to see if everything works as expected? - - #### Run Tests - - Time to put things to the test ๐Ÿงช - - ```shell - keploy test -c "sudo docker run -p 6000:6000 --rm --network backend --name flask-app flask-app:1.0" --delay 10 - ``` - - > The `--delay` flag? Oh, that's just giving your app a little breather (in seconds) before the test cases come knocking. - - Final thoughts? Dive deeper! Try different API calls, tweak the DB response in the `mocks.yml`, or fiddle with the request or response in `test-x.yml`. Run the tests again and see the magic unfold!โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ - - ## Wrapping it up ๐ŸŽ‰ - - 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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ -
+Happy coding! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ diff --git a/rest-mongo/__pycache__/app.cpython-310.pyc b/flask-mongo/__pycache__/app.cpython-310.pyc similarity index 100% rename from rest-mongo/__pycache__/app.cpython-310.pyc rename to flask-mongo/__pycache__/app.cpython-310.pyc diff --git a/rest-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc b/flask-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc similarity index 100% rename from rest-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc rename to flask-mongo/__pycache__/test_app.cpython-310-pytest-8.1.1.pyc diff --git a/rest-mongo/__pycache__/test_app.cpython-310.pyc b/flask-mongo/__pycache__/test_app.cpython-310.pyc similarity index 100% rename from rest-mongo/__pycache__/test_app.cpython-310.pyc rename to flask-mongo/__pycache__/test_app.cpython-310.pyc diff --git a/rest-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc b/flask-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc similarity index 100% rename from rest-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc rename to flask-mongo/__pycache__/test_keploy.cpython-310-pytest-8.1.1.pyc diff --git a/flask-mongo/app.py b/flask-mongo/app.py index 6e31416..730db9f 100644 --- a/flask-mongo/app.py +++ b/flask-mongo/app.py @@ -1,42 +1,56 @@ from flask import Flask, request, jsonify from pymongo import MongoClient from flask_cors import CORS -import collections.abc +from bson import ObjectId app = Flask(__name__) cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) -# Connect to MongoDB -client = MongoClient('mongodb://mongo:27017/') -db = client['studentsdb'] -students_collection = db['students'] - -@app.route('/students', methods=['GET']) -def get_students(): - students = list(students_collection.find({}, {'_id': 0})) - return jsonify(students) - -@app.route('/students/', methods=['GET']) -def get_student(student_id): - student = students_collection.find_one({'student_id': student_id}, {'_id': 0}) - return jsonify(student) - -@app.route('/students', methods=['POST']) -def create_student(): - new_student = request.json - students_collection.insert_one(new_student) - return jsonify({'message': 'Student created successfully'}) - -@app.route('/students/', methods=['PUT']) -def update_student(student_id): - updated_student = request.json - students_collection.update_one({'student_id': student_id}, {'$set': updated_student}) - return jsonify({'message': 'Student updated successfully'}) - -@app.route('/students/', methods=['DELETE']) -def delete_student(student_id): - students_collection.delete_one({'student_id': student_id}) - return jsonify({'message': 'Student deleted successfully'}) +client = MongoClient('mongodb://localhost:27017/task_manager') +db = client['task_manager'] +collection = db['tasks'] + +@app.route('/api/tasks', methods=['POST']) +def create_task(): + data = request.get_json() + task = { + 'title': data['title'], + 'description': data['description'] + } + result = collection.insert_one(task) + return jsonify({'message': 'Task created successfully', 'id': str(result.inserted_id)}), 201 + +@app.route('/api/tasks', methods=['GET']) +def get_all_tasks(): + tasks = [] + for task in collection.find(): + tasks.append({ + 'id': str(task['_id']), + 'title': task['title'], + 'description': task['description'] + }) + return jsonify({'tasks': tasks}) + +@app.route('/api/tasks/', methods=['PUT']) +def update_task(task_id): + data = request.get_json() + updated_task = { + 'title': data['title'], + 'description': data['description'] + } + try: + result = collection.update_one({'_id': ObjectId(task_id)}, {'$set': updated_task}) + if result.modified_count == 0: + return jsonify({'error': 'Task not found or no changes were made'}), 404 + else: + return jsonify({'message': 'Task updated successfully'}) + except Exception as e: + return jsonify({'error': str(e)}), 500 + +@app.route('/api/tasks/', methods=['DELETE']) +def delete_task(task_id): + collection.delete_one({'_id': ObjectId(task_id)}) + return jsonify({'message': 'Task deleted successfully'}) if __name__ == '__main__': - app.run(host='0.0.0.0', port=6000, debug=True) + app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/flask-mongo/docker-compose.yml b/flask-mongo/docker-compose.yml index 7ef7346..1d71e32 100644 --- a/flask-mongo/docker-compose.yml +++ b/flask-mongo/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3' +version: "3" services: mongo: image: mongo @@ -16,7 +16,7 @@ services: build: context: . ports: - - "6000:6000" + - "5000:5000" depends_on: - mongo networks: diff --git a/rest-mongo/keploy/reports/test-run-0/test-set-0-report.yaml b/flask-mongo/keploy/reports/test-run-0/test-set-0-report.yaml similarity index 100% rename from rest-mongo/keploy/reports/test-run-0/test-set-0-report.yaml rename to flask-mongo/keploy/reports/test-run-0/test-set-0-report.yaml diff --git a/rest-mongo/keploy/reports/test-run-1/test-set-0-report.yaml b/flask-mongo/keploy/reports/test-run-1/test-set-0-report.yaml similarity index 100% rename from rest-mongo/keploy/reports/test-run-1/test-set-0-report.yaml rename to flask-mongo/keploy/reports/test-run-1/test-set-0-report.yaml diff --git a/rest-mongo/keploy/test-set-0/mocks.yaml b/flask-mongo/keploy/test-set-0/mocks.yaml similarity index 100% rename from rest-mongo/keploy/test-set-0/mocks.yaml rename to flask-mongo/keploy/test-set-0/mocks.yaml diff --git a/rest-mongo/keploy/test-set-0/tests/test-1.yaml b/flask-mongo/keploy/test-set-0/tests/test-1.yaml similarity index 100% rename from rest-mongo/keploy/test-set-0/tests/test-1.yaml rename to flask-mongo/keploy/test-set-0/tests/test-1.yaml diff --git a/rest-mongo/keploy/test-set-0/tests/test-2.yaml b/flask-mongo/keploy/test-set-0/tests/test-2.yaml similarity index 100% rename from rest-mongo/keploy/test-set-0/tests/test-2.yaml rename to flask-mongo/keploy/test-set-0/tests/test-2.yaml diff --git a/rest-mongo/keploy/test-set-0/tests/test-3.yaml b/flask-mongo/keploy/test-set-0/tests/test-3.yaml similarity index 100% rename from rest-mongo/keploy/test-set-0/tests/test-3.yaml rename to flask-mongo/keploy/test-set-0/tests/test-3.yaml diff --git a/rest-mongo/keploy/test-set-0/tests/test-4.yaml b/flask-mongo/keploy/test-set-0/tests/test-4.yaml similarity index 100% rename from rest-mongo/keploy/test-set-0/tests/test-4.yaml rename to flask-mongo/keploy/test-set-0/tests/test-4.yaml diff --git a/flask-mongo/keploy/test-set-1/config.yaml b/flask-mongo/keploy/test-set-1/config.yaml deleted file mode 100755 index e451518..0000000 --- a/flask-mongo/keploy/test-set-1/config.yaml +++ /dev/null @@ -1,167 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"}}, returnFieldsSelector: }' - requests: - - header: - length: 262 - requestId: 1890541915 - responseTo: 0 - Opcode: 2004 - message: - flags: 0 - collection_name: admin.$cmd - number_to_skip: 0 - number_to_return: -1 - query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"}}' - return_fields_selector: "" - read_delay: 82208 - responses: - - header: - length: 329 - requestId: 3 - responseTo: 1890541915 - Opcode: 1 - message: - response_flags: 8 - cursor_id: 0 - starting_from: 0 - number_returned: 1 - documents: - - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448932"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' - read_delay: 659750 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.29-0-virt"},"platform": "CPython 3.9.17.final.0"},"compression": []}, returnFieldsSelector: }' - requests: - - header: - length: 280 - requestId: 1076681270 - responseTo: 0 - Opcode: 2004 - message: - flags: 0 - collection_name: admin.$cmd - number_to_skip: 0 - number_to_return: -1 - query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.29-0-virt"},"platform":"CPython 3.9.17.final.0"},"compression":[]}' - return_fields_selector: "" - read_delay: 51917 - responses: - - header: - length: 329 - requestId: 4 - responseTo: 1076681270 - Opcode: 1 - message: - response_flags: 8 - cursor_id: 0 - starting_from: 0 - number_returned: 1 - documents: - - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190448936"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"2"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' - read_delay: 999250 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 65536, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 134 - requestId: 613273587 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 65536 - sections: - - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }' - checksum: 0 - read_delay: 3336333 - responses: - - header: - length: 313 - requestId: 10 - responseTo: 613273587 - Opcode: 2013 - message: - flagBits: 2 - sections: - - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458940"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 10005077213 - created: 1692190458 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 52 - requestId: 1075693109 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }' - checksum: 0 - read_delay: 10043184088 - responses: - - header: - length: 313 - requestId: 11 - responseTo: 1075693109 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190458982"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 746417 - created: 1692190458 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: config -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }], checksum: 0 }' - requests: - - header: - length: 65 - requestId: 1299455543 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }' - checksum: 0 - read_delay: 10042282047 - responses: - - header: - length: 314 - requestId: 15 - responseTo: 1299455543 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"64dcc6eb86233da4f389a58b"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1692190469027"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"3"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"17"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 1815417 - created: 1692190469 diff --git a/flask-mongo/keploy/test-set-1/mocks.yaml b/flask-mongo/keploy/test-set-1/mocks.yaml deleted file mode 100755 index 3051236..0000000 --- a/flask-mongo/keploy/test-set-1/mocks.yaml +++ /dev/null @@ -1,64 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Mongo -name: mocks -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }, { SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }], checksum: 0 }' - requests: - - header: - length: 197 - requestId: 1340074696 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"insert":"students","ordered":true,"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' - - '{ SectionSingle identifier: documents , msgs: [ {"_id":{"$oid":"64dcc6f03b29d5de7bb2ae07"},"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}} ] }' - checksum: 0 - read_delay: 566167 - responses: - - header: - length: 45 - requestId: 6 - responseTo: 1340074696 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 27458 - created: 1692190448 ---- -version: api.keploy.io/v1beta2 -kind: Mongo -name: mocks -spec: - metadata: - operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }], checksum: 0 }' - requests: - - header: - length: 140 - requestId: 1596327406 - responseTo: 0 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"find":"students","filter":{},"projection":{"_id":{"$numberInt":"0"}},"lsid":{"id":{"$binary":{"base64":"HHvg4XLYQFWra6WjBn1j/A==","subType":"04"}}},"$db":"studentsdb"} }' - checksum: 0 - read_delay: 9681533921 - responses: - - header: - length: 273 - requestId: 9 - responseTo: 1596327406 - Opcode: 2013 - message: - flagBits: 0 - sections: - - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}},{"student_id":"123","name":"Sarthak","age":{"$numberInt":"20"}}],"id":{"$numberLong":"0"},"ns":"studentsdb.students"},"ok":{"$numberDouble":"1.0"}} }' - checksum: 0 - read_delay: 40167 - created: 1692190458 diff --git a/flask-mongo/keploy/test-set-1/test-1.yaml b/flask-mongo/keploy/test-set-1/test-1.yaml deleted file mode 100755 index 4141f28..0000000 --- a/flask-mongo/keploy/test-set-1/test-1.yaml +++ /dev/null @@ -1,38 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Http -name: test-1 -spec: - metadata: {} - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: '*/*' - Content-Length: "51" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: '{"student_id": "123", "name": "Sarthak", "age": 20}' - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:08 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - objects: [] - assertions: - noise: - - header.Date - created: 1692190448 diff --git a/flask-mongo/keploy/test-set-1/test-2.yaml b/flask-mongo/keploy/test-set-1/test-2.yaml deleted file mode 100755 index 77cb4a3..0000000 --- a/flask-mongo/keploy/test-set-1/test-2.yaml +++ /dev/null @@ -1,34 +0,0 @@ -version: api.keploy.io/v1beta2 -kind: Http -name: test-2 -spec: - metadata: {} - req: - method: GET - proto_major: 1 - proto_minor: 1 - url: http://localhost:6000/students - header: - Accept: '*/*' - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: "" - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "224" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:18 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - objects: [] - assertions: - noise: - - header.Date - - body.name - created: 1692190458 diff --git a/flask-mongo/keploy/testReports/report-1.yaml b/flask-mongo/keploy/testReports/report-1.yaml deleted file mode 100755 index 14623ce..0000000 --- a/flask-mongo/keploy/testReports/report-1.yaml +++ /dev/null @@ -1,181 +0,0 @@ -version: api.keploy.io/v1beta1 -name: report-1 -status: PASSED -success: 2 -failure: 0 -total: 2 -tests: - - kind: Http - name: report-1 - status: PASSED - started: 1692258836 - completed: 1692258836 - test_case_path: /files/keploy - mock_path: "" - test_case_id: test-1 - req: - method: POST - proto_major: 1 - proto_minor: 1 - url: http://172.19.0.4:6000/students - header: - Accept: '*/*' - Content-Length: "51" - Content-Type: application/json - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: '{"student_id": "123", "name": "Sarthak", "age": 20}' - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "48" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:08 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: | - { - "message": "Student created successfully" - } - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - noise: - - header.Date - result: - status_code: - normal: true - expected: 200 - actual: 200 - headers_result: - - normal: true - expected: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - actual: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - - normal: true - expected: - key: Content-Length - value: - - "48" - actual: - key: Content-Length - value: - - "48" - - normal: true - expected: - key: Content-Type - value: - - application/json - actual: - key: Content-Type - value: - - application/json - - normal: true - expected: - key: Date - value: - - Wed, 16 Aug 2023 12:54:08 GMT - actual: - key: Date - value: - - Thu, 17 Aug 2023 07:53:56 GMT - body_result: - - normal: true - type: JSON - expected: | - { - "message": "Student created successfully" - } - actual: | - { - "message": "Student created successfully" - } - dep_result: [] - - kind: Http - name: report-1 - status: PASSED - started: 1692258836 - completed: 1692258836 - test_case_path: /files/keploy - mock_path: "" - test_case_id: test-2 - req: - method: GET - proto_major: 1 - proto_minor: 1 - url: http://172.19.0.4:6000/students - header: - Accept: '*/*' - Host: localhost:6000 - User-Agent: curl/7.77.0 - body: "" - body_type: "" - resp: - status_code: 200 - header: - Content-Length: "224" - Content-Type: application/json - Date: Wed, 16 Aug 2023 12:54:18 GMT - Server: Werkzeug/2.3.7 Python/3.9.17 - body: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - body_type: "" - status_message: "" - proto_major: 0 - proto_minor: 0 - noise: - - header.Date - - body.name - result: - status_code: - normal: true - expected: 200 - actual: 200 - headers_result: - - normal: true - expected: - key: Date - value: - - Wed, 16 Aug 2023 12:54:18 GMT - actual: - key: Date - value: - - Thu, 17 Aug 2023 07:53:56 GMT - - normal: true - expected: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - actual: - key: Server - value: - - Werkzeug/2.3.7 Python/3.9.17 - - normal: true - expected: - key: Content-Length - value: - - "224" - actual: - key: Content-Length - value: - - "224" - - normal: true - expected: - key: Content-Type - value: - - application/json - actual: - key: Content-Type - value: - - application/json - body_result: - - normal: true - type: JSON - expected: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - actual: "[\n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }, \n {\n \"age\": 20, \n \"name\": \"Sarthak\", \n \"student_id\": \"123\"\n }\n]\n" - dep_result: [] diff --git a/rest-mongo/postman_tests/delete.js b/flask-mongo/postman_tests/delete.js similarity index 100% rename from rest-mongo/postman_tests/delete.js rename to flask-mongo/postman_tests/delete.js diff --git a/rest-mongo/postman_tests/get.js b/flask-mongo/postman_tests/get.js similarity index 100% rename from rest-mongo/postman_tests/get.js rename to flask-mongo/postman_tests/get.js diff --git a/rest-mongo/postman_tests/post.js b/flask-mongo/postman_tests/post.js similarity index 100% rename from rest-mongo/postman_tests/post.js rename to flask-mongo/postman_tests/post.js diff --git a/rest-mongo/postman_tests/put.js b/flask-mongo/postman_tests/put.js similarity index 100% rename from rest-mongo/postman_tests/put.js rename to flask-mongo/postman_tests/put.js diff --git a/flask-mongo/requirements.txt b/flask-mongo/requirements.txt index 7a03746..324ca18 100644 --- a/flask-mongo/requirements.txt +++ b/flask-mongo/requirements.txt @@ -1,4 +1,6 @@ -Flask -pymongo==4.4.1 -Flask-Cors==3.0.10 -Werkzeug==2.2.2 \ No newline at end of file +Flask==3.0.3 +Flask-Cors==4.0.0 +pymongo==4.6.3 +coverage==7.4.4 +bson==0.5.10 +keploy==2.0.0a33 \ No newline at end of file diff --git a/rest-mongo/test_app.py b/flask-mongo/test_app.py similarity index 100% rename from rest-mongo/test_app.py rename to flask-mongo/test_app.py diff --git a/rest-mongo/test_keploy.py b/flask-mongo/test_keploy.py similarity index 100% rename from rest-mongo/test_keploy.py rename to flask-mongo/test_keploy.py diff --git a/rest-mongo/README.md b/rest-mongo/README.md deleted file mode 100644 index 2d79824..0000000 --- a/rest-mongo/README.md +++ /dev/null @@ -1,102 +0,0 @@ -# Sample Flask+Mongo app to demo Keploy - -## Clone the sample flask-mongo application - -```bash -git clone https://github.com/keploy/samples-python.git && cd samples-python/flask-mongo-local -``` - -## Install all dependencies - -```bash -pip install -r requirements.txt -``` - -## Start the MongoDB server - -```bash -sudo service mongod start -``` - -## Setup Keploy - -Let's get started by setting up the Keploy alias with this command: - -```bash -curl -O https://raw.githubusercontent.com/keploy/keploy/main/keploy.sh && source keploy.sh -``` - -You should see something like this: - -```bash - โ–“โ–ˆโ–ˆโ–“โ–„ - โ–“โ–“โ–“โ–“โ–ˆโ–ˆโ–“โ–ˆโ–“โ–„ - โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–“โ–’ - โ–€โ–“โ–“โ–ˆโ–ˆโ–ˆโ–„ โ–„โ–„ โ–„ โ–Œ - โ–„โ–Œโ–Œโ–“โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–„ โ–ˆโ–ˆ โ–“โ–ˆโ–€ โ–„โ–Œโ–€โ–„ โ–“โ–“โ–Œโ–„ โ–“โ–ˆ โ–„โ–Œโ–“โ–“โ–Œโ–„ โ–Œโ–Œ โ–“ - โ–“โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–Œโ–“โ–“ โ–ˆโ–ˆโ–“โ–ˆโ–„ โ–“โ–ˆโ–„โ–“โ–“ โ–โ–ˆโ–Œ โ–ˆโ–ˆ โ–“โ–ˆ โ–ˆโ–Œ โ–ˆโ–ˆ โ–ˆโ–Œ โ–ˆโ–“ - โ–“โ–“โ–“โ–“โ–€โ–€โ–€โ–€โ–“โ–“โ–“โ–“โ–“โ–“โ–Œ โ–ˆโ–ˆ โ–ˆโ–“ โ–“โ–Œโ–„โ–„ โ–โ–ˆโ–“โ–„โ–“โ–ˆโ–€ โ–ˆโ–“โ–ˆ โ–€โ–ˆโ–„โ–„โ–ˆโ–€ โ–ˆโ–“โ–ˆ - โ–“โ–Œ โ–โ–ˆโ–Œ โ–ˆโ–Œ - โ–“ - -Keploy CLI - -Available Commands: - example Example to record and test via keploy - generate-config generate the keploy configuration file - record record the keploy testcases from the API calls - test run the recorded testcases and execute assertions - update Update Keploy - -Flags: - --debug Run in debug mode - -h, --help help for keploy - -v, --version version for keploy - -Use "keploy [command] --help" for more information about a command. -``` - -## Lights, Camera, Record! ๐ŸŽฅ - -To initiate the recording of API calls, execute this command in your terminal: - -```bash -keploy record -c "python3 app.py" -``` - -Now, your app will start running, and you have to make some API calls!! - -And once you are done, you can stop the recording and give yourself a pat on the back! With that simple spell, you've conjured up a test case with a mock! Explore the **keploy** directory and you'll discover your handiwork in `tests` directory and `mocks.yml`. - -## Check Test Coverage - -We have a `test-app.py` where all the unit test cases has been written. Now using Keploy, we can check it's code coverage!! -Now to run your unit tests with Keploy, you can run the command given below: - -```bash -python3 -m coverage run -p --data-file=.coverage.unit -m pytest -s test_keploy.py test_app.py -``` - -To combine the coverage from the unit tests, and Keploy's API tests we can use the command below: - -```bash -python3 -m coverage combine -``` - -Finally, to generate the coverage report for the test run, you can run: - -```bash -python3 -m coverage report -``` - -and if you want the coverage in an html file, you can run: - -```bash -python3 -m coverage html -``` - -## Wrapping it up ๐ŸŽ‰ - -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! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ diff --git a/rest-mongo/app.py b/rest-mongo/app.py deleted file mode 100644 index 730db9f..0000000 --- a/rest-mongo/app.py +++ /dev/null @@ -1,56 +0,0 @@ -from flask import Flask, request, jsonify -from pymongo import MongoClient -from flask_cors import CORS -from bson import ObjectId - -app = Flask(__name__) -cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) - -client = MongoClient('mongodb://localhost:27017/task_manager') -db = client['task_manager'] -collection = db['tasks'] - -@app.route('/api/tasks', methods=['POST']) -def create_task(): - data = request.get_json() - task = { - 'title': data['title'], - 'description': data['description'] - } - result = collection.insert_one(task) - return jsonify({'message': 'Task created successfully', 'id': str(result.inserted_id)}), 201 - -@app.route('/api/tasks', methods=['GET']) -def get_all_tasks(): - tasks = [] - for task in collection.find(): - tasks.append({ - 'id': str(task['_id']), - 'title': task['title'], - 'description': task['description'] - }) - return jsonify({'tasks': tasks}) - -@app.route('/api/tasks/', methods=['PUT']) -def update_task(task_id): - data = request.get_json() - updated_task = { - 'title': data['title'], - 'description': data['description'] - } - try: - result = collection.update_one({'_id': ObjectId(task_id)}, {'$set': updated_task}) - if result.modified_count == 0: - return jsonify({'error': 'Task not found or no changes were made'}), 404 - else: - return jsonify({'message': 'Task updated successfully'}) - except Exception as e: - return jsonify({'error': str(e)}), 500 - -@app.route('/api/tasks/', methods=['DELETE']) -def delete_task(task_id): - collection.delete_one({'_id': ObjectId(task_id)}) - return jsonify({'message': 'Task deleted successfully'}) - -if __name__ == '__main__': - app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/rest-mongo/requirements.txt b/rest-mongo/requirements.txt deleted file mode 100644 index 7230e6a..0000000 --- a/rest-mongo/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -Flask==3.0.3 -Flask-Cors==4.0.0 -pymongo==4.6.3 -coverage==7.4.4 -