Fix #861 - Add unit test and documentation for email_smtp_force_starttls
This commit is contained in:
parent
3b104bbcef
commit
7ffd4cf4b5
@ -23,14 +23,29 @@ direct_remote_path = string(default="/mgoblin_static/")
|
|||||||
|
|
||||||
# set to false to enable sending notices
|
# set to false to enable sending notices
|
||||||
email_debug_mode = boolean(default=True)
|
email_debug_mode = boolean(default=True)
|
||||||
|
|
||||||
|
# Uses SSL/TLS when connecting to SMTP server
|
||||||
email_smtp_use_ssl = boolean(default=False)
|
email_smtp_use_ssl = boolean(default=False)
|
||||||
email_smtp_force_tls = boolean(default=False)
|
|
||||||
|
# Uses STARTTLS when connecting to SMTP server
|
||||||
|
email_smtp_force_starttls = boolean(default=False)
|
||||||
|
|
||||||
|
# Email address which notices are sent from
|
||||||
email_sender_address = string(default="notice@mediagoblin.example.org")
|
email_sender_address = string(default="notice@mediagoblin.example.org")
|
||||||
|
|
||||||
|
# Hostname of SMTP server
|
||||||
email_smtp_host = string(default='')
|
email_smtp_host = string(default='')
|
||||||
|
|
||||||
|
# Port for SMTP server
|
||||||
email_smtp_port = integer(default=0)
|
email_smtp_port = integer(default=0)
|
||||||
|
|
||||||
|
# Username used for SMTP server
|
||||||
email_smtp_user = string(default=None)
|
email_smtp_user = string(default=None)
|
||||||
|
|
||||||
|
# Password used for SMTP server
|
||||||
email_smtp_pass = string(default=None)
|
email_smtp_pass = string(default=None)
|
||||||
|
|
||||||
|
|
||||||
# Set to false to disable registrations
|
# Set to false to disable registrations
|
||||||
allow_registration = boolean(default=True)
|
allow_registration = boolean(default=True)
|
||||||
|
|
||||||
|
@ -14,8 +14,13 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import mock
|
||||||
import email
|
import email
|
||||||
|
import pytest
|
||||||
|
import smtplib
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
from mediagoblin.tests.tools import get_app
|
||||||
from mediagoblin.tools import common, url, translate, mail, text, testing
|
from mediagoblin.tools import common, url, translate, mail, text, testing
|
||||||
|
|
||||||
testing._activate_testing()
|
testing._activate_testing()
|
||||||
@ -69,6 +74,28 @@ I hope you like unit tests JUST AS MUCH AS I DO!"""
|
|||||||
|
|
||||||
I hope you like unit tests JUST AS MUCH AS I DO!"""
|
I hope you like unit tests JUST AS MUCH AS I DO!"""
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def starttls_enabled_app(request):
|
||||||
|
return get_app(
|
||||||
|
request,
|
||||||
|
mgoblin_config=pkg_resources.resource_filename(
|
||||||
|
"mediagoblin.tests",
|
||||||
|
"starttls_config.ini"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_email_force_starttls(starttls_enabled_app):
|
||||||
|
common.TESTS_ENABLED = False
|
||||||
|
SMTP = lambda *args, **kwargs: mail.FakeMhost()
|
||||||
|
with mock.patch('smtplib.SMTP', SMTP):
|
||||||
|
with pytest.raises(smtplib.SMTPException):
|
||||||
|
mail.send_email(
|
||||||
|
from_addr="notices@my.test.instance.com",
|
||||||
|
to_addrs="someone@someplace.com",
|
||||||
|
subject="Testing is so much fun!",
|
||||||
|
message_body="Ohai ^_^"
|
||||||
|
)
|
||||||
|
|
||||||
def test_slugify():
|
def test_slugify():
|
||||||
assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park'
|
assert url.slugify(u'a walk in the park') == u'a-walk-in-the-park'
|
||||||
assert url.slugify(u'A Walk in the Park') == u'a-walk-in-the-park'
|
assert url.slugify(u'A Walk in the Park') == u'a-walk-in-the-park'
|
||||||
|
@ -111,7 +111,7 @@ def send_email(from_addr, to_addrs, subject, message_body):
|
|||||||
mhost.starttls()
|
mhost.starttls()
|
||||||
except smtplib.SMTPException:
|
except smtplib.SMTPException:
|
||||||
# Only raise an exception if we're forced to
|
# Only raise an exception if we're forced to
|
||||||
if mg_globals.app_config['email_smtp_force_tls']:
|
if mg_globals.app_config['email_smtp_force_starttls']:
|
||||||
six.reraise(*sys.exc_info())
|
six.reraise(*sys.exc_info())
|
||||||
|
|
||||||
if ((not common.TESTS_ENABLED)
|
if ((not common.TESTS_ENABLED)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user