Skip to content

Commit c174ae0

Browse files
Achanandhi-Mactions-user
authored andcommitted
feat: added django-mysql quickstart guide
Signed-off-by: Achanandhi-M <[email protected]>
1 parent 0d6730c commit c174ae0

File tree

2 files changed

+269
-0
lines changed

2 files changed

+269
-0
lines changed
Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
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+
import InstallationGuide from '../concepts/installation.md'
28+
29+
<InstallationGuide/>
30+
31+
# Get Started! 🎬
32+
33+
## Clone the app 🧪
34+
35+
```bash
36+
git clone https://github.com/keploy/samples-python.git && cd samples-python/django-mysql
37+
```
38+
39+
Open a different terminal and setup your Mysql through docker
40+
41+
```shell
42+
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
43+
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+
# Generated by Keploy (2.6.22)
112+
version: api.keploy.io/v1beta1
113+
kind: MySQL
114+
name: mock-0
115+
spec:
116+
metadata:
117+
connID: "0"
118+
requestOperation: HandshakeV10
119+
responseOperation: OK
120+
type: config
121+
requests:
122+
- header:
123+
header:
124+
payload_length: 205
125+
sequence_id: 1
126+
packet_type: HandshakeResponse41
127+
message:
128+
capability_flags: 12558991
129+
max_packet_size: 1073741824
130+
character_set: 33
131+
filler:
132+
[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:
135+
[
136+
192,
137+
100,
138+
88,
139+
71,
140+
91,
141+
252,
142+
72,
143+
166,
144+
159,
145+
206,
146+
23,
147+
237,
148+
148,
149+
243,
150+
163,
151+
6,
152+
88,
153+
23,
154+
166,
155+
84,
156+
221,
157+
255,
158+
84,
159+
159,
160+
200,
161+
159,
162+
6,
163+
122,
164+
117,
165+
240,
166+
47,
167+
166,
168+
]
169+
database: keploy_db
170+
auth_plugin_name: caching_sha2_password
171+
connection_attributes:
172+
_client_name: libmariadb
173+
_client_version: 3.3.14
174+
_os: Linux
175+
_pid: "7"
176+
_platform: aarch64
177+
_server_host: mySQL
178+
zstdcompressionlevel: 0
179+
responses:
180+
- header:
181+
header:
182+
payload_length: 73
183+
sequence_id: 0
184+
packet_type: HandshakeV10
185+
message:
186+
protocol_version: 10
187+
server_version: 9.4.0
188+
connection_id: 54
189+
auth_plugin_data:
190+
[
191+
113,
192+
21,
193+
7,
194+
81,
195+
7,
196+
12,
197+
87,
198+
112,
199+
51,
200+
94,
201+
104,
202+
13,
203+
51,
204+
38,
205+
48,
206+
123,
207+
104,
208+
89,
209+
77,
210+
39,
211+
0,
212+
]
213+
filler: 0
214+
capability_flags: 3758096383
215+
character_set: 255
216+
status_flags: 2
217+
auth_plugin_name: caching_sha2_password
218+
- header:
219+
header:
220+
payload_length: 2
221+
sequence_id: 2
222+
packet_type: AuthMoreData
223+
message:
224+
status_tag: 1
225+
data: FastAuthSuccess
226+
- header:
227+
header:
228+
payload_length: 21
229+
sequence_id: 3
230+
packet_type: OK
231+
message:
232+
header: 0
233+
affected_rows: 0
234+
last_insert_id: 0
235+
status_flags: 16386
236+
warnings: 0
237+
info: "\0\f\x01\n\tkeploy_db"
238+
created: 1753793504
239+
reqtimestampmock: 2025-07-29T12:51:44.329059627Z
240+
restimestampmock: 2025-07-29T12:51:44.330062582Z
241+
```
242+
243+
## **Time to put things to the test 🧪:**
244+
245+
Note:
246+
If you want to view the coverage, follow the guide below:
247+
248+
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.
249+
250+
```bash
251+
keploy test -c "sudo docker run --name django-app --net keploy-network -p 8000:8000 -v $(pwd):$(pwd) --rm py-app"
252+
```
253+
254+
This is how your terminal would look like :
255+
256+
<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' }} />
257+
258+
Once the tests are executed, a .coverage file will be generated. To view the coverage report, run:
259+
260+
```bash
261+
python3 -m coverage report
262+
```
263+
264+
This is how output would look like :
265+
266+
<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' }} />
267+
268+
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)