Skip to content

Commit

Permalink
Add a test for mailer not being configured
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Feb 8, 2019
1 parent c4707dc commit 6078441
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ckan/tests/controllers/test_user.py
Expand Up @@ -9,7 +9,7 @@

from ckan.lib.helpers import url_for
from ckan import model
from ckan.lib.mailer import create_reset_key
from ckan.lib.mailer import create_reset_key, MailerException

webtest_submit = helpers.webtest_submit
submit_and_follow = helpers.submit_and_follow
Expand Down Expand Up @@ -922,3 +922,17 @@ def test_request_reset_for_unknown_email(self, send_reset_link):
# doesn't reveal account does or doesn't exist
assert_in('A reset link has been emailed to you', response)
send_reset_link.assert_not_called()

@mock.patch('ckan.lib.mailer.send_reset_link')
def test_request_reset_but_mailer_not_configured(self, send_reset_link):
user = factories.User()
app = self._get_test_app()
offset = url_for('user.request_reset')
# This is the exception when the mailer is not configured:
send_reset_link.side_effect = MailerException(
'SMTP server could not be connected to: "localhost" '
'[Errno 111] Connection refused')
response = app.post(offset, params=dict(user=user['name']),
status=302).follow()

assert_in('Error sending the email', response)

0 comments on commit 6078441

Please sign in to comment.