|
| 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