Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b6a32e8
feat: adding django-postgres sample application
nehagup Sep 28, 2023
3453600
fix: removed the docker part from readme (#5)
Shashwat79802 Oct 19, 2023
73af76f
feat: adding new sample app for python (#7)
Shashwat79802 Oct 24, 2023
a4f811e
feat: application description added to the master readme
Shashwat79802 Oct 28, 2023
fc9acbd
feat: adding new python sample app
Shashwat79802 Nov 14, 2023
d854abb
Merge pull request #8 from Shashwat79802/main
Sonichigo Nov 16, 2023
0bd58eb
fix: updated requirements file, docker-compose config
Shashwat79802 Dec 12, 2023
d619dbc
Merge branch 'keploy:main' into main
Shashwat79802 Dec 12, 2023
0ad9d40
Merge pull request #9 from Shashwat79802/main
PranshuSrivastava Dec 12, 2023
b467f10
feat: added new requirements & changed port to 5432 (#11)
prajwalpd7 Jan 30, 2024
fe09284
fix: app running command
Sonichigo Feb 9, 2024
66c2ffd
feat: added missing steps (#10)
Sonichigo Feb 9, 2024
6426975
fix: app running command (#12)
Sonichigo Feb 9, 2024
5503b0b
fix: docker and readme instruction
Sonichigo Mar 4, 2024
b14963d
Merge branch 'main' into fastapi-readme
Sonichigo Mar 4, 2024
f05aab2
fix: docker and readme instruction
Sonichigo Mar 4, 2024
086b7a9
Merge pull request #16 from keploy/fastapi-readme
Sarthak160 Mar 7, 2024
3ba7e7c
Added Flask+MongoDB app with Unit tests, Postman testcases, Keploy te…
Swpn0neel Jun 14, 2024
c4fc91e
feat: revert for the workflow (#21)
Sonichigo Jun 14, 2024
fb38369
refactor: changes revert in flask-mongo (#22)
Sonichigo Jun 14, 2024
7e0e92e
Updated README (#20)
Swpn0neel Jun 18, 2024
d3f8140
fix: fastapi with docker compose (#15)
Guruprasanna02 Jul 26, 2024
9bdfbd8
add coverage guide and refacator flask and fastapi apps (#25)
Sonichigo Aug 4, 2024
181110e
refactor: remove keployFlaskMiddleware (#27)
Sarthak160 Aug 4, 2024
b043a93
added sanic+mongo sample app (#23)
Swpn0neel Aug 8, 2024
442f9e2
feat: created a sample app using flask and redis (#26)
Aman172003 Aug 8, 2024
1bd6f6e
chore: remove test folder (#28)
Sonichigo Sep 4, 2024
85d7561
feat:update unit test file in flask mongo (#29)
khareyash05 Sep 5, 2024
1234418
django-mongo sample app (#31)
AryanBakliwal Oct 24, 2024
aa1cafb
added sample app (#32)
Harshjosh361 Oct 28, 2024
28f4700
Feat: Add sample sanic-postgres app for the samples python repository…
slashexx Nov 20, 2024
20b388e
Bugfix/fastapi postgres (#34)
trivedi-khushi Dec 31, 2024
4868958
fix: docker compose cmd (#37)
Sonichigo Jan 1, 2025
4803633
chore: Update new slack url (#39)
Achanandhi-M May 11, 2025
c18373b
Added Twilio voice call feature using ngrok
drishlekh Jun 18, 2025
09b34fa
Added Twilio voice call feature using ngrok
drishlekh Jun 18, 2025
71faeda
Added Twilio voice call feature using ngrok
drishlekh Jun 18, 2025
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This repo contains the samples for [Keploy's](https://keploy.io) Python-based Ap

3. [FastAPI-Postgres](https://github.com/keploy/samples-python/tree/main/fastapi-postgres) - This application is a student management API built using Python's FastAPI and PostgreSQL for data storage. It allows you to perform basic CRUD (Create, Read, Update, Delete) operations on student data.

4. [FastAPI-Twilio](https://github.com/keploy/samples-python/tree/main/fastapi-twilio) - This application is a SMS sending API built using Python's FastAPI and Twilio for their SMS sharing service.

## Community Support ❤️

We'd love to collaborate with you to make Keploy great. To get started:
Expand Down
2 changes: 2 additions & 0 deletions fastapi-twilio/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./venv
./__pycache__
11 changes: 11 additions & 0 deletions fastapi-twilio/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:3.11.5-bullseye

WORKDIR /app

COPY . /app/

RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

EXPOSE 8000

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
84 changes: 84 additions & 0 deletions fastapi-twilio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# FastAPI-Twilio Application

A sample FastAPI-Twilio app to test Keploy integration capabilities using [FastAPI](https://fastapi.tiangolo.com/) and [Twilio](https://www.twilio.com/en-us). <br>

## Installation Setup

```bash
git clone https://github.com/keploy/samples-python.git && cd samples-python/fastapi-twilio
pip3 install -r requirements.txt
```

## Installation Keploy

Keploy can be installed on Linux directly and on Windows with the help of WSL. Based on your system architecture, install the keploy latest binary release

**1. AMD Architecture**

```shell
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
```

<details>
<summary> 2. ARM Architecture </summary>

```shell
curl --silent --location "https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz" | tar xz -C /tmp

sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin && keploy
```

</details>

### Get your Twilio Credentials

You can get your Twilio credentials by signing in to [Twilio Console](https://console.twilio.com/).
Once you get the Twilio Account SID, Auth Token, and Phone Number, modify the `.env` file with your credentials.

### Capture the Testcases

This command will start the recording of API calls:-

```shell
keploy record -c "uvicorn main:app --reload"
```

Make API Calls using Hoppscotch, Postman or cURL command. Keploy with capture those calls to generate the test-suites containing testcases and data mocks.

### Make the POST requests

1. Replace the place holder below i.e. `YOUR_REGISTERED_PERSONAL_PHONE_NUMBER` with your registered personal phone number that you linked with Twilio.

```bash
curl --location 'http://127.0.0.1:8000/send-sms/' \
--header 'Content-Type: application/json' \
--data '{
"Body": "Test, testtt, testttttttssss :)",
"To": "YOUR_REGISTERED_PERSONAL_PHONE_NUMBER",
}'
```

2. Replace the place holder below i.e. `SOME_WRONG_PHONE_NUMBER` with any wrong phone number and make the request.

```bash
curl --location 'http://127.0.0.1:8000/send-sms/' \
--header 'Content-Type: application/json' \
--data '{
"Body": "Test, testtt, testttttttssss :)",
"To": "SOME_WRONG_PHONE_NUMBER",
}'
```

Now all these API calls were captured as **editable** testcases and written to `keploy/tests` folder. The keploy directory would also have `mocks` file that contains all the outputs of Twilio operations.

## Run the Testcases

Now let's run the application in test mode.

```shell
keploy test -c "uvicorn main:app --reload" --delay 10
```

So, no need to setup fake apis like Twilio or write mocks for them. Keploy automatically mocks them and, **The application thinks it's talking to Twilio 😄**
64 changes: 64 additions & 0 deletions fastapi-twilio/keploy-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
record:
path: ""
# mandatory
command: ""
proxyport: 0
containerName: ""
networkName: ""
delay: 5
passThroughPorts: []
test:
path: ""
# mandatory
command: ""
proxyport: 0
containerName: ""
networkName: ""
testSets: []
globalNoise: |-
{
"global": {
"body": {},
"header": {}
},
"test-sets": {
"test-set-name": {
"body": {},
"header": {}
}
}
}
delay: 5
apiTimeout: 5
passThroughPorts: []
#
# Example on using globalNoise
# globalNoise: |-
# {
# "global": {
# "body": {
# # to ignore some values for a field,
# # pass regex patterns to the corresponding array value
# "url": ["https?://\S+", "http://\S+"],
# },
# "header": {
# # to ignore the entire field, pass an empty array
# "Date: [],
# }
# },
# # to ignore fields or the corresponding values for a specific test-set,
# # pass the test-set-name as a key to the "test-sets" object and
# # populate the corresponding "body" and "header" objects
# "test-sets": {
# "test-set-1": {
# "body": {
# # ignore all the values for the "url" field
# "url": []
# },
# "header": {
# # we can also pass the exact value to ignore for a field
# "User-Agent": ["PostmanRuntime/7.34.0"]
# }
# }
# }
# }
162 changes: 162 additions & 0 deletions fastapi-twilio/keploy/test-set-0/mocks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
version: api.keploy.io/v1beta1
kind: Http
name: mocks
spec:
metadata:
name: Http
operation: POST
type: HTTP_CLIENT
req:
method: POST
proto_major: 1
proto_minor: 1
url: /2010-04-01/Accounts/AC19413687d9ce28c80cda944730f8b286/Messages.json
header:
Accept: '*/*'
Accept-Encoding: gzip, deflate
Authorization: Basic QUMxOTQxMzY4N2Q5Y2UyOGM4MGNkYTk0NDczMGY4YjI4NjpjMTc0MDc5YzU2NTA0N2FmYWJmNDk5MWI2ZGQ1MmFiYg==
Connection: keep-alive
Content-Length: "82"
Content-Type: application/x-www-form-urlencoded
User-Agent: python-requests/2.31.0
body: Body=Test%2C+testtt%2C+testttttttssss+%3A%29&From=%2B16413324066&To=%2B91700004379
body_type: ""
timestamp: 0001-01-01T00:00:00Z
resp:
status_code: 400
header:
Access-Control-Allow-Credentials: "true"
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Idempotency-Key
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: '*'
Access-Control-Expose-Headers: ETag
Connection: keep-alive
Content-Length: 158,158
Content-Type: application/json
Date: Tue, 14 Nov 2023 09:26:29 GMT
Strict-Transport-Security: max-age=31536000
Twilio-Concurrent-Requests: "1"
Twilio-Request-Duration: "0.051"
Twilio-Request-Id: RQec3c4676524fe2951583489e90bc1b33
X-Api-Domain: api.twilio.com
X-Home-Region: us1
X-Powered-By: AT-5000
X-Shenanigans: none
body: '{"code": 21211, "message": "The ''To'' number +9170000XXXX is not a valid phone number", "more_info": "https://www.twilio.com/docs/errors/21211", "status": 400}'
body_type: ""
status_message: ""
proto_major: 0
proto_minor: 0
timestamp: 0001-01-01T00:00:00Z
objects: []
created: 1699953989
reqTimestampMock: 2023-11-14T14:56:28.791864295+05:30
resTimestampMock: 2023-11-14T14:56:29.304057844+05:30
---
version: api.keploy.io/v1beta1
kind: Http
name: mocks
spec:
metadata:
name: Http
operation: POST
type: HTTP_CLIENT
req:
method: POST
proto_major: 1
proto_minor: 1
url: /2010-04-01/Accounts/AC19413687d9ce28c80cda944730f8b286/Messages.json
header:
Accept: '*/*'
Accept-Encoding: gzip, deflate
Authorization: Basic QUMxOTQxMzY4N2Q5Y2UyOGM4MGNkYTk0NDczMGY4YjI4NjpjMTc0MDc5YzU2NTA0N2FmYWJmNDk5MWI2ZGQ1MmFiYg==
Connection: keep-alive
Content-Length: "83"
Content-Type: application/x-www-form-urlencoded
User-Agent: python-requests/2.31.0
body: Body=Test%2C+testtt%2C+testttttttssss+%3A%29&From=%2B16413324066&To=%2B917000043797
body_type: ""
timestamp: 0001-01-01T00:00:00Z
resp:
status_code: 201
header:
Access-Control-Allow-Credentials: "true"
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Idempotency-Key
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: '*'
Access-Control-Expose-Headers: ETag
Connection: keep-alive
Content-Length: 834,834
Content-Type: application/json
Date: Tue, 14 Nov 2023 09:26:35 GMT
Twilio-Concurrent-Requests: "1"
Twilio-Request-Duration: "0.131"
Twilio-Request-Id: RQ2f5288499581f3fe12524b11bbb3d866
X-Api-Domain: api.twilio.com
X-Home-Region: us1
X-Powered-By: AT-5000
X-Shenanigans: none
body: '{"body": "Sent from your Twilio trial account - Test, testtt, testttttttssss :)", "num_segments": "1", "direction": "outbound-api", "from": "+16413324066", "date_updated": "Tue, 14 Nov 2023 09:26:35 +0000", "price": null, "error_message": null, "uri": "/2010-04-01/Accounts/AC19413687d9ce28c80cda944730f8b286/Messages/SM2f5288499581f3fe12524b11bbb3d866.json", "account_sid": "AC19413687d9ce28c80cda944730f8b286", "num_media": "0", "to": "+917000043797", "date_created": "Tue, 14 Nov 2023 09:26:35 +0000", "status": "queued", "sid": "SM2f5288499581f3fe12524b11bbb3d866", "date_sent": null, "messaging_service_sid": null, "error_code": null, "price_unit": "USD", "api_version": "2010-04-01", "subresource_uris": {"media": "/2010-04-01/Accounts/AC19413687d9ce28c80cda944730f8b286/Messages/SM2f5288499581f3fe12524b11bbb3d866/Media.json"}}'
body_type: ""
status_message: ""
proto_major: 0
proto_minor: 0
timestamp: 0001-01-01T00:00:00Z
objects: []
created: 1699953995
reqTimestampMock: 2023-11-14T14:56:34.833506359+05:30
resTimestampMock: 2023-11-14T14:56:35.27188354+05:30
---
version: api.keploy.io/v1beta1
kind: Http
name: mocks
spec:
metadata:
name: Http
operation: POST
type: HTTP_CLIENT
req:
method: POST
proto_major: 1
proto_minor: 1
url: /2010-04-01/Accounts/AC19413687d9ce28c80cda944730f8b286/Messages.json
header:
Accept: '*/*'
Accept-Encoding: gzip, deflate
Authorization: Basic QUMxOTQxMzY4N2Q5Y2UyOGM4MGNkYTk0NDczMGY4YjI4NjpjMTc0MDc5YzU2NTA0N2FmYWJmNDk5MWI2ZGQ1MmFiYg==
Connection: keep-alive
Content-Length: "81"
Content-Type: application/x-www-form-urlencoded
User-Agent: python-requests/2.31.0
body: Body=Test%2C+testtt%2C+testttttttssss+%3A%29&From=%2B16413324066&To=%2B9170000437
body_type: ""
timestamp: 0001-01-01T00:00:00Z
resp:
status_code: 400
header:
Access-Control-Allow-Credentials: "true"
Access-Control-Allow-Headers: Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Idempotency-Key
Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS
Access-Control-Allow-Origin: '*'
Access-Control-Expose-Headers: ETag
Connection: keep-alive
Content-Length: 335,335
Content-Type: application/json
Date: Tue, 14 Nov 2023 09:27:21 GMT
Twilio-Concurrent-Requests: "1"
Twilio-Request-Duration: "0.080"
Twilio-Request-Id: RQb54d7f05d29e83bc89889cc136bcd99d
X-Api-Domain: api.twilio.com
X-Home-Region: us1
X-Powered-By: AT-5000
X-Shenanigans: none
body: '{"code": 21608, "message": "The number +917000XXXX is unverified. Trial accounts cannot send messages to unverified numbers; verify +917000XXXX at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers", "more_info": "https://www.twilio.com/docs/errors/21608", "status": 400}'
body_type: ""
status_message: ""
proto_major: 0
proto_minor: 0
timestamp: 0001-01-01T00:00:00Z
objects: []
created: 1699954041
reqTimestampMock: 2023-11-14T14:57:20.914415283+05:30
resTimestampMock: 2023-11-14T14:57:21.298027703+05:30
58 changes: 58 additions & 0 deletions fastapi-twilio/keploy/test-set-0/tests/test-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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/send-sms/
header:
Accept: '*/*'
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: "75"
Content-Type: application/json
Host: 127.0.0.1:8000
Postman-Token: c871b715-7aae-46b6-8e0d-1341aa426624
User-Agent: PostmanRuntime/7.34.0
body: |-
{
"Body": "Test, testtt, testttttttssss :)",
"To": "+91700004379"
}
body_type: ""
timestamp: 2023-11-14T14:56:25.800517709+05:30
resp:
status_code: 200
header:
Content-Length: "73"
Content-Type: application/json
Date: Tue, 14 Nov 2023 09:26:25 GMT
Server: uvicorn
body: '{"message":"Failed to send SMS. Please check the provided phone number."}'
body_type: ""
status_message: ""
proto_major: 0
proto_minor: 0
timestamp: 2023-11-14T14:56:32.013566624+05:30
objects: []
assertions:
noise:
header.Date: []
created: 1699953992
curl: |-
curl --request POST \
--url http://127.0.0.1:8000/send-sms/ \
--header 'User-Agent: PostmanRuntime/7.34.0' \
--header 'Accept: */*' \
--header 'Postman-Token: c871b715-7aae-46b6-8e0d-1341aa426624' \
--header 'Host: 127.0.0.1:8000' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--data '{
"Body": "Test, testtt, testttttttssss :)",
"To": "+91700004379"
}'
Loading