Changeset b8ef4ab in OpenWorkouts-current for ow/tests/test_mail.py


Ignore:
Timestamp:
Feb 19, 2019, 6:58:39 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
42d775c
Parents:
07f5190
Message:

(#61) Better templates for "verify your account" emails:

  • Send a multipart text/html email (instead text only)
  • Added some styling to the html version of the email, based on our current login page styles.

Important: as the html version contains html code generated using
request.resource_url() and request.static_url(), when running in
development mode under http://localhost, the links to images
and css files in the rendered email point to localhost, so they
won't work outside the machine running openworkouts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/tests/test_mail.py

    r07f5190 rb8ef4ab  
    4141        message.recipients = ['user@example.net']
    4242        m.return_value = message
    43         body = Mock()
    44         r.return_value = body
     43
     44        txt_body = Mock()
     45        html_body = Mock()
     46        r.side_effect = [txt_body, html_body]
     47
    4548        request = DummyRequest()
    4649        request.root = root
     
    4952        verify_link = request.resource_url(
    5053            user, 'verify', user.verification_token)
    51         r.assert_called_once_with(
    52             'ow:templates/mail_verify_account.pt',
    53             {'user': user, 'verify_link': verify_link},
    54             request
    55         )
     54
     55        # two render calls
     56        assert r.call_count == 2
     57
     58        # first call renders the text version of the email
     59        assert r.call_args_list[0][0][0] == (
     60            'ow:templates/mail_verify_account_txt.pt')
     61        assert r.call_args_list[0][0][1] == (
     62            {'user': user, 'verify_link': verify_link})
     63        assert r.call_args_list[0][0][2] == request
     64
     65        # second call renders the html version of the email
     66        assert r.call_args_list[1][0][0] == (
     67            'ow:templates/mail_verify_account_html.pt')
     68        assert r.call_args_list[1][0][1] == (
     69            {'user': user, 'verify_link': verify_link})
     70        assert r.call_args_list[1][0][2] == request
     71
    5672        m.assert_called_once
    5773        m.call_args_list[0][1]['recipients'] == user.email
    58         m.call_args_list[0][1]['body'] == body
     74        m.call_args_list[0][1]['body'] == txt_body
     75        m.call_args_list[0][1]['html'] == html_body
    5976        mailer.send_to_queue.assert_called_once_with(message)
Note: See TracChangeset for help on using the changeset viewer.