From 3dee03d6e4bbf1fde6e11a3c1b797d981b83f3ab Mon Sep 17 00:00:00 2001 From: jwag956 Date: Mon, 29 Apr 2019 10:15:22 -0700 Subject: [PATCH] add unit test --- tests/test_misc.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/test_misc.py b/tests/test_misc.py index 81dc6fce..65568a37 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -17,7 +17,7 @@ RegisterForm, ResetPasswordForm, SendConfirmationForm, StringField, \ email_required, email_validator, valid_user_email from flask_security.utils import capture_reset_password_requests, \ - encode_string, hash_data, string_types, verify_hash + encode_string, hash_data, send_mail, string_types, verify_hash @pytest.mark.recoverable() @@ -280,3 +280,23 @@ class MyRegisterForm(RegisterForm): def test_without_babel(client): response = client.get('/login') assert b'Login' in response.data + + +def test_no_email_sender(app): + """ Verify that if SECURITY_EMAIL_SENDER is default + (which is a local proxy) that send_mail picks up MAIL_DEFAULT_SENDER. + """ + app.config['MAIL_DEFAULT_SENDER'] = 'test@testme.com' + + class TestUser(object): + def __init__(self, email): + self.email = email + security = Security() + security.init_app(app) + + with app.app_context(): + user = TestUser('matt@lp.com') + with app.mail.record_messages() as outbox: + send_mail('Test Default Sender', user.email, 'welcome', user=user) + assert 1 == len(outbox) + assert 'test@testme.com' == outbox[0].sender