Skip to content

Commit c262010

Browse files
authored
added sanic+mongo sample app (#23)
Signed-off-by: Swapnoneel Saha <[email protected]>
1 parent c58758f commit c262010

File tree

9 files changed

+879
-0
lines changed

9 files changed

+879
-0
lines changed

β€Žsanic-mongo/README.mdβ€Ž

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
This application is a simple movie management API built using Python's Sanic framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records.
2+
3+
## Table of Contents
4+
5+
# Introduction
6+
7+
πŸͺ„ Dive into the world of Movie CRUD Apps and see how seamlessly Keploy integrated with [Sanic](hhttps://sanic.dev/en/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! 🎒
8+
9+
## Pre-Requisite πŸ› οΈ
10+
11+
- Install WSL (`wsl --install`) for <img src="https://keploy.io/docs/img/os/windows.png" alt="Windows" width="3%" /> Windows.
12+
13+
## Optional πŸ› οΈ
14+
15+
- Install Colima( `brew install colima && colima start` ) for <img src="https://keploy.io/docs/img/os/macos.png" alt="MacOS" width="3%" /> MacOs.
16+
17+
## Installation πŸ“₯
18+
19+
Depending on your OS, choose your adventure:
20+
21+
Alright, let's equip ourselves with the **latest Keploy binary**:
22+
23+
```bash
24+
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp
25+
26+
sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
27+
```
28+
29+
#### Add alias for Keploy:
30+
31+
```bash
32+
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'
33+
```
34+
35+
Now head to the folder of the application and run
36+
37+
```
38+
pip3 install -r requirements.txt
39+
```
40+
41+
### Lights, Camera, Record! πŸŽ₯
42+
43+
Capture the test-cases-
44+
45+
```shell
46+
keploy record -c "python3 server.py"
47+
```
48+
49+
πŸ”₯**Make some API calls**. Postman, Hoppscotch or even curl - take your pick!
50+
51+
Let's make URLs short and sweet:
52+
53+
### Generate testcases
54+
55+
To generate testcases we just need to **make some API calls.**
56+
57+
**1. Make a POST requests**
58+
59+
```bash
60+
curl -X "POST" "http://127.0.0.1:8000/add_movie" \
61+
-H 'Accept: application/json' \
62+
-H 'Content-Type: application/json; charset=utf-8' \
63+
-d '{
64+
"name": "Whiplash"
65+
}'
66+
```
67+
68+
```bash
69+
curl -X "POST" "http://127.0.0.1:8000/add_movie" \
70+
-H 'Accept: application/json' \
71+
-H 'Content-Type: application/json; charset=utf-8' \
72+
-d '{
73+
"name": "Chappie"
74+
}'
75+
```
76+
77+
```bash
78+
curl -X "POST" "http://127.0.0.1:8000/add_movie" \
79+
-H 'Accept: application/json' \
80+
-H 'Content-Type: application/json; charset=utf-8' \
81+
-d '{
82+
"name": "Titanic"
83+
}'
84+
```
85+
86+
**2. Make a GET request**
87+
88+
In order to see all the movies added to the database, run:
89+
90+
```
91+
curl -X "GET" "http://127.0.0.1:8000/movies" \
92+
-H 'Accept: application/json' \
93+
-H 'Content-Type: application/json; charset=utf-8'
94+
```
95+
96+
**3. Make a DELETE request**
97+
98+
In order to delete all the movies, run:
99+
100+
```bash
101+
curl -X "DELETE" "http://127.0.0.1:8000/movies" \
102+
-H 'Accept: application/json' \
103+
-H 'Content-Type: application/json; charset=utf-8'
104+
```
105+
106+
You will now see a folder named `keploy` with your recorded tests.
107+
108+
#### Run Tests
109+
110+
Time to put things to the test πŸ§ͺ
111+
112+
```shell
113+
keploy test -c "python server.py"
114+
```
115+
116+
## Wrapping it up πŸŽ‰
117+
118+
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.πŸ˜ŠπŸš€
119+
120+
Happy coding! βœ¨πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»βœ¨
121+
122+
<br/>

0 commit comments

Comments
Β (0)