From f8397e273ddfe9bf0954c153b6570c553f7ecdd0 Mon Sep 17 00:00:00 2001 From: ShraddhaAg Date: Mar 20 2019 13:10:43 +0000 Subject: Add alternative method to test sending emails This commit adds: 1. The configurations to test sending emails using Gmail's SMTP server. 2. Add documentation guide for the same. --- diff --git a/docker-compose.yml b/docker-compose.yml index 35fab71..706f073 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,8 @@ services: links: - db - redis + # ports: + # - "587:587" db: image: postgres:10-alpine environment: diff --git a/docs/setup/development.rst b/docs/setup/development.rst index 5125096..4ed8d77 100644 --- a/docs/setup/development.rst +++ b/docs/setup/development.rst @@ -47,7 +47,24 @@ In order to run the script, simply type ``./t`` in the Docker container's shell. Integration tests are run via the following command: ``docker-compose exec web ./manage.py test -v 2 -p integration_test*.py --settings=happinesspackets.settings.tsting`` -To test if messages are being sent to the RabbitMQ broker, open a new terminal and run the following command inside the shell of the Docker conatiner `web`:: +Alternative methods to test sending email +----------------------------------------- + +In the development environment sending emails is setup in two ways: + +* The default setup is to send emails on the console. The settings for the same can be found under the comment ``Configurations for sending email on console``. To see this in action, no changes to the present code base is needed. + +* Emails are also configured to send using Gmail SMTP server. To test this functionality: + + 1. In ``settings/dev.py`` un-comment the setting for ``Configurations to test sending emails using Gmail SMTP`` and comment out the setting under ``Configurations for sending email on console`` and in ``docker-compose.yml`` un-comment the ports setting in ``celery`` service. + 2. Enable `less secure apps `_ in the Gmail account which you want to use as the host email. + (It is strongly recommended to not allow less secure apps in your primary Gmail account. A separate account for testing is recommended with this setting enabled.) + 3. Replace ```` and ```` with the email address of the above account and its password. + +Testing Fedora Messaging Integration +-------------------------------------- + +To test if messages are being sent to the RabbitMQ broker, open a new terminal and run the following command inside the shell of the Docker container `web`:: fedora-messaging consume --callback=fedora_messaging.example:printer diff --git a/happinesspackets/settings/dev.py b/happinesspackets/settings/dev.py index cdfe56e..8da1bd0 100644 --- a/happinesspackets/settings/dev.py +++ b/happinesspackets/settings/dev.py @@ -21,9 +21,19 @@ DATABASES = { } } +#Configurations to send email on console CELERY_EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" +#Configurations to test sending emails using Gmail SMTP +# CELERY_EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" +# EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend' +# EMAIL_HOST = 'smtp.gmail.com' +# EMAIL_HOST_USER = '' +# EMAIL_HOST_PASSWORD = '' +# EMAIL_USE_TLS = True +# EMAIL_PORT = 587 + SECRET_KEY = 'only-for-testing'