Skip to content
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

add backend and settings for email #203

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ jobs:
django-version:
- '2.2'
- '3.2'
- '4.0'
- '4.2'

steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down Expand Up @@ -56,10 +56,10 @@ jobs:

steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.8

Expand Down Expand Up @@ -88,10 +88,10 @@ jobs:
echo "::set-output name=dtc_tag::django-test-container:${FIXED_BRANCH}"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Cache Docker layers
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: >-
Expand All @@ -101,7 +101,7 @@ jobs:
${{ runner.os }}-buildx-

- name: Build Django Container Image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
target: django-container
tags: ${{ steps.tags.outputs.dc_tag }}
Expand All @@ -111,7 +111,7 @@ jobs:
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Build Django Container Test Image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v3
with:
tags: ${{ steps.tags.outputs.dtc_tag }}
push: false
Expand Down
15 changes: 15 additions & 0 deletions project/base_settings/restclients_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,18 @@
RESTCLIENTS_MEMCACHED_SERVERS = tuple(MEMCACHED_SERVER_SPEC.format(n)
for n in range(
MEMCACHED_SERVER_COUNT))

if os.getenv('EMAIL_HOST'):
EMAIL_HOST = os.getenv('EMAIL_HOST')
EMAIL_PORT = os.getenv('EMAIL_PORT', 587)
EMAIL_TIMEOUT = os.getenv('EMAIL_TIMEOUT', 15)
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', True)
EMAIL_SSL_CERTFILE = APPLICATION_CERT_PATH
EMAIL_SSL_KEYFILE = APPLICATION_KEY_PATH

if os.getenv('ENV', 'localdev') == 'prod':
EMAIL_BACKEND = 'project.mail.backends.EmailBackend'
else:
if os.getenv('SAFE_EMAIL_RECIPIENT'):
EMAIL_BACKEND = 'saferecipient.EmailBackend'
SAFE_EMAIL_RECIPIENT = os.getenv('SAFE_EMAIL_RECIPIENT')
Empty file added project/mail/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions project/mail/backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.core.mail.backends.smtp import EmailBackend as SMTPBackend
from django.utils.functional import cached_property
import ssl


class EmailBackend(SMTPBackend):
"""
See https://code.djangoproject.com/ticket/34504
"""
@cached_property
def ssl_context(self):
ssl_context = super().ssl_context
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
return ssl_context
13 changes: 13 additions & 0 deletions tests/test_settings/test_restclients.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase
from ..utils import SettingLoader


class TestGlobals(TestCase):
def setUp(self):
self.mock_env = {
Expand Down Expand Up @@ -30,6 +31,7 @@ def test_default_globals_with_env(self):
self.assertEqual(RESTCLIENTS_DEFAULT_POOL_SIZE, base_settings.RESTCLIENTS_DEFAULT_POOL_SIZE)
self.assertEqual(RESTCLIENTS_DEFAULT_ENVS, base_settings.RESTCLIENTS_DEFAULT_ENVS)


class TestCache(TestCase):
def test_memcached(self):
mock_memcached = {
Expand All @@ -39,6 +41,17 @@ def test_memcached(self):
with SettingLoader('project.base_settings', **mock_memcached) as base_settings:
self.assertSequenceEqual(('mock_memcached_0:11211',), base_settings.RESTCLIENTS_MEMCACHED_SERVERS)


class TestEmail(TestCase):
def test_email(self):
mock_email = {
'EMAIL_HOST': 'test.edu',
'ENV': 'prod',
}
with SettingLoader('project.base_settings', **mock_email) as base_settings:
self.assertEqual(base_settings.EMAIL_BACKEND, 'project.mail.backends.EmailBackend')


class TestRestClients(TestCase):
def test_settings_not_overwritten(self):
restclients = [
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __enter__(self):

self.loaded_setting = importlib.import_module(self.setting_file_path)
return self.loaded_setting

def __exit__(self, exc_type, exc_value, tb):
for variable_name in self.enviroment_variables:
del os.environ[variable_name]
Expand Down
Loading