@@ -233,25 +233,26 @@ Now, your app will start running, and you have to make some API calls to generat
2332331. **Make a POST request:**
234234
235235` ` ` bash
236- curl -X POST -H "Content-Type: application/json" -d '{"title":"Task 1","description":"Important task" }' http://localhost:5000/api/tasks
236+ curl -X POST -H "Content-Type: application/json" -d '{"student_id": "12345", "name": "John Doe", "age": 20 }' http://localhost:6000/students
237237` ` `
238238
2392392. **Make a GET request:**
240240
241241` ` ` bash
242- curl http://localhost:5000/api/tasks
242+ curl http://localhost:6000/students
243243` ` `
244244
2452453. **Make a PUT request:**
246246
247+
247248` ` ` bash
248- curl -X PUT -H "Content-Type: application/json" -d '{"title":"Task 1","description":"Random task" }' http://localhost:5000/api/tasks /12345
249+ curl -X PUT -H "Content-Type: application/json" -d '{"name": "Jane Smith", "age": 21 }' http://localhost:6000/students /12345
249250` ` `
250251
2512524. **Make a DELETE request:**
252253
253254` ` ` bash
254- curl -X DELETE http://localhost:5000/api/tasks /12345
255+ curl -X DELETE http://localhost:6000/students /12345
255256` ` `
256257
257258And 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`.
@@ -263,66 +264,46 @@ name: test-1
263264spec:
264265 metadata: {}
265266 req:
266- method: GET
267+ method: POST
267268 proto_major: 1
268269 proto_minor: 1
269- url: http://localhost:5000/api/tasks
270+ url: http://localhost:6000/students
270271 header:
271272 Accept: "*/*"
272- Accept-Encoding: gzip, deflate, br
273- Cache-Control: no-cache
274- Connection: keep-alive
275- Content-Length: "59"
273+ Content-Length: "54"
276274 Content-Type: application/json
277- Host: localhost:5000
278- Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1
279- User-Agent: PostmanRuntime/7.32.1
280- body: '{"title": "Task 6","description": "Description for Task 6"}'
281- timestamp: 2024-04-22T16:38:39.232565209+05:30
275+ Host: localhost:6000
276+ User-Agent: curl/8.7.1
277+ body: '{"student_id": "12345", "name": "John Doe", "age": 20}'
278+ timestamp: 2025-04-02T13:12:05.255523333Z
282279 resp:
283280 status_code: 200
284281 header:
285- Access-Control-Allow-Origin: "*"
286- Content-Length: "267"
282+ Content-Length: "48"
287283 Content-Type: application/json
288- Date: Mon, 22 Apr 2024 11:08:39 GMT
289- Server: Werkzeug/3.0 .2 Python/3.10.12
284+ Date: Wed, 02 Apr 2025 13:12:05 GMT
285+ Server: Werkzeug/2.2 .2 Python/3.9.21
290286 body: |
291287 {
292- "tasks": [
293- {
294- "description": "should update",
295- "id": "6626362fc7c5eddf174c88e4",
296- "title": "Updated"
297- },
298- {
299- "description": "Should work",
300- "id": "66263667c7c5eddf174c88e5",
301- "title": "Let's Check another time"
302- }
303- ]
288+ "message": "Student created successfully"
304289 }
305290 status_message: OK
306291 proto_major: 0
307292 proto_minor: 0
308- timestamp: 2024 -04-22T16:38:41.245704918+05:30
293+ timestamp: 2025 -04-02T13:12:07.292707847Z
309294 objects: []
310295 assertions:
311296 noise:
312297 header.Date: []
313- created: 1713784121
298+ created: 1743599527
314299curl: |-
315- curl --request GET \
316- --url http://localhost:5000/api/tasks \
317- --header 'Host: localhost:5000 ' \
318- --header 'User-Agent: PostmanRuntime/7.32 .1' \
300+ curl --request POST \
301+ --url http://localhost:6000/students \
302+ --header 'Host: localhost:6000 ' \
303+ --header 'User-Agent: curl/8.7 .1' \
319304 --header 'Accept: */*' \
320305 --header 'Content-Type: application/json' \
321- --header 'Connection: keep-alive' \
322- --header 'Cache-Control: no-cache' \
323- --header 'Postman-Token: 10512b5c-4da7-4ef3-b145-101cdd1357f1' \
324- --header 'Accept-Encoding: gzip, deflate, br' \
325- --data '{"title": "Task 6","description": "Description for Task 6"}'
306+ --data "{\" student_id\" : \" 12345\" , \" name\" : \" John Doe\" , \" age\" : 20}"
326307` ` `
327308
328309This is how the `mocks.yml` looks like :
@@ -333,38 +314,38 @@ kind: Mongo
333314name: mock-0
334315spec:
335316 metadata:
336- 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: }'
317+ 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: }'
337318 type: config
338319 requests:
339320 - header:
340- length: 283
341- requestId: 1804289383
321+ length: 269
322+ requestId: 846930886
342323 responseTo: 0
343324 Opcode: 2004
344325 message:
345326 flags: 0
346327 collection_name: admin.$cmd
347328 number_to_skip: 0
348329 number_to_return: -1
349- 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"}}'
330+ 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"}}'
350331 return_fields_selector: ""
351332 responses:
352333 - header:
353334 length: 329
354- requestId: 238
355- responseTo: 1804289383
335+ requestId: 3
336+ responseTo: 846930886
356337 Opcode: 1
357338 message:
358339 response_flags: 8
359340 cursor_id: 0
360341 starting_from: 0
361342 number_returned: 1
362343 documents:
363- - '{"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"}}'
364- read_delay: 1010011
365- created: 1713784113
366- reqTimestampMock: 2024 -04-22T16:38:33.762559618+05:30
367- resTimestampMock: 2024 -04-22T16:38:33.763749062+05:30
344+ - '{"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"}}'
345+ read_delay: 990489
346+ created: 1743599485
347+ reqTimestampMock: 2025 -04-02T13:11:25.434864042Z
348+ resTimestampMock: 2025 -04-02T13:11:25.436114528Z
368349` ` `
369350
370351# # Run the tests
0 commit comments