Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 34 additions & 53 deletions versioned_docs/version-2.0.0/quickstart/python-flask-mongo.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,26 @@ Now, your app will start running, and you have to make some API calls to generat
1. **Make a POST request:**

```bash
curl -X POST -H "Content-Type: application/json" -d '{"title":"Task 1","description":"Important task"}' http://localhost:5000/api/tasks
curl -X POST -H "Content-Type: application/json" -d '{"student_id": "12345", "name": "John Doe", "age": 20}' http://localhost:6000/students
```

2. **Make a GET request:**

```bash
curl http://localhost:5000/api/tasks
curl http://localhost:6000/students
```

3. **Make a PUT request:**


```bash
curl -X PUT -H "Content-Type: application/json" -d '{"title":"Task 1","description":"Random task"}' http://localhost:5000/api/tasks/12345
curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21}' http://localhost:6000/students/12345
```

4. **Make a DELETE request:**

```bash
curl -X DELETE http://localhost:5000/api/tasks/12345
curl -X DELETE http://localhost:6000/students/12345
```

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`.
Expand All @@ -263,66 +264,46 @@ name: test-1
spec:
metadata: {}
req:
method: GET
method: POST
proto_major: 1
proto_minor: 1
url: http://localhost:5000/api/tasks
url: http://localhost:6000/students
header:
Accept: "*/*"
Accept-Encoding: gzip, deflate, br
Cache-Control: no-cache
Connection: keep-alive
Content-Length: "59"
Content-Length: "54"
Content-Type: application/json
Host: localhost:5000
Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1
User-Agent: PostmanRuntime/7.32.1
body: '{"title": "Task 6","description": "Description for Task 6"}'
timestamp: 2024-04-22T16:38:39.232565209+05:30
Host: localhost:6000
User-Agent: curl/8.7.1
body: '{"student_id": "12345", "name": "John Doe", "age": 20}'
timestamp: 2025-04-02T13:12:05.255523333Z
resp:
status_code: 200
header:
Access-Control-Allow-Origin: "*"
Content-Length: "267"
Content-Length: "48"
Content-Type: application/json
Date: Mon, 22 Apr 2024 11:08:39 GMT
Server: Werkzeug/3.0.2 Python/3.10.12
Date: Wed, 02 Apr 2025 13:12:05 GMT
Server: Werkzeug/2.2.2 Python/3.9.21
body: |
{
"tasks": [
{
"description": "should update",
"id": "6626362fc7c5eddf174c88e4",
"title": "Updated"
},
{
"description": "Should work",
"id": "66263667c7c5eddf174c88e5",
"title": "Let's Check another time"
}
]
"message": "Student created successfully"
}
status_message: OK
proto_major: 0
proto_minor: 0
timestamp: 2024-04-22T16:38:41.245704918+05:30
timestamp: 2025-04-02T13:12:07.292707847Z
objects: []
assertions:
noise:
header.Date: []
created: 1713784121
created: 1743599527
curl: |-
curl --request GET \
--url http://localhost:5000/api/tasks \
--header 'Host: localhost:5000' \
--header 'User-Agent: PostmanRuntime/7.32.1' \
curl --request POST \
--url http://localhost:6000/students \
--header 'Host: localhost:6000' \
--header 'User-Agent: curl/8.7.1' \
--header 'Accept: */*' \
--header 'Content-Type: application/json' \
--header 'Connection: keep-alive' \
--header 'Cache-Control: no-cache' \
--header 'Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1' \
--header 'Accept-Encoding: gzip, deflate, br' \
--data '{"title": "Task 6","description": "Description for Task 6"}'
--data "{\"student_id\": \"12345\", \"name\": \"John Doe\", \"age\": 20}"
```

This is how the `mocks.yml` looks like:
Expand All @@ -333,38 +314,38 @@ kind: Mongo
name: mock-0
spec:
metadata:
operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.6.3"},"os": {"type": "Linux","name": "Linux","architecture": "x86_64","version": "5.15.146.1-microsoft-standard-WSL2"},"platform": "CPython 3.10.12.final.0"}}, returnFieldsSelector: }'
operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo","version": "4.4.1"},"os": {"type": "Linux","name": "Linux","architecture": "aarch64","version": "6.1.0-32-cloud-arm64"},"platform": "CPython 3.9.21.final.0"}}, returnFieldsSelector: }'
type: config
requests:
- header:
length: 283
requestId: 1804289383
length: 269
requestId: 846930886
responseTo: 0
Opcode: 2004
message:
flags: 0
collection_name: admin.$cmd
number_to_skip: 0
number_to_return: -1
query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.6.3"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.15.146.1-microsoft-standard-WSL2"},"platform":"CPython 3.10.12.final.0"}}'
query: '{"ismaster":{"$numberInt":"1"},"helloOk":true,"client":{"driver":{"name":"PyMongo","version":"4.4.1"},"os":{"type":"Linux","name":"Linux","architecture":"aarch64","version":"6.1.0-32-cloud-arm64"},"platform":"CPython 3.9.21.final.0"}}'
return_fields_selector: ""
responses:
- header:
length: 329
requestId: 238
responseTo: 1804289383
requestId: 3
responseTo: 846930886
Opcode: 1
message:
response_flags: 8
cursor_id: 0
starting_from: 0
number_returned: 1
documents:
- '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"6626352423399d438e00b0cf"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1713784113763"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"18"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}'
read_delay: 1010011
created: 1713784113
reqTimestampMock: 2024-04-22T16:38:33.762559618+05:30
resTimestampMock: 2024-04-22T16:38:33.763749062+05:30
- '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"67ed3773a2f7dd8385defa99"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1743599485435"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"1"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"25"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}'
read_delay: 990489
created: 1743599485
reqTimestampMock: 2025-04-02T13:11:25.434864042Z
resTimestampMock: 2025-04-02T13:11:25.436114528Z
```

## Run the tests
Expand Down