diff --git a/sanic-mongo/README.md b/sanic-mongo/README.md new file mode 100644 index 0000000..f0cc267 --- /dev/null +++ b/sanic-mongo/README.md @@ -0,0 +1,122 @@ +This application is a simple movie management API built using Python's Sanic framework and MongoDB for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on Movie records. + +## Table of Contents + +# Introduction + +๐Ÿช„ Dive into the world of Movie CRUD Apps and see how seamlessly Keploy integrated with [Sanic](hhttps://sanic.dev/en/) and [MongoDB](https://www.mongodb.com/). Buckle up, it's gonna be a fun ride! ๐ŸŽข + +## Pre-Requisite ๐Ÿ› ๏ธ + +- Install WSL (`wsl --install`) for Windows Windows. + +## Optional ๐Ÿ› ๏ธ + +- Install Colima( `brew install colima && colima start` ) for MacOS MacOs. + +## Installation ๐Ÿ“ฅ + +Depending on your OS, choose your adventure: + +Alright, let's equip ourselves with the **latest Keploy binary**: + +```bash +curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz" | tar xz -C /tmp + +sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy +``` + +#### Add alias for Keploy: + +```bash +alias keploy='sudo docker run --pull always --name keploy-v2 -p 16789:16789 --privileged --pid=host -it -v "$(pwd)":/files -v /sys/fs/cgroup:/sys/fs/cgroup -v /sys/kernel/debug:/sys/kernel/debug -v /sys/fs/bpf:/sys/fs/bpf -v /var/run/docker.sock:/var/run/docker.sock -v '"$HOME"'/.keploy-config:/root/.keploy-config -v '"$HOME"'/.keploy:/root/.keploy --rm ghcr.io/keploy/keploy' +``` + +Now head to the folder of the application and run + +``` +pip3 install -r requirements.txt +``` + +### Lights, Camera, Record! ๐ŸŽฅ + +Capture the test-cases- + +```shell +keploy record -c "python3 server.py" +``` + +๐Ÿ”ฅ**Make some API calls**. Postman, Hoppscotch or even curl - take your pick! + +Let's make URLs short and sweet: + +### Generate testcases + +To generate testcases we just need to **make some API calls.** + +**1. Make a POST requests** + +```bash + curl -X "POST" "http://127.0.0.1:8000/add_movie" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d '{ + "name": "Whiplash" + }' +``` + +```bash + curl -X "POST" "http://127.0.0.1:8000/add_movie" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d '{ + "name": "Chappie" + }' +``` + +```bash + curl -X "POST" "http://127.0.0.1:8000/add_movie" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' \ + -d '{ + "name": "Titanic" + }' +``` + +**2. Make a GET request** + +In order to see all the movies added to the database, run: + +``` +curl -X "GET" "http://127.0.0.1:8000/movies" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' +``` + +**3. Make a DELETE request** + +In order to delete all the movies, run: + +```bash + curl -X "DELETE" "http://127.0.0.1:8000/movies" \ + -H 'Accept: application/json' \ + -H 'Content-Type: application/json; charset=utf-8' +``` + +You will now see a folder named `keploy` with your recorded tests. + +#### Run Tests + +Time to put things to the test ๐Ÿงช + +```shell +keploy test -c "python server.py" +``` + +## Wrapping it up ๐ŸŽ‰ + +Congrats on the journey so far! You've seen Keploy's power, flexed your coding muscles, and had a bit of fun too! Now, go out there and keep exploring, innovating, and creating! Remember, with the right tools and a sprinkle of fun, anything's possible.๐Ÿ˜Š๐Ÿš€ + +Happy coding! โœจ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ปโœจ + +
diff --git a/sanic-mongo/keploy/test-set-0/mocks.yaml b/sanic-mongo/keploy/test-set-0/mocks.yaml new file mode 100644 index 0000000..55e5e0a --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/mocks.yaml @@ -0,0 +1,490 @@ +version: api.keploy.io/v1beta1 +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|Motor","version": "4.6.3|3.4.0"},"os": {"type": "Linux","name": "Linux","architecture": "x86_64","version": "5.15.146.1-microsoft-standard-WSL2"},"platform": "CPython 3.10.12.final.0|asyncio"}}, returnFieldsSelector: }' + type: config + requests: + - header: + length: 303 + requestId: 1804289383 + 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|Motor","version":"4.6.3|3.4.0"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.15.146.1-microsoft-standard-WSL2"},"platform":"CPython 3.10.12.final.0|asyncio"}}' + return_fields_selector: "" + responses: + - header: + length: 329 + requestId: 13 + responseTo: 1804289383 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1719344783026"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"4"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 560917 + created: 1719344783 + reqTimestampMock: 2024-06-26T01:16:23.025984506+05:30 + resTimestampMock: 2024-06-26T01:16:23.026710262+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-1 +spec: + metadata: + operation: '{ OpQuery flags: [], fullCollectionName: admin.$cmd, numberToSkip: 0, numberToReturn: -1, query: {"ismaster": {"$numberInt":"1"},"helloOk": true,"client": {"driver": {"name": "PyMongo|Motor","version": "4.6.3|3.4.0"},"os": {"type": "Linux","name": "Linux","architecture": "x86_64","version": "5.15.146.1-microsoft-standard-WSL2"},"platform": "CPython 3.10.12.final.0|asyncio"},"compression": []}, returnFieldsSelector: }' + type: config + requests: + - header: + length: 321 + requestId: 1714636915 + 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|Motor","version":"4.6.3|3.4.0"},"os":{"type":"Linux","name":"Linux","architecture":"x86_64","version":"5.15.146.1-microsoft-standard-WSL2"},"platform":"CPython 3.10.12.final.0|asyncio"},"compression":[]}' + return_fields_selector: "" + responses: + - header: + length: 329 + requestId: 15 + responseTo: 1714636915 + Opcode: 1 + message: + response_flags: 8 + cursor_id: 0 + starting_from: 0 + number_returned: 1 + documents: + - '{"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1719344783030"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"6"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}}' + read_delay: 657515 + created: 1719344783 + reqTimestampMock: 2024-06-26T01:16:23.030363133+05:30 + resTimestampMock: 2024-06-26T01:16:23.031173194+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-2 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }, { SectionSingle identifier: documents , msgs: [ {"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"} ] }], checksum: 0 }' + requests: + - header: + length: 179 + requestId: 1957747793 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + - '{ SectionSingle identifier: documents , msgs: [ {"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"} ] }' + checksum: 0 + read_delay: 542094 + responses: + - header: + length: 45 + requestId: 16 + responseTo: 1957747793 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 551413 + created: 1719344783 + reqTimestampMock: 2024-06-26T01:16:23.031860881+05:30 + resTimestampMock: 2024-06-26T01:16:23.032549882+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-3 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e8fd71cb97567de07c5"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }], checksum: 0 }' + requests: + - header: + length: 166 + requestId: 424238335 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e8fd71cb97567de07c5"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + checksum: 0 + read_delay: 1402363 + responses: + - header: + length: 162 + requestId: 17 + responseTo: 424238335 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"}],"id":{"$numberLong":"0"},"ns":"myapp.movies"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 778841 + created: 1719344783 + reqTimestampMock: 2024-06-26T01:16:23.034169772+05:30 + resTimestampMock: 2024-06-26T01:16:23.035109665+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-4 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }, { SectionSingle identifier: documents , msgs: [ {"_id":"667b1e95d71cb97567de07c6","name":"Chappie"} ] }], checksum: 0 }' + requests: + - header: + length: 178 + requestId: 719885386 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + - '{ SectionSingle identifier: documents , msgs: [ {"_id":"667b1e95d71cb97567de07c6","name":"Chappie"} ] }' + checksum: 0 + read_delay: 6203095487 + responses: + - header: + length: 45 + requestId: 18 + responseTo: 719885386 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 745693 + created: 1719344789 + reqTimestampMock: 2024-06-26T01:16:29.238351946+05:30 + resTimestampMock: 2024-06-26T01:16:29.239303785+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-5 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e95d71cb97567de07c6"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }], checksum: 0 }' + requests: + - header: + length: 166 + requestId: 1649760492 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e95d71cb97567de07c6"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + checksum: 0 + read_delay: 2447949 + responses: + - header: + length: 161 + requestId: 19 + responseTo: 1649760492 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"_id":"667b1e95d71cb97567de07c6","name":"Chappie"}],"id":{"$numberLong":"0"},"ns":"myapp.movies"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 630241 + created: 1719344789 + reqTimestampMock: 2024-06-26T01:16:29.241914889+05:30 + resTimestampMock: 2024-06-26T01:16:29.242682647+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-6 +spec: + metadata: + operation: '{ OpMsg flags: 65536, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 134 + requestId: 846930886 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 65536 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxAwaitTimeMS":{"$numberInt":"10000"},"$db":"admin"} }' + checksum: 0 + read_delay: 2161277 + responses: + - header: + length: 313 + requestId: 20 + responseTo: 846930886 + Opcode: 2013 + message: + flagBits: 2 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1719344793039"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"4"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 10010918319 + created: 1719344793 + reqTimestampMock: 2024-06-26T01:16:23.029068649+05:30 + resTimestampMock: 2024-06-26T01:16:33.040142118+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-7 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 52 + requestId: 596516649 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"hello":{"$numberInt":"1"},"$db":"admin"} }' + checksum: 0 + read_delay: 10012578387 + responses: + - header: + length: 313 + requestId: 21 + responseTo: 596516649 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"isWritablePrimary":true,"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1719344793043"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"5"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 455336 + created: 1719344793 + reqTimestampMock: 2024-06-26T01:16:33.043665579+05:30 + resTimestampMock: 2024-06-26T01:16:33.044280965+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-8 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }, { SectionSingle identifier: documents , msgs: [ {"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"} ] }], checksum: 0 }' + requests: + - header: + length: 178 + requestId: 1189641421 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"insert":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + - '{ SectionSingle identifier: documents , msgs: [ {"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"} ] }' + checksum: 0 + read_delay: 6649200875 + responses: + - header: + length: 45 + requestId: 22 + responseTo: 1189641421 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"1"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 561569 + created: 1719344795 + reqTimestampMock: 2024-06-26T01:16:35.892029796+05:30 + resTimestampMock: 2024-06-26T01:16:35.892711+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-9 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e9bd71cb97567de07c7"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }], checksum: 0 }' + requests: + - header: + length: 166 + requestId: 1025202362 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"movies","filter":{"_id":"667b1e9bd71cb97567de07c7"},"limit":{"$numberInt":"1"},"singleBatch":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + checksum: 0 + read_delay: 1988209 + responses: + - header: + length: 161 + requestId: 23 + responseTo: 1025202362 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"}],"id":{"$numberLong":"0"},"ns":"myapp.movies"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 502216 + created: 1719344795 + reqTimestampMock: 2024-06-26T01:16:35.894867685+05:30 + resTimestampMock: 2024-06-26T01:16:35.895517417+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-10 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"find":"movies","filter":{},"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }], checksum: 0 }' + requests: + - header: + length: 107 + requestId: 1350490027 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"find":"movies","filter":{},"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + checksum: 0 + read_delay: 6177066246 + responses: + - header: + length: 343 + requestId: 24 + responseTo: 1350490027 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"cursor":{"firstBatch":[{"_id":"667b1e6d33a7849da6520cea","name":"Whiplash"},{"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"},{"_id":"667b1e95d71cb97567de07c6","name":"Chappie"},{"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"}],"id":{"$numberLong":"0"},"ns":"myapp.movies"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 1275690 + created: 1719344802 + reqTimestampMock: 2024-06-26T01:16:42.072696856+05:30 + resTimestampMock: 2024-06-26T01:16:42.074091198+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-11 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }], checksum: 0 }' + type: config + requests: + - header: + length: 65 + requestId: 783368690 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"ismaster":{"$numberInt":"1"},"helloOk":true,"$db":"admin"} }' + checksum: 0 + read_delay: 10012605933 + responses: + - header: + length: 314 + requestId: 26 + responseTo: 783368690 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"helloOk":true,"ismaster":true,"topologyVersion":{"processId":{"$oid":"667b1d2066b0c1d16885b016"},"counter":{"$numberLong":"0"}},"maxBsonObjectSize":{"$numberInt":"16777216"},"maxMessageSizeBytes":{"$numberInt":"48000000"},"maxWriteBatchSize":{"$numberInt":"100000"},"localTime":{"$date":{"$numberLong":"1719344803057"}},"logicalSessionTimeoutMinutes":{"$numberInt":"30"},"connectionId":{"$numberInt":"5"},"minWireVersion":{"$numberInt":"0"},"maxWireVersion":{"$numberInt":"21"},"readOnly":false,"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 522723 + created: 1719344803 + reqTimestampMock: 2024-06-26T01:16:43.057053931+05:30 + resTimestampMock: 2024-06-26T01:16:43.057762251+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-12 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"delete":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }, { SectionSingle identifier: deletes , msgs: [ {"q":{},"limit":{"$numberInt":"0"}} ] }], checksum: 0 }' + requests: + - header: + length: 143 + requestId: 1102520059 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"delete":"movies","ordered":true,"lsid":{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}},"$db":"myapp"} }' + - '{ SectionSingle identifier: deletes , msgs: [ {"q":{},"limit":{"$numberInt":"0"}} ] }' + checksum: 0 + read_delay: 9127441948 + responses: + - header: + length: 45 + requestId: 27 + responseTo: 1102520059 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"n":{"$numberInt":"4"},"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 761264 + created: 1719344811 + reqTimestampMock: 2024-06-26T01:16:51.201703124+05:30 + resTimestampMock: 2024-06-26T01:16:51.20258821+05:30 +--- +version: api.keploy.io/v1beta1 +kind: Mongo +name: mock-13 +spec: + metadata: + operation: '{ OpMsg flags: 0, sections: [{ SectionSingle msg: {"endSessions":[{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}}],"$db":"admin"} }], checksum: 0 }' + requests: + - header: + length: 92 + requestId: 1967513926 + responseTo: 0 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"endSessions":[{"id":{"$binary":{"base64":"Mx+ps9bVQSSsAdH3K5VdCg==","subType":"04"}}}],"$db":"admin"} }' + checksum: 0 + read_delay: 8507808445 + responses: + - header: + length: 38 + requestId: 30 + responseTo: 1967513926 + Opcode: 2013 + message: + flagBits: 0 + sections: + - '{ SectionSingle msg: {"ok":{"$numberDouble":"1.0"}} }' + checksum: 0 + read_delay: 382255 + created: 1719344819 + reqTimestampMock: 2024-06-26T01:16:59.710542397+05:30 + resTimestampMock: 2024-06-26T01:16:59.711041681+05:30 diff --git a/sanic-mongo/keploy/test-set-0/tests/test-1.yaml b/sanic-mongo/keploy/test-set-0/tests/test-1.yaml new file mode 100644 index 0000000..320cd9b --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/tests/test-1.yaml @@ -0,0 +1,42 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-1 +spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://127.0.0.1:8000/add_movie + header: + Accept: application/json + Content-Length: "20" + Content-Type: application/json; charset=utf-8 + Host: 127.0.0.1:8000 + User-Agent: curl/7.81.0 + body: '{"name": "Whiplash"}' + timestamp: 2024-06-26T01:16:23.022752322+05:30 + resp: + status_code: 200 + header: + Alt-Svc: "" + Connection: keep-alive + Content-Length: "52" + Content-Type: application/json + body: '{"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"}' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-06-26T01:16:25.086349854+05:30 + objects: [] + assertions: + noise: {} + created: 1719344785 +curl: |- + curl --request POST \ + --url http://127.0.0.1:8000/add_movie \ + --header 'Host: 127.0.0.1:8000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json; charset=utf-8' \ + --data '{"name": "Whiplash"}' diff --git a/sanic-mongo/keploy/test-set-0/tests/test-2.yaml b/sanic-mongo/keploy/test-set-0/tests/test-2.yaml new file mode 100644 index 0000000..719b20c --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/tests/test-2.yaml @@ -0,0 +1,42 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-2 +spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://127.0.0.1:8000/add_movie + header: + Accept: application/json + Content-Length: "19" + Content-Type: application/json; charset=utf-8 + Host: 127.0.0.1:8000 + User-Agent: curl/7.81.0 + body: '{"name": "Chappie"}' + timestamp: 2024-06-26T01:16:29.236765225+05:30 + resp: + status_code: 200 + header: + Alt-Svc: "" + Connection: keep-alive + Content-Length: "51" + Content-Type: application/json + body: '{"_id":"667b1e95d71cb97567de07c6","name":"Chappie"}' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-06-26T01:16:31.312393895+05:30 + objects: [] + assertions: + noise: {} + created: 1719344791 +curl: |- + curl --request POST \ + --url http://127.0.0.1:8000/add_movie \ + --header 'Host: 127.0.0.1:8000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json; charset=utf-8' \ + --data '{"name": "Chappie"}' diff --git a/sanic-mongo/keploy/test-set-0/tests/test-3.yaml b/sanic-mongo/keploy/test-set-0/tests/test-3.yaml new file mode 100644 index 0000000..9948d84 --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/tests/test-3.yaml @@ -0,0 +1,42 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-3 +spec: + metadata: {} + req: + method: POST + proto_major: 1 + proto_minor: 1 + url: http://127.0.0.1:8000/add_movie + header: + Accept: application/json + Content-Length: "19" + Content-Type: application/json; charset=utf-8 + Host: 127.0.0.1:8000 + User-Agent: curl/7.81.0 + body: '{"name": "Titanic"}' + timestamp: 2024-06-26T01:16:35.890538161+05:30 + resp: + status_code: 200 + header: + Alt-Svc: "" + Connection: keep-alive + Content-Length: "51" + Content-Type: application/json + body: '{"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"}' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-06-26T01:16:37.940966466+05:30 + objects: [] + assertions: + noise: {} + created: 1719344797 +curl: |- + curl --request POST \ + --url http://127.0.0.1:8000/add_movie \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json; charset=utf-8' \ + --header 'Host: 127.0.0.1:8000' \ + --header 'User-Agent: curl/7.81.0' \ + --data '{"name": "Titanic"}' diff --git a/sanic-mongo/keploy/test-set-0/tests/test-4.yaml b/sanic-mongo/keploy/test-set-0/tests/test-4.yaml new file mode 100644 index 0000000..f69d270 --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/tests/test-4.yaml @@ -0,0 +1,40 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-4 +spec: + metadata: {} + req: + method: GET + proto_major: 1 + proto_minor: 1 + url: http://127.0.0.1:8000/movies + header: + Accept: application/json + Content-Type: application/json; charset=utf-8 + Host: 127.0.0.1:8000 + User-Agent: curl/7.81.0 + body: "" + timestamp: 2024-06-26T01:16:42.071382334+05:30 + resp: + status_code: 200 + header: + Alt-Svc: "" + Connection: keep-alive + Content-Length: "211" + Content-Type: application/json + body: '[{"_id":"667b1e6d33a7849da6520cea","name":"Whiplash"},{"_id":"667b1e8fd71cb97567de07c5","name":"Whiplash"},{"_id":"667b1e95d71cb97567de07c6","name":"Chappie"},{"_id":"667b1e9bd71cb97567de07c7","name":"Titanic"}]' + status_message: OK + proto_major: 0 + proto_minor: 0 + timestamp: 2024-06-26T01:16:44.167252247+05:30 + objects: [] + assertions: + noise: {} + created: 1719344804 +curl: | + curl --request GET \ + --url http://127.0.0.1:8000/movies \ + --header 'Host: 127.0.0.1:8000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json; charset=utf-8' \ diff --git a/sanic-mongo/keploy/test-set-0/tests/test-5.yaml b/sanic-mongo/keploy/test-set-0/tests/test-5.yaml new file mode 100644 index 0000000..198d464 --- /dev/null +++ b/sanic-mongo/keploy/test-set-0/tests/test-5.yaml @@ -0,0 +1,38 @@ +version: api.keploy.io/v1beta1 +kind: Http +name: test-5 +spec: + metadata: {} + req: + method: DELETE + proto_major: 1 + proto_minor: 1 + url: http://127.0.0.1:8000/movies + header: + Accept: application/json + Content-Type: application/json; charset=utf-8 + Host: 127.0.0.1:8000 + User-Agent: curl/7.81.0 + body: "" + timestamp: 2024-06-26T01:16:51.200010582+05:30 + resp: + status_code: 204 + header: + Alt-Svc: "" + Connection: keep-alive + body: "" + status_message: No Content + proto_major: 0 + proto_minor: 0 + timestamp: 2024-06-26T01:16:53.208616296+05:30 + objects: [] + assertions: + noise: {} + created: 1719344813 +curl: | + curl --request DELETE \ + --url http://127.0.0.1:8000/movies \ + --header 'Content-Type: application/json; charset=utf-8' \ + --header 'Host: 127.0.0.1:8000' \ + --header 'User-Agent: curl/7.81.0' \ + --header 'Accept: application/json' \ diff --git a/sanic-mongo/requirements.txt b/sanic-mongo/requirements.txt new file mode 100644 index 0000000..04a5484 --- /dev/null +++ b/sanic-mongo/requirements.txt @@ -0,0 +1,3 @@ +pymongo==4.6.3 +sanic==23.12.1 +sanic_motor==0.7.0 \ No newline at end of file diff --git a/sanic-mongo/server.py b/sanic-mongo/server.py new file mode 100644 index 0000000..c05998d --- /dev/null +++ b/sanic-mongo/server.py @@ -0,0 +1,60 @@ +from sanic import Sanic, text +from sanic.response import json as json_response +from sanic.exceptions import NotFound +from sanic_motor import BaseModel +from bson import ObjectId + +app = Sanic(__name__) + +settings = dict( + MOTOR_URI='mongodb://localhost:27017/myapp', LOGO=None +) + +app.config.update(settings) + +BaseModel.init_app(app) + +class Movie(BaseModel): + __coll__ = "movies" + +@app.route("/add_movie", methods=["POST"]) +async def add_movie(request): + movie = request.json + movie["_id"] = str(ObjectId()) + + new_movie = await Movie.insert_one(movie) + created_movie = await Movie.find_one({"_id": new_movie.inserted_id}, as_raw=True) + return json_response(created_movie) + + +@app.route("/movies", methods=["GET"]) +async def list_movies(request): + movies = await Movie.find(as_raw=True) + return json_response(movies.objects) + + + +@app.route("/movies/", methods=["GET"]) +async def get_movie(request, id): + if (movies := await Movie.find_one({"_id": id}, as_raw=True)) is not None: + return json_response(movies) + + raise NotFound(f"Movie {id} not found") + + +@app.route("/movies/", methods=["DELETE"]) +async def delete_movie(request, id): + delete_result = await Movie.delete_one({"_id": id}) + + if delete_result.deleted_count == 1: + return json_response({}, status=204) + + raise NotFound(f"Movie {id} not found") + +@app.route("/movies", methods=["DELETE"]) +async def delete_all_movies(request): + await Movie.delete_many({}) + return json_response({}, status=204) + +if __name__ == "__main__": + app.run(host="127.0.0.1", port=8000, debug=True) \ No newline at end of file