From c174ae0ee72d44b05a58a62a7642993a2199102d Mon Sep 17 00:00:00 2001 From: Achanandhi-M Date: Tue, 29 Jul 2025 19:38:39 +0530 Subject: [PATCH 1/3] feat: added django-mysql quickstart guide Signed-off-by: Achanandhi-M --- .../quickstart/python-django-mysql.md | 268 ++++++++++++++++++ .../version-3.0.0-sidebars.json | 1 + 2 files changed, 269 insertions(+) create mode 100644 versioned_docs/version-3.0.0/quickstart/python-django-mysql.md diff --git a/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md new file mode 100644 index 000000000..db2d8a0b7 --- /dev/null +++ b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md @@ -0,0 +1,268 @@ +--- +id: samples-django-mysql +title: Employee Data CRUD App +sidebar_label: Django + mysql +description: The following sample app showcases how to use the Django framework and the Keploy Platform. +tags: + - python + - quickstart + - samples + - examples + - tutorial + - python-framework + - mysql +keyword: + - Django Framework + - mysql + - SQL + - Python + - API Test generator + - Auto case generation +--- + +## Introduction + +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. + +import InstallationGuide from '../concepts/installation.md' + + + +# Get Started! ๐ŸŽฌ + +## Clone the app ๐Ÿงช + +```bash +git clone https://github.com/keploy/samples-python.git && cd samples-python/django-mysql +``` + +Open a different terminal and setup your Mysql through docker + +```shell +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 + +``` + +Build and Run Django Application Container + +```shell +docker build --build-arg HOST_PWD="$(pwd)" -t py-app . + +``` + +## Lights, Camera, Record! ๐ŸŽฅ + +Capture the test-cases- + +```shell +keploy record -c "sudo docker run --name django-app --net keploy-network -p 8000:8000 -v $(pwd):$(pwd) --rm py-app" +``` + +You should be able to see this in your terminal + +Sample Keploy record django-mysql + +๐Ÿ”ฅ**Make some API calls**. + +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 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"}' + +``` + +2. **Make a GET request:** + +```bash + +curl -X GET http://localhost:8000/api/employee/ + +``` + +3. **Make a PUT request:** + +```bash + + 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"}' + +``` + +4. **Make a DELETE request:** + +```bash + curl -X "DELETE" "http://127.0.0.1:8000/movies" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' + +``` + +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`. + +This is an example of what your mocks would look like + +```yaml +# Generated by Keploy (2.6.22) +version: api.keploy.io/v1beta1 +kind: MySQL +name: mock-0 +spec: + metadata: + connID: "0" + requestOperation: HandshakeV10 + responseOperation: OK + type: config + requests: + - header: + header: + payload_length: 205 + sequence_id: 1 + packet_type: HandshakeResponse41 + message: + capability_flags: 12558991 + max_packet_size: 1073741824 + character_set: 33 + filler: + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + username: admin + 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, + ] + database: keploy_db + auth_plugin_name: caching_sha2_password + connection_attributes: + _client_name: libmariadb + _client_version: 3.3.14 + _os: Linux + _pid: "7" + _platform: aarch64 + _server_host: mySQL + zstdcompressionlevel: 0 + responses: + - header: + header: + payload_length: 73 + sequence_id: 0 + packet_type: HandshakeV10 + message: + protocol_version: 10 + server_version: 9.4.0 + connection_id: 54 + auth_plugin_data: + [ + 113, + 21, + 7, + 81, + 7, + 12, + 87, + 112, + 51, + 94, + 104, + 13, + 51, + 38, + 48, + 123, + 104, + 89, + 77, + 39, + 0, + ] + filler: 0 + capability_flags: 3758096383 + character_set: 255 + status_flags: 2 + auth_plugin_name: caching_sha2_password + - header: + header: + payload_length: 2 + sequence_id: 2 + packet_type: AuthMoreData + message: + status_tag: 1 + data: FastAuthSuccess + - header: + header: + payload_length: 21 + sequence_id: 3 + packet_type: OK + message: + header: 0 + affected_rows: 0 + last_insert_id: 0 + status_flags: 16386 + warnings: 0 + info: "\0\f\x01\n\tkeploy_db" + created: 1753793504 + reqtimestampmock: 2025-07-29T12:51:44.329059627Z + restimestampmock: 2025-07-29T12:51:44.330062582Z +``` + +## **Time to put things to the test ๐Ÿงช:** + +Note: +If you want to view the coverage, follow the guide below: + +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. + +```bash +keploy test -c "sudo docker run --name django-app --net keploy-network -p 8000:8000 -v $(pwd):$(pwd) --rm py-app" +``` + +This is how your terminal would look like : + +Sample Keploy Test django-mysql + +Once the tests are executed, a .coverage file will be generated. To view the coverage report, run: + +```bash +python3 -m coverage report +``` + +This is how output would look like : + +Sample Keploy Test django-mysql + +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 diff --git a/versioned_sidebars/version-3.0.0-sidebars.json b/versioned_sidebars/version-3.0.0-sidebars.json index ebcc1c71f..6c62bb98a 100644 --- a/versioned_sidebars/version-3.0.0-sidebars.json +++ b/versioned_sidebars/version-3.0.0-sidebars.json @@ -126,6 +126,7 @@ "collapsed": true, "items": [ "quickstart/samples-django", + "quickstart/samples-django-mysql", "quickstart/samples-flask", "quickstart/samples-fastapi", "quickstart/samples-fastapi-twilio", From bc74c1b852bf10bab9df261d95f63589bdcc28a2 Mon Sep 17 00:00:00 2001 From: Achanandhi-M Date: Mon, 11 Aug 2025 15:02:57 +0530 Subject: [PATCH 2/3] fix: django-mysql-quickstart Signed-off-by: Achanandhi-M --- .../version-3.0.0/quickstart/python-django-mysql.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md index db2d8a0b7..23421a3f3 100644 --- a/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md +++ b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md @@ -97,10 +97,7 @@ curl -X GET http://localhost:8000/api/employee/ 4. **Make a DELETE request:** ```bash - curl -X "DELETE" "http://127.0.0.1:8000/movies" \ - -H 'Accept: application/json' \ - -H 'Content-Type: application/json; charset=utf-8' - +curl -X DELETE http://localhost:8000/api/employee/delete/1/ ``` 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`. From ad411c6aba762c6964fed330f18a085d6c8be7fc Mon Sep 17 00:00:00 2001 From: Achanandhi-M Date: Wed, 13 Aug 2025 15:09:29 +0530 Subject: [PATCH 3/3] feat: added django keyword Signed-off-by: Achanandhi-M --- versioned_docs/version-3.0.0/quickstart/python-django-mysql.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md index 23421a3f3..eaa1ccca5 100644 --- a/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md +++ b/versioned_docs/version-3.0.0/quickstart/python-django-mysql.md @@ -8,6 +8,7 @@ tags: - quickstart - samples - examples + - django - tutorial - python-framework - mysql @@ -17,6 +18,7 @@ keyword: - SQL - Python - API Test generator + - django - Auto case generation ---