Skip to content

Commit

Permalink
Validate recipient address format in send_email.py
Browse files Browse the repository at this point in the history
Make validator available on name space package
Update test runner
  • Loading branch information
dormant-user committed Apr 3, 2023
1 parent d8b63a5 commit 287f19c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion gmailconnector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from .send_email import SendEmail # noqa: F401
from .send_sms import SendSMS # noqa: F401
from .sms_deleter import DeleteSent # noqa: F401
from .validator.address import EmailAddress # noqa: F401
from .validator.validate_email import validate_email # noqa: F401

version = "0.7"
version = "0.8"


def load_env(filename: Union[str, os.PathLike] = ".env", scan: bool = False) -> NoReturn:
Expand Down
2 changes: 2 additions & 0 deletions gmailconnector/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .models.config import Encryption
from .models.responder import Response
from .validator.address import EmailAddress


class SendEmail:
Expand Down Expand Up @@ -198,6 +199,7 @@ def send_email(self, subject: str, recipient: Union[str, list] = None,
raise ValueError(
'Cannot proceed without the arg: `recipient`'
)
recipient = EmailAddress(address=recipient).email # validates recipient before sending email
if not self._authenticated:
status = self.authenticate
if not status.ok:
Expand Down
6 changes: 6 additions & 0 deletions release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Release Notes
=============

0.7.9 (04/03/2023)
------------------
- Validate recipient address format in send_email.py
- Make validator available on name space package
- Update test runner

0.7.8 (04/03/2023)
------------------
- Update README.md and python version requirement
Expand Down
20 changes: 12 additions & 8 deletions test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import gmailconnector as gc

logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s - [%(module)s:%(lineno)d] - %(funcName)s - %(message)s'))
logger.addHandler(handler)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())

gc.load_env(filename="secrets.env")

logger.info("RUNNING TESTS on version: %s", gc.version)


def test_run_read_email():
"""Test run read emails."""
Expand Down Expand Up @@ -77,7 +81,7 @@ def test_run_send_sms_ssl():

def test_run_validate_email_smtp_off():
"""Test run on email validator with SMTP disabled."""
logger.info("Test initiated on email validator using SMTP enabled.")
logger.info("Test initiated on email validator with SMTP disabled.")
response = gc.validate_email(email_address=os.environ.get("GMAIL_USER"),
smtp_check=False, debug=True, logger=logger)
assert response.ok, response.body
Expand All @@ -86,18 +90,18 @@ def test_run_validate_email_smtp_off():

def test_run_validate_email_smtp_on():
"""Test run on email validator with SMTP enabled."""
logger.info("Test initiated on email validator using SMTP disabled.")
logger.info("Test initiated on email validator with SMTP enabled.")
response = gc.validate_email(email_address=os.environ.get("GMAIL_USER"),
smtp_check=True, debug=True, logger=logger)
assert response.status <= 299, response.body
logger.info("Test successful on validate email with SMTP disabled.")


if __name__ == '__main__':
# test_run_validate_email_smtp_off()
# test_run_validate_email_smtp_on()
# test_run_send_email_tls()
# test_run_send_email_ssl()
test_run_validate_email_smtp_off()
test_run_validate_email_smtp_on()
test_run_send_email_tls()
test_run_send_email_ssl()
test_run_send_sms_tls()
test_run_send_sms_ssl()
# test_run_read_email()
test_run_read_email()

0 comments on commit 287f19c

Please sign in to comment.