Skip to content

Commit a2b3b2d

Browse files
committed
feat: added django-mysql quickstart guide
Signed-off-by: Achanandhi-M <achanandhi.m@gmail.com>
1 parent 0d6730c commit a2b3b2d

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed
Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
---
2+
id: samples-django-mysql
3+
title: Employee Data CRUD App
4+
sidebar_label: Django + mysql
5+
description: The following sample app showcases how to use the Django framework and the Keploy Platform.
6+
tags:
7+
- python
8+
- quickstart
9+
- samples
10+
- examples
11+
- tutorial
12+
- python-framework
13+
- mysql
14+
keyword:
15+
- Django Framework
16+
- mysql
17+
- SQL
18+
- Python
19+
- API Test generator
20+
- Auto case generation
21+
---
22+
23+
## Introduction
24+
25+
This application is a simple Employee Management System built with Django and MySQL. It allows you to create, retrieve, update, and delete employee records via RESTful API endpoints. The application is containerized using Docker, making it easy to deploy and run in different environments. The backend is powered by Django, and the MySQL database is used to store employee information.
26+
27+
28+
import InstallationGuide from '../concepts/installation.md'
29+
30+
<InstallationGuide/>
31+
32+
# Get Started! 🎬
33+
34+
## Clone the app 🧪
35+
36+
```bash
37+
git clone https://github.com/keploy/samples-python.git && cd samples-python/django-mysql
38+
```
39+
40+
Open a different terminal and setup your Mysql through docker
41+
42+
```shell
43+
docker run --name mySQL --network keploy-network -e MYSQL_ROOT_PASSWORD=keploy -e MYSQL_DATABASE=keploy_db -e MYSQL_USER=admin -e MYSQL_PASSWORD=keploy -p 3306:3306 -d mysql
44+
45+
```
46+
Build and Run Django Application Container
47+
48+
```shell
49+
docker build --build-arg HOST_PWD="$(pwd)" -t py-app .
50+
51+
```
52+
53+
## Lights, Camera, Record! 🎥
54+
55+
Capture the test-cases-
56+
57+
```shell
58+
keploy record -c "sudo docker run --name django-app --net keploy-network -p 8000:8000 -v $(pwd):$(pwd) --rm py-app"
59+
```
60+
61+
You should be able to see this in your terminal
62+
63+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy-record-django-mysql.webp" alt="Sample Keploy record django-mysql" width="100%" style={{ borderRadius: '5px' }} />
64+
65+
🔥**Make some API calls**.
66+
67+
Let's make URLs short and sweet:
68+
69+
## Generate testcases
70+
71+
To generate testcases we just need to **make some API calls.**
72+
73+
1. **Make a POST request:**
74+
75+
```bash
76+
77+
curl -X POST http://localhost:8000/api/employee/create/ -H "Content-Type: application/json" -d '{"name": "John Doe", "years_of_experience": 5, "field": "Computer Science", "company": "TechCorp"}'
78+
79+
```
80+
81+
2. **Make a GET request:**
82+
83+
```bash
84+
85+
curl -X GET http://localhost:8000/api/employee/
86+
87+
```
88+
89+
3. **Make a PUT request:**
90+
91+
```bash
92+
93+
curl -X PUT http://localhost:8000/api/employee/update/1/ -H "Content-Type: application/json" -d '{"name": "Jane Doe", "years_of_experience": 6, "field": "Data Science", "company": "TechCorp"}'
94+
95+
```
96+
97+
4. **Make a DELETE request:**
98+
99+
```bash
100+
curl -X "DELETE" "http://127.0.0.1:8000/movies" \
101+
-H 'Accept: application/json' \
102+
-H 'Content-Type: application/json; charset=utf-8'
103+
104+
```
105+
106+
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`.
107+
108+
This is an example of what your mocks would look like
109+
110+
```yaml
111+
112+
# Generated by Keploy (2.6.22)
113+
version: api.keploy.io/v1beta1
114+
kind: MySQL
115+
name: mock-0
116+
spec:
117+
metadata:
118+
connID: "0"
119+
requestOperation: HandshakeV10
120+
responseOperation: OK
121+
type: config
122+
requests:
123+
- header:
124+
header:
125+
payload_length: 205
126+
sequence_id: 1
127+
packet_type: HandshakeResponse41
128+
message:
129+
capability_flags: 12558991
130+
max_packet_size: 1073741824
131+
character_set: 33
132+
filler: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
133+
username: admin
134+
auth_response: [192, 100, 88, 71, 91, 252, 72, 166, 159, 206, 23, 237, 148, 243, 163, 6, 88, 23, 166, 84, 221, 255, 84, 159, 200, 159, 6, 122, 117, 240, 47, 166]
135+
database: keploy_db
136+
auth_plugin_name: caching_sha2_password
137+
connection_attributes:
138+
_client_name: libmariadb
139+
_client_version: 3.3.14
140+
_os: Linux
141+
_pid: "7"
142+
_platform: aarch64
143+
_server_host: mySQL
144+
zstdcompressionlevel: 0
145+
responses:
146+
- header:
147+
header:
148+
payload_length: 73
149+
sequence_id: 0
150+
packet_type: HandshakeV10
151+
message:
152+
protocol_version: 10
153+
server_version: 9.4.0
154+
connection_id: 54
155+
auth_plugin_data: [113, 21, 7, 81, 7, 12, 87, 112, 51, 94, 104, 13, 51, 38, 48, 123, 104, 89, 77, 39, 0]
156+
filler: 0
157+
capability_flags: 3758096383
158+
character_set: 255
159+
status_flags: 2
160+
auth_plugin_name: caching_sha2_password
161+
- header:
162+
header:
163+
payload_length: 2
164+
sequence_id: 2
165+
packet_type: AuthMoreData
166+
message:
167+
status_tag: 1
168+
data: FastAuthSuccess
169+
- header:
170+
header:
171+
payload_length: 21
172+
sequence_id: 3
173+
packet_type: OK
174+
message:
175+
header: 0
176+
affected_rows: 0
177+
last_insert_id: 0
178+
status_flags: 16386
179+
warnings: 0
180+
info: "\0\f\x01\n\tkeploy_db"
181+
created: 1753793504
182+
reqtimestampmock: 2025-07-29T12:51:44.329059627Z
183+
restimestampmock: 2025-07-29T12:51:44.330062582Z
184+
185+
```
186+
187+
188+
## **Time to put things to the test 🧪:**
189+
190+
Note:
191+
If you want to view the coverage, follow the guide below:
192+
193+
There is an alternate entrypoint in the Dockerfile that is currently commented out. To enable it, simply uncomment the entrypoint, rebuild the Docker image, and run the application again with Keploy.
194+
195+
```bash
196+
keploy test -c "sudo docker run --name django-app --net keploy-network -p 8000:8000 -v $(pwd):$(pwd) --rm py-app"
197+
```
198+
199+
200+
This is how your terminal would look like :
201+
202+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy-test-django-mysql.webp" alt="Sample Keploy Test django-mysql" width="100%" style={{ borderRadius: '5px' }} />
203+
204+
Once the tests are executed, a .coverage file will be generated. To view the coverage report, run:
205+
206+
```bash
207+
python3 -m coverage report
208+
```
209+
This is how output would look like :
210+
211+
<img src="https://keploy-devrel.s3.us-west-2.amazonaws.com/keploy-test-coverage-django-mysql.webp" alt="Sample Keploy Test django-mysql" width="100%" style={{ borderRadius: '5px' }} />
212+
213+
214+
You can experiment with different API calls, modify the database response in mocks.yml, or adjust the request or response in test-x.yml. Then, run the tests again to see the change in response

versioned_sidebars/version-3.0.0-sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
"collapsed": true,
127127
"items": [
128128
"quickstart/samples-django",
129+
"quickstart/samples-django-mysql",
129130
"quickstart/samples-flask",
130131
"quickstart/samples-fastapi",
131132
"quickstart/samples-fastapi-twilio",

0 commit comments

Comments
 (0)