This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,11 @@ | ||
from django.conf import settings | ||
|
||
from allauth.account.adapter import DefaultAccountAdapter | ||
|
||
|
||
class ApostelloAccountAdapter(DefaultAccountAdapter): | ||
def get_from_email(self): | ||
"""Override to use SiteConfiguration, then fall back to settings.""" | ||
from site_config.models import SiteConfiguration | ||
s = SiteConfiguration.get_solo() | ||
return s.email_from or settings.EMAIL_FROM |
This file contains 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,21 @@ | ||
from django.core.mail.backends.smtp import EmailBackend | ||
|
||
|
||
class ApostelloEmailBackend(EmailBackend): | ||
"""Email backend that reads settings from SiteConfiguration model.""" | ||
|
||
@staticmethod | ||
def _db_or_setting(db_val, setting_val): | ||
"""Default to value from settings if db value is None.""" | ||
if db_val: | ||
return db_val | ||
return setting_val | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(ApostelloEmailBackend, self).__init__(*args, **kwargs) | ||
from site_config.models import SiteConfiguration | ||
s = SiteConfiguration.get_solo() | ||
self.host = self._db_or_setting(s.email_host, self.host) | ||
self.port = self._db_or_setting(s.email_port, self.port) | ||
self.username = self._db_or_setting(s.email_username, self.username) | ||
self.password = self._db_or_setting(s.email_password, self.password) |
This file contains 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 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 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 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 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,19 @@ | ||
import pytest | ||
|
||
from apostello.account import ApostelloAccountAdapter | ||
from site_config.models import SiteConfiguration | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_get_email(): | ||
"""Test pulling email from settings and SiteConfiguration.""" | ||
s = SiteConfiguration.get_solo() | ||
a = ApostelloAccountAdapter() | ||
# test from db | ||
s.email_from = 'test2@apostello.ninja' | ||
s.save() | ||
assert a.get_from_email() == 'test2@apostello.ninja' | ||
# test from settings | ||
s.email_from = '' | ||
s.save() | ||
assert a.get_from_email() == 'test@apostello.ninja' |
This file contains 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,21 @@ | ||
import pytest | ||
|
||
from apostello.mail import ApostelloEmailBackend | ||
from site_config.models import SiteConfiguration | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_apostello_mail_backend(): | ||
"""Test email backend pulling from settings and db.""" | ||
# get from Siteconfiguration | ||
s = SiteConfiguration.get_solo() | ||
s.get_solo() | ||
s.email_host = 'smtp.test2.apostello' | ||
s.save() | ||
mail_backend = ApostelloEmailBackend() | ||
assert mail_backend.host == 'smtp.test2.apostello' | ||
# get from settings | ||
s.email_host = '' | ||
s.save() | ||
mail_backend = ApostelloEmailBackend() | ||
assert mail_backend.host == 'smtp.test.apostello' |
This file contains 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