Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 23 additions & 0 deletions app/internal/whatsapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import webbrowser


def send(phone_number: str, message: str) -> bool:
"""This function is being used to send whatsapp messages.
It takes a string message and a cell phone number and it sends 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:
bool: Returns True if the message was sent, else returns False.
"""
try:
webbrowser.open_new(f'https://api.whatsapp.com/send?phone={phone_number}&text={message}')
except webbrowser.Error: # pragma: no cover
# Exception raised when a browser control error occurs.
return False
if not phone_number:
return False
if not message:
return False
return True
28 changes: 28 additions & 0 deletions tests/test_whatsapp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
from app.internal import whatsapp


phone_and_msg = [
('972536106106', 'Event or a joke or the schedule of one day'),
# You will redirect to whatsapp window of the specified number and you can send the message
('999999', 'Wrong phone number?'),
# You will redirect to whatsapp window and you will receive a message "The phone number shared via a link is incorrect"
]


@pytest.mark.parametrize('phone_number, message', phone_and_msg)
def test_whatsapp_send(phone_number, message):
assert whatsapp.send(phone_number, message) == True


no_phone_or_msg = [
('972536106106', ''),
# You will redirect to whatsapp window of the specified number and you can write your own message
('', 'Which phone number?'),
# You will redirect to whatsapp window and you can choose someone from your contact list
]


@pytest.mark.parametrize('phone_number, message', no_phone_or_msg)
def test_no_message_or_phone(phone_number, message):
assert whatsapp.send(phone_number, message) == False