-
Notifications
You must be signed in to change notification settings - Fork 52
feat: Add a feature for sharing information with a WhatsApp account #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yammesicka
merged 19 commits into
PythonFreeCourse:develop
from
nelliei:featture/whatsappsend
Jan 27, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b424528
feat: Add a feature to share to a WhatsApp account
82ab4e0
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
6c804d3
Feat: creating a link function and modifying tests
be783c5
fix: test_whatsapp according to flake8
9d4bcd7
fix: according to flake8
740df0e
fix: hopefuly according to flake8
b8c5ee9
fix: change function name and add urlencode
a700bb9
fix: one line was too long
b7e3ca9
fix: fixing a small bug :)
e6e30e8
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
36a11f4
fix: add a route to the code and adjust the tests
b466818
fix: changes according flake8
3bcc735
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
b1b65ce
fix: adding end to end test
071767f
fix: fixing conflicts
494ff31
fix: fixing conflicts
6773787
fix: flake8
342cdde
fix: fix tests
656a14d
fix: a small mistake
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from fastapi import APIRouter | ||
from typing import Optional | ||
from urllib.parse import urlencode | ||
|
||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/whatsapp") | ||
def make_link(phone_number: Optional[str], message: Optional[str]) -> str: | ||
"""This function is being used to send whatsapp messages. | ||
It takes a string message and a cell phone number and it returns a link so | ||
we can add it to an html page and send the message to that phone number. | ||
Args: | ||
phone_number (str): Cell phone number to send the message to. | ||
message (str): Message that is going to be sent. | ||
|
||
Returns: | ||
str: Returns a string which contains a link to whatsapp api so we can | ||
send the message via whatsapp. | ||
""" | ||
link = 'https://api.whatsapp.com/send?' | ||
mydict = {'phone': phone_number, 'text': message} | ||
msglink = link + urlencode(mydict) | ||
return {"link": msglink} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from app.routers import whatsapp | ||
|
||
|
||
def test_whatsapp_send(): | ||
# Redirects you directly to the specified contact and the message will | ||
# already be there (or to whatsapp web if the call is from the web) | ||
phone_number = "972536106106" | ||
message = 'Event or a joke or the schedule of one day' | ||
assert whatsapp.make_link(phone_number, message) == { | ||
"link": "https://api.whatsapp.com/send?phone=972536106106&text=Event+" | ||
"or+a+joke+or+the+schedule+of+one+day"} | ||
|
||
|
||
def test_wrong_phone_number(): | ||
# Redirects you to a popup: The phone number shared via a link is incorrect | ||
phone_number = "999999" | ||
message = 'Wrong phone number?' | ||
assert whatsapp.make_link(phone_number, message) == { | ||
"link": "https://api.whatsapp.com/send?phone=999999&text=Wrong+phone+" | ||
"number%3F"} | ||
|
||
|
||
def test_no_message(): | ||
# Redirects to whatsapp of the specified number. Write your own message. | ||
phone_number = "972536106106" | ||
message = '' | ||
assert whatsapp.make_link(phone_number, message) == { | ||
"link": "https://api.whatsapp.com/send?phone=972536106106&text="} | ||
|
||
|
||
def test_no_number(): | ||
# Redirects to whatsapp window. Choose someone from your own contact list. | ||
phone_number = "" | ||
message = 'Which phone number?' | ||
assert whatsapp.make_link(phone_number, message) == { | ||
"link": "https://api.whatsapp.com/send?phone=&text=Which+phone+" | ||
"number%3F"} | ||
|
||
|
||
def test_end_to_end_testing(client): | ||
resp = client.get('/whatsapp?phone_number=972536106106&message=testing') | ||
assert resp.ok | ||
assert resp.json |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an end to end test:
Use the client to fetch the
/whatsapp
route and check you get a valid JSON.